Skip to content

dq.coherent_dm

coherent_dm(dim: int | tuple[int, ...], alpha: ArrayLike) -> QArray

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

Parameters:

  • dim –

    Hilbert space dimension of each mode.

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

    Coherent state amplitude for each mode. If dim is a tuple, the last dimension of alpha should match the length of dim.

Returns:

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

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

Examples:

Single-mode coherent state \(\ket{\alpha}\bra{\alpha}\):

>>> dq.coherent_dm(4, 0.5)
QArray: shape=(4, 4), dims=(4,), dtype=complex64, layout=dense
[[0.779+0.j 0.389+0.j 0.137+0.j 0.042+0.j]
 [0.389+0.j 0.195+0.j 0.069+0.j 0.021+0.j]
 [0.137+0.j 0.069+0.j 0.024+0.j 0.007+0.j]
 [0.042+0.j 0.021+0.j 0.007+0.j 0.002+0.j]]

Batched single-mode coherent states \(\{\ket{\alpha_0}\bra{\alpha_0}\!, \ket{\alpha_1}\bra{\alpha_1}\}\):

>>> dq.coherent_dm(4, [0.5, 0.5j]).shape
(2, 4, 4)

Multi-mode coherent state \(\ket{\alpha}\bra{\alpha}\otimes\ket{\beta}\bra{\beta}\):

>>> dq.coherent_dm((2, 3), (0.5, 0.5j)).shape
(6, 6)

Batched multi-mode coherent states \(\{\ket{\alpha_0}\bra{\alpha_0}\otimes\ket{\beta_0}\bra{\beta_0}\!, \ket{\alpha_1}\bra{\alpha_1}\otimes\ket{\beta_1}\bra{\beta_1}\}\):

>>> alpha = [(0.5, 0.5j), (0.5j, 0.5)]
>>> dq.coherent_dm((4, 6), alpha).shape
(2, 24, 24)