sf.physics.representations.Fock¶
- class mrmustard.physics.representations.Fock(array, batched=False)[source]¶
Bases:
Representation
The Fock representation of a broad class of quantum states, transformations, measurements, channels, etc.
The ansatz available in this representation is
ArrayAnsatz
.This function allows for vector space operations on Fock objects including linear combinations, outer product (
&
), and inner product (@
).>>> # initialize Fock objects >>> array1 = math.astensor(np.random.random((1,5,7,8))) # where 1 is the batch. >>> array2 = math.astensor(np.random.random((1,5,7,8))) # where 1 is the batch. >>> array3 = math.astensor(np.random.random((3,5,7,8))) # where 3 is the batch. >>> fock1 = Fock(array1) >>> fock2 = Fock(array2) >>> fock3 = Fock(array3) >>> # linear combination can be done with the same batch dimension >>> fock4 = 1.3 * fock1 - fock2 * 2.1 >>> # division by a scalar >>> fock5 = fock1 / 1.3 >>> # inner product by contracting on marked indices >>> fock6 = fock1[2] @ fock3[2] >>> # outer product (tensor product) >>> fock7 = fock1 & fock3 >>> # conjugation >>> fock8 = fock1.conj()
- Parameters:
array (
Batch
[ndarray
[Tuple
[int
,...
],Union
[TypeVar
(R
,float16
,float32
,float64
),TypeVar
(C
,complex64
,complex128
),TypeVar
(Z
,int16
,int32
,int64
),TypeVar
(N
,uint16
,uint32
,uint64
)]]]) – the (batched) array in Fock representation.batched – whether the array input has a batch dimension.
Note: The args can be passed non-batched, as they will be automatically broadcasted to the correct batch shape.
Attributes
Methods
conj
()The conjugate of this Fock object.
from_ansatz
(ansatz)Returns a Fock object from an ansatz object.
reorder
(order)Reorders the indices of the array with the given order.
trace
(idxs1, idxs2)Implements the partial trace over the given index pairs.