mm.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 (@).

>>> from mrmustard.physics.representations import Fock

>>> # initialize Fock objects
>>> array1 = np.random.random((5,7,8))
>>> array2 = np.random.random((5,7,8))
>>> array3 = np.random.random((3,5,7,8)) # where 3 is the batch.
>>> fock1 = Fock(array1)
>>> fock2 = Fock(array2)
>>> fock3 = Fock(array3, batched=True)

>>> # 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.

ansatz

The ansatz of the representation.

array

The array from the ansatz.

ansatz

The ansatz of the representation.

array

The array from the ansatz.

conj()

The conjugate of this Fock object.

from_ansatz(ansatz)

Returns a Fock object from an ansatz object.

reduce(shape)

Returns a new Fock with a sliced array.

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

reduce(shape)[source]

Returns a new Fock with a sliced array.

>>> from mrmustard import math
>>> from mrmustard.physics.representations import Fock

>>> array1 = math.arange(27).reshape((3, 3, 3))
>>> fock1 = Fock(array1)

>>> fock2 = fock1.reduce(3)
>>> assert fock1 == fock2

>>> fock3 = fock1.reduce(2)
>>> array3 = [[[0, 1], [3, 4]], [[9, 10], [12, 13]]]
>>> assert fock3 == Fock(array3)

>>> fock4 = fock1.reduce((2, 1, 3, 1))
>>> array4 = [[[0], [3], [6]]]
>>> assert fock4 == Fock(array4)
Parameters:

shape (Union[int, Iterable[int]]) – The shape of the array of the returned Fock.

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.