Skip to content

dq.snap_gate

snap_gate(phase: ArrayLike) -> Array

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

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

Examples

>>> dq.snap_gate([0, 1, 2])
Array([[ 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]], dtype=complex64)
>>> dq.snap_gate([[0, 1, 2], [2, 3, 4]]).shape
(2, 3, 3)