Skip to content

dq.fock_dm

fock_dm(dim: int | tuple[int, ...], number: ArrayLike) -> QArray

Returns the density matrix of a Fock state or a tensor product of Fock states.

Parameters:

  • dim –

    Hilbert space dimension of each mode.

  • number (array-like of shape (...) or (..., len(dim))) –

    Fock state number for each mode, of integer type. If dim is a tuple, the last dimension of number should match the length of dim.

Returns:

  • (qarray of shape (..., n, n)) –

    Density matrix of the Fock state or tensor product of Fock states, with n = prod(dims).

Examples:

Single-mode Fock state \(\ket{1}\bra{1}\):

>>> dq.fock_dm(3, 1)
QArray: shape=(3, 3), dims=(3,), dtype=complex64, layout=dense
[[0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 1.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j]]

Batched single-mode Fock states \(\{\ket{0}\bra{0}\!, \ket{1}\bra{1}\!, \ket{2}\bra{2}\}\):

>>> dq.fock_dm(3, [0, 1, 2])
QArray: shape=(3, 3, 3), dims=(3,), dtype=complex64, layout=dense
[[[1.+0.j 0.+0.j 0.+0.j]
  [0.+0.j 0.+0.j 0.+0.j]
  [0.+0.j 0.+0.j 0.+0.j]]

 [[0.+0.j 0.+0.j 0.+0.j]
  [0.+0.j 1.+0.j 0.+0.j]
  [0.+0.j 0.+0.j 0.+0.j]]

 [[0.+0.j 0.+0.j 0.+0.j]
  [0.+0.j 0.+0.j 0.+0.j]
  [0.+0.j 0.+0.j 1.+0.j]]]

Multi-mode Fock state \(\ket{1,0}\bra{1,0}\):

>>> dq.fock_dm((3, 2), (1, 0))
QArray: shape=(6, 6), dims=(3, 2), dtype=complex64, layout=dense
[[0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 1.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]
 [0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j]]

Batched multi-mode Fock states \(\{\ket{0,0}\bra{0,0}\!, \ket{0,1}\bra{0,1}\!, \ket{1,1}\bra{1,1}\!, \ket{2,0}\bra{2,0}\}\):

>>> number = [(0, 0), (0, 1), (1, 1), (2, 0)]
>>> dq.fock_dm((3, 2), number).shape
(4, 6, 6)