sf.lab.MZgate¶
- class mrmustard.lab.MZgate(phi_a=0.0, phi_b=0.0, phi_a_trainable=False, phi_b_trainable=False, phi_a_bounds=(None, None), phi_b_bounds=(None, None), internal=False, modes=None)[source]¶
Bases:
Unitary
Mach-Zehnder gate.
- It supports two conventions:
if
internal=True
, both phases act inside the interferometer:phi_a
on the upper arm,phi_b
on the lower arm;if
internal = False
, both phases act on the upper arm:phi_a
before the first BS,phi_b
after the first BS.
One can optionally set bounds for each parameter, which the optimizer will respect.
- Parameters:
phi_a (float) – the phase in the upper arm of the MZ interferometer
phi_a_bounds (float, float) – bounds for phi_a
phi_a_trainable (bool) – whether phi_a is a trainable variable
phi_b (float) – the phase in the lower arm or external of the MZ interferometer
phi_b_bounds (float, float) – bounds for phi_b
phi_b_trainable (bool) – whether phi_b is a trainable variable
internal (bool) – whether phases are both in the internal arms (default is False)
modes (optional, List[int]) – the list of modes this gate is applied to
Attributes
The adjoint view of this Tensor (with new ``id``s). That is, ket <-> bra.
A dictionary mapping the input modes to their respective wires.
For backward compatibility.
The list of input modes that are used by this Tensor.
The list of output modes that are used by this Tensor.
The name of this tensor.
The number of modes on which the transformation acts.
A dictionary mapping the output modes to their respective wires.
The set of parameters for this transformation.
The list of all wires in this tensor, sorted as
[ket_in, ket_out, bra_in, bra_out]
.- X_matrix¶
- X_matrix_dual¶
- Y_matrix¶
- Y_matrix_dual¶
- d_vector¶
- d_vector_dual¶
- input¶
A dictionary mapping the input modes to their respective wires.
- is_gaussian = True¶
- modes¶
For backward compatibility. Don’t overuse. It returns a list of modes for this Tensor, unless it’s ambiguous.
- modes_in¶
The list of input modes that are used by this Tensor.
If this tensor has no input modes on the bra side, or if the input modes are equal on both ket and bra sides, it returns the list of modes. Otherwise, it performs the
set()
operation before returning the list (and hence, the order may be unexpected).
- modes_out¶
The list of output modes that are used by this Tensor.
If this tensor has no output modes on the bra side, or if the output modes are equal on both ket and bra sides, it returns the list of modes. Otherwise, it performs the
set()
operation before returning the list (and hence, the order may be unexpected).
- name¶
The name of this tensor.
- num_modes¶
The number of modes on which the transformation acts.
- output¶
A dictionary mapping the output modes to their respective wires.
- parallelizable = False¶
- parameter_set¶
The set of parameters for this transformation.
- short_name = 'MZ'¶
- wires¶
The list of all wires in this tensor, sorted as
[ket_in, ket_out, bra_in, bra_out]
.
Methods
U
([cutoffs, shape])Returns the unitary representation of the transformation.
XYd
([allow_none])Returns the
`(X, Y, d)`
triple.XYd_dual
([allow_none])Returns the
`(X, Y, d)`
triple of the dual of the current transformation.bargmann
([numpy])change_modes
([modes_in_ket, modes_out_ket, ...])Changes the modes in this tensor.
choi
([cutoffs, shape, dual])Returns the Choi representation of the transformation.
dual
(state)Applies the dual of this transformation to the given
state
and returns the transformed state.primal
(state)Applies this transformation to the given
state
and returns the transformed state.shape
([default_dim, out_in])Returns the shape of the underlying tensor, as inferred from the dimensions of the individual wires.
unpack_shape
(shape)Unpack the given
shape
into the shapes of the input and output wires on ket and bra sides.value
(shape)The value of this tensor.
- U(cutoffs=None, shape=None)¶
Returns the unitary representation of the transformation.
If specified,
shape
takes precedence overcutoffs
.shape
is in the order(out, in)
.Note that for a unitary transformation on N modes,
len(cutoffs)
isN
andlen(shape)
is2N
.- Parameters:
cutoffs (
Optional
[Sequence
[int
]]) – the cutoffs of the input and output modesshape (
Optional
[Sequence
[int
]]) – the shape of the unitary matrix
- Returns:
the unitary matrix in Fock representation
- Return type:
ComplexTensor
- XYd(allow_none=True)¶
Returns the
`(X, Y, d)`
triple.Override in subclasses if computing
X
,Y
andd
together is more efficient.- Return type:
Tuple
[Optional
[ndarray
[Tuple
[int
,int
],TypeVar
(R
,float16
,float32
,float64
)]],Optional
[ndarray
[Tuple
[int
,int
],TypeVar
(R
,float16
,float32
,float64
)]],Optional
[ndarray
[Tuple
[int
],TypeVar
(R
,float16
,float32
,float64
)]]]
- XYd_dual(allow_none=True)¶
Returns the
`(X, Y, d)`
triple of the dual of the current transformation.Override in subclasses if computing
Xdual
,Ydual
andddual
together is more efficient.- Return type:
tuple
[Optional
[ndarray
[Tuple
[int
,int
],TypeVar
(R
,float16
,float32
,float64
)]],Optional
[ndarray
[Tuple
[int
,int
],TypeVar
(R
,float16
,float32
,float64
)]],Optional
[ndarray
[Tuple
[int
],TypeVar
(R
,float16
,float32
,float64
)]]]
- bargmann(numpy=False)¶
- change_modes(modes_in_ket=None, modes_out_ket=None, modes_in_bra=None, modes_out_bra=None)¶
Changes the modes in this tensor.
- Parameters:
name – The name of this tensor.
modes_in_ket (
Optional
[list
[int
]]) – The input modes on the ket side.modes_out_ket (
Optional
[list
[int
]]) – The output modes on the ket side.modes_in_bra (
Optional
[list
[int
]]) – The input modes on the bra side.modes_out_bra (
Optional
[list
[int
]]) – The output modes on the bra side.
- Raises:
ValueError – if one or more wires in this tensor are already connected.
- Return type:
None
- choi(cutoffs=None, shape=None, dual=False)¶
Returns the Choi representation of the transformation.
If specified,
shape
takes precedence overcutoffs
. Theshape
is in the order(out_L, in_L, out_R, in_R)
.- Parameters:
cutoffs (
Optional
[Sequence
[int
]]) – the cutoffs of the input and output modesshape (
Optional
[Sequence
[int
]]) – the shape of the Choi matrixdual (
bool
) – whether to return the dual Choi
- dual(state)¶
Applies the dual of this transformation to the given
state
and returns the transformed state.
- primal(state)¶
Applies this transformation to the given
state
and returns the transformed state.
- shape(default_dim=None, out_in=False)¶
Returns the shape of the underlying tensor, as inferred from the dimensions of the individual wires.
If
out_in
isFalse
, the shape returned is in the order(in_ket, in_bra, out_ket, out_bra)
. Otherwise, it is in the order(out_ket, out_bra, in_ket, in_bra)
.- Parameters:
default_dim (
Optional
[int
]) – The default dimension of wires with unspecified dimension.out_in – Whether to return output shapes followed by input shapes or viceversa.
- unpack_shape(shape)¶
Unpack the given
shape
into the shapes of the input and output wires on ket and bra sides.- Parameters:
shape (
Tuple
[int
]) – A shape.- Returns:
The shape of the input wires on the ket side. shape_out_ket: The shape of the output wires on the ket side. shape_in_bra: The shape of the input wires on the bra side. shape_out_bra: The shape of the output wires on the bra side.
- Return type:
shape_in_ket
- value(shape)¶
The value of this tensor.
- Parameters:
shape (
Tuple
[int
]) – the shape of this tensor- Returns:
the unitary matrix in Fock representation
- Return type:
ComplexTensor