MrMustard Einsum¶
Decorator that wraps a function returning a |
|
Decorator that wraps a function returning an |
|
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
PolyExpAnsatzand returns anArrayAnsatzinstead usingto_fock.- Parameters:
func (Callable[[...], PolyExpAnsatz]) – A callable that returns a
PolyExpAnsatz.- Returns:
A wrapped function that returns an
ArrayAnsatzconstructed from the Bargmann triple (A, b, c) usingto_fock. The wrapped function has the same signature as the original function with an additional optionalshapeparameter.- Return type:
Callable[[…], ArrayAnsatz]
fock_to_bargmann¶
- mrmustard.physics.mm_einsum.fock_to_bargmann(func)[source]¶
Decorator that wraps a function returning an
ArrayAnsatzand returns aPolyExpAnsatzinstead usingto_bargmann.- Parameters:
func (Callable[[...], ArrayAnsatz]) – A callable that returns an
ArrayAnsatz.- Returns:
A wrapped function that returns a
PolyExpAnsatzconstructed from theArrayAnsatzusingto_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, ..., outputwherelabelsare 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
PolyExpAnsatzto 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
ArrayAnsatzorPolyExpAnsatzdepending on conversion requirements.- Raises:
ValueError – If the equation is invalid or the operands are not compatible.
- Similar to