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.

array

The array from the ansatz.

array

The array from the ansatz.

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.

conj()[source]

The conjugate of this Fock object.

classmethod from_ansatz(ansatz)[source]

Returns a Fock object from an ansatz object.

Return type:

Fock

reorder(order)[source]

Reorders the indices of the array with the given order.

Parameters:

order (tuple[int, ...] | list[int]) – The order. Does not need to refer to the batch dimension.

Return type:

Fock

Returns:

The reordered Fock.

trace(idxs1, idxs2)[source]

Implements the partial trace over the given index pairs.

Parameters:
  • idxs1 (tuple[int, ...]) – The first part of the pairs of indices to trace over.

  • idxs2 (tuple[int, ...]) – The second part.

Return type:

Fock

Returns:

The traced-over Fock object.