Skip to content

dq.coherent

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

Returns the ket 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 first dimension of alpha should match the length of dim.

Note

If you provide argument alpha as a list, all elements must be broadcastable.

Returns

(qarray of shape (..., n, 1)) Ket of the coherent state or tensor product of coherent states, with n = prod(dims).

Examples

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

>>> dq.coherent(4, 0.5)
QArray: shape=(4, 1), dims=(4,), dtype=complex64, layout=dense
[[0.882+0.j]
 [0.441+0.j]
 [0.156+0.j]
 [0.047+0.j]]

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

>>> dq.coherent(4, [0.5, 0.5j])
QArray: shape=(2, 4, 1), dims=(4,), dtype=complex64, layout=dense
[[[ 0.882+0.j   ]
  [ 0.441+0.j   ]
  [ 0.156+0.j   ]
  [ 0.047+0.j   ]]

 [[ 0.882+0.j   ]
  [ 0.   +0.441j]
  [-0.156+0.j   ]
  [ 0.   -0.047j]]]

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

>>> dq.coherent((2, 3), (0.5, 0.5j))
QArray: shape=(6, 1), dims=(2, 3), dtype=complex64, layout=dense
[[ 0.775+0.j   ]
 [ 0.   +0.386j]
 [-0.146+0.j   ]
 [ 0.423+0.j   ]
 [ 0.   +0.211j]
 [-0.08 +0.j   ]]

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

>>> alpha1 = np.linspace(0, 1, 5)
>>> alpha2 = np.linspace(0, 1, 7)
>>> dq.coherent((8, 8), (alpha1[None, :], alpha2[:, None])).shape
(7, 5, 64, 1)