Skip to content

dq.snap_gate

snap_gate(phase: ArrayLike) -> QArray

Returns a SNAP gate.

The selective number-dependent arbitrary phase (SNAP) gate imparts a different phase \(\theta_k\) to each Fock state \(\ket{k}\bra{k}\). It is defined by $$ \mathrm{SNAP}(\theta_0,\dots,\theta_{n-1}) = \sum_{k=0}^{n-1} e^{i\theta_k} \ket{k}\bra{k}. $$

Parameters

  • phase (array-like of shape (..., n)) –

    Phase for each Fock state. The last dimension of the array n defines the Hilbert space dimension.

Returns

(qarray of shape (..., n, n)) SNAP gate operator.

Examples

>>> dq.snap_gate([0, 1, 2])
QArray: shape=(3, 3), dims=(3,), dtype=complex64, layout=dense
[[ 1.   +0.j     0.   +0.j     0.   +0.j   ]
 [ 0.   +0.j     0.54 +0.841j  0.   +0.j   ]
 [ 0.   +0.j     0.   +0.j    -0.416+0.909j]]
>>> dq.snap_gate([[0, 1, 2], [2, 3, 4]]).shape
(2, 3, 3)