MrMustard Einsum

bargmann_to_fock

Decorator that wraps a function returning a PolyExpAnsatz and returns an ArrayAnsatz instead using to_fock.

fock_to_bargmann

Decorator that wraps a function returning an ArrayAnsatz and returns a PolyExpAnsatz instead using to_bargmann.

mm_einsum

Performs Einstein summation over ansatze with explicit batch and core dimension labeling.

bargmann_to_fock

mrmustard.physics.mm_einsum.bargmann_to_fock(func)[source]

Decorator that wraps a function returning a PolyExpAnsatz and returns an ArrayAnsatz instead using to_fock.

Parameters:

func (Callable[[...], PolyExpAnsatz]) – A callable that returns a PolyExpAnsatz.

Returns:

A wrapped function that returns an ArrayAnsatz constructed from the Bargmann triple (A, b, c) using to_fock. The wrapped function has the same signature as the original function with an additional optional shape parameter.

Return type:

Callable[[…], ArrayAnsatz]

fock_to_bargmann

mrmustard.physics.mm_einsum.fock_to_bargmann(func)[source]

Decorator that wraps a function returning an ArrayAnsatz and returns a PolyExpAnsatz instead using to_bargmann.

Parameters:

func (Callable[[...], ArrayAnsatz]) – A callable that returns an ArrayAnsatz.

Returns:

A wrapped function that returns a PolyExpAnsatz constructed from the ArrayAnsatz using to_bargmann.

Return type:

Callable[[…], PolyExpAnsatz]

mm_einsum

mrmustard.physics.mm_einsum.mm_einsum(*operands: Ansatz | list[int] | list[int | tuple[int, ...]], fock_dims: dict[int, int] | None, contraction_path: list[tuple[int, int]] | None = None, path_type: Literal['SSA', 'LA', 'UA'] = 'LA') Ansatz[source]
mrmustard.physics.mm_einsum.mm_einsum(*operands: str | Ansatz, fock_dims: dict[str, int] | None, contraction_path: list[tuple[int, int]] | None = None, path_type: Literal['SSA', 'LA', 'UA'] = 'LA') Ansatz

Performs Einstein summation over ansatze with explicit batch and core dimension labeling. All batch dimensions (including an eventual linear superposition axis) must be explicitly labeled.

Similar to np.einsum, two signatures are supported:
  • Subscript style:

    The first operand is a string where batch dimensions are explicitly labeled with UPPERCASE letters, while core dimensions use lowercase letters. The subscripts for summation are a comma separated list of subscript labels with explicit output indices following a -> indicator.

  • Sublist style:

    The operands must be in the form ansatz0, labels0, ansatz1, labels1, ..., output where labels are a list of integers labeling indices for the preceding ansatz in the list of operands and output is a list of integers labeling output indices for the resulting ansatz.

In both signatures output batch labels can be group with parentheses for batch grouping support.

Parameters:
  • *operands – The operands for the contraction in either subscript style or sublist style.

  • fock_dims – Mapping from core labels to Fock sizes. Required if converting a PolyExpAnsatz to Fock.

  • contraction_path – List of contraction steps over operand IDs. When supplied, it is used end-to-end: the Bargmann phase consumes the path prefix it can execute, and the final array/Fock einsum consumes the remaining suffix.

  • path_type – Path interpretation method (“LA”, “SSA”, or “UA”). Default is “LA”.

Returns:

Final ArrayAnsatz or PolyExpAnsatz depending on conversion requirements.

Raises:

ValueError – If the equation is invalid or the operands are not compatible.