Gates#

Gates can be characterized by a unitary operator \(U\), which evolves the quantum state in the following manner

\[\rho' = U \rho U^\dagger\]

Gates with at most quadratic Hamiltonians are called linear gates. Evolution of the ladder operators by linear gates could be expressed in the form

\[U^\dagger \xi U = S_{(c)} \xi + d,\]

where \(S_{(c)} \in \operatorname{Sp}(2d, \mathbb{R})\), \(d \in \mathbb{C}^{2d}\),

\[\xi = \begin{bmatrix} a_1, \dots, a_d, a_1^\dagger, \dots, a_d^\dagger \end{bmatrix}^T,\]

where \(a_1^\dagger, ..., a_d^\dagger\) and \(a_1, \dots, a_d\) are the creation and annihilation operators, respectively.

Most of the gates defined here are linear gates, which can be characterized by \(S_{(c)}\) and \(d\).

class Interferometer(matrix: ndarray)#

Applies a general interferometer gate.

The general unitary operator can be written as

\[I = \exp \left ( i \sum_{i, j = 1}^d H_{i j} a_i^\dagger a_j \right ),\]

where the parameter U and \(H\) is related by

\[U = \exp \left ( i H \right ).\]

The evolution of the ladder operators can be described by

\[\begin{split}S_{(c)} = \begin{bmatrix} U & 0_{d \times d} \\ 0_{d \times d} & U^* \end{bmatrix},\end{split}\]

where \(U \in \mathbb{C}^{d \times d}\) is a unitary matrix.

Parameters:

matrix (numpy.ndarray) – The unitary interferometer matrix, corresponding to a passive transformation on the one-particle subspace.

class Beamsplitter(theta: float = 0.0, phi: float = 0.7853981633974483)#

Applies a beamsplitter gate.

The general unitary operator can be written as

\[B_{ij} (\theta, \phi) = \exp \left ( \theta e^{i \phi} a^\dagger_i a_j - \theta e^{- i \phi} a^\dagger_j a_i \right ).\]

The symplectic representation of the beamsplitter gate is

\[\begin{split}S_{(c)} = \begin{bmatrix} t & -r^* & & \\ r & t & & \\ & & t & -r \\ & & r^* & t \end{bmatrix},\end{split}\]

where \(t = \cos(\theta)\) and \(r = e^{i \phi} \sin(\theta)\).

Parameters:
  • phi (float) – Phase angle of the beamsplitter. (defaults to \(\phi = \pi/2\) that gives a symmetric beamsplitter)

  • theta (float) – The transmissivity angle of the beamsplitter. (defaults to \(\theta=\pi/4\) that gives a 50-50 beamsplitter)

class Phaseshifter(phi: float)#

Applies a rotation or a phaseshifter gate.

The unitary operator corresponding to the phaseshifter gate on the \(i\)-th mode is

\[R_i (\phi) = \exp \left ( i \phi a_i^\dagger a_i \right ).\]

The symplectic representation of the phaseshifter gate is

\[\begin{split}S_{(c)} = \begin{bmatrix} e^{i \phi} & 0 \\ 0 & e^{- i \phi} \end{bmatrix}.\end{split}\]
Parameters:

phi (float) – The angle of the rotation.

class MachZehnder(int_: float, ext: float)#

Mach-Zehnder interferometer.

The Mach-Zehnder interferometer is equivalent to

\[MZ(\phi_{int}, \phi_{ext}) = B(\pi/4, \pi/2) (R(\phi_{int}) \oplus \mathbb{1}) B(\pi/4, \pi/2) (R(\phi_{ext}) \oplus \mathbb{1}).\]

The symplectic representation of the Mach-Zehnder interferometer is

\[\begin{split}S_{(c)} = \begin{bmatrix} e^{i \phi_{ext} } (e^{i \phi_{int} } - 1) & i (e^{i \phi_{int} } + 1) & & \\ i e^{i \phi_{ext} } (e^{i \phi_{int} } + 1) & 1 - e^{i \phi_{int} } & & \\ & & e^{-i \phi_{ext} } (e^{-i \phi_{int} } - 1) & -i (e^{-i \phi_{int} } + 1) \\ & & -i e^{-i \phi_{ext} } (e^{-i \phi_{int} } + 1) & 1 - e^{-i \phi_{int} } \end{bmatrix},\end{split}\]

where \(\phi_{int}, \phi_{ext} \in \mathbb{R}\).

Parameters:
  • int (float) – The internal angle.

  • ext (float) – The external angle.

class Fourier#

Applies a Fourier gate. It simply transforms the quadratures as follows:

\[\begin{split}-\hat{p} = \operatorname{\textit{F}} \hat{x} \operatorname{\textit{F}}^\dagger \\ \hat{x} = \operatorname{\textit{F}} \hat{p} \operatorname{\textit{F}}^\dagger\end{split}\]

The unitary operator corresponding to the Fourier gate on the \(i\)-th mode is

\[F_{i} = \exp \left ( i \frac{\pi}{2} a_i^\dagger a_i \right ).\]

The symplectic representation of the Fourier gate is

\[\begin{split}S_{(c)} = \begin{bmatrix} i & 0 \\ 0 & -i \\ \end{bmatrix}.\end{split}\]

Note

Corresponds to the Phaseshifter gate with \(\phi = \pi/2\).

class GaussianTransform(passive: ndarray, active: ndarray)#

Applies a Gaussian transformation gate.

The symplectic representation of the Gaussian gate is

\[\begin{split}S_{(c)} = \begin{bmatrix} P & A \\ A^* & P^* \end{bmatrix},\end{split}\]

where \(P, A \in C^{d \times d}\) fulfilling the relations

\[\begin{split}P P^\dagger - A A^\dagger &= I_{d \times d} \\ P A^T &= A P^T\end{split}\]
Parameters:
  • passive (numpy.ndarray) – The passive submatrix of the symplectic matrix corresponding to the transformation.

  • active (numpy.ndarray) – The active submatrix of the symplectic matrix corresponding to the transformation.

Raises:

InvalidParameters – Raised if the parameters do not form a symplectic matrix.

class Squeezing(r: float, phi: float = 0.0)#

Applies the squeezing gate.

The unitary operator corresponding to the squeezing gate is

\[S_{i} (z) = \exp \left ( \frac{1}{2}(z^* a_i^2 - z a_i^{\dagger 2} ) \right ).\]

The symplectic representation of the squeezing gate is

\[\begin{split}S_{(c)} = \begin{bmatrix} \cosh r & - e^{i \phi} \sinh r \\ - e^{- i \phi} \sinh r & \cosh r \end{bmatrix}.\end{split}\]

The unitary squeezing operator is

\[S(z) = \exp \left ( \frac{1}{2}(z^* a_i^2 - z a_i^{\dagger 2}) \right ),\]

where \(z = re^{i\phi}\).

Parameters:
  • r (float) – The amplitude of the squeezing instruction.

  • phi (float) – The squeezing angle.

class QuadraticPhase(s: float)#

Applies the quadratic phase instruction to the state.

The unitary operator corresponding to the Fourier gate is

\[QP_{i} (s) = \exp \left ( i \frac{s}{2 \hbar} x_i^2 \right ).\]

The symplectic representation of the quadratic phase gate is

\[\begin{split}S_{(c)} = \begin{bmatrix} 1 + i \frac{s}{2} & i \frac{s}{2} \\ -i \frac{s}{2} & 1 - i \frac{s}{2} \end{bmatrix}.\end{split}\]
class Squeezing2(r: float, phi: float = 0.0)#

Applies the two-mode squeezing gate to the state.

The unitary operator corresponding to the two-mode squeezing gate is

\[S_{ij} (z) = \exp \left ( \frac{1}{2}(z^* a_i a_j - z a_i^\dagger a_j^\dagger ) \right ).\]

The symplectic representation of the two-mode squeezing gate is

\[\begin{split}S_{(c)} = \begin{bmatrix} \cosh r & 0 & 0 & e^{i \phi} \sinh r \\ 0 & \cosh r & e^{i \phi} \sinh r & 0 \\ 0 & e^{- i \phi} \sinh r & \cosh r & 0 \\ e^{- i \phi} \sinh r & 0 & 0 & \cosh r \end{bmatrix}.\end{split}\]
Parameters:
  • r (float) – The amplitude of the squeezing instruction.

  • phi (float) – The squeezing angle.

class ControlledX(s: float)#

Applies the controlled X gate to the state.

The unitary operator corresponding to the controlled X gate is

\[CX_{ij} (s) = \exp \left ( -i \frac{s}{\hbar} x_i p_j \right ).\]

The symplectic representation of the controlled X gate is

\[\begin{split}S_{(z)} = \begin{bmatrix} 1 & - \frac{s}{2} & 0 & \frac{s}{2} \\ \frac{s}{2} & 1 & \frac{s}{2} & 0 \\ 0 & \frac{s}{2} & 1 & - \frac{s}{2} \\ \frac{s}{2} & 0 & \frac{s}{2} & 1 \end{bmatrix}.\end{split}\]
class ControlledZ(s: float)#

Applies the controlled Z gate to the state.

The unitary operator corresponding to the controlled Z gate is

\[CZ_{ij} (s) = \exp \left ( -i \frac{s}{\hbar} x_i x_j \right ).\]

The symplectic representation of the controlled Z gate is

\[\begin{split}S_{(z)} = \begin{bmatrix} 1 & i \frac{s}{2} & 0 & i \frac{s}{2} \\ i \frac{s}{2} & 1 & i \frac{s}{2} & 0 \\ 0 & -i \frac{s}{2} & 1 & - i \frac{s}{2} \\ -i \frac{s}{2} & 0 & -i \frac{s}{2} & 1 \end{bmatrix}.\end{split}\]
class Displacement(r: float, phi: float | None = 0.0)#

Phase space displacement instruction.

Evolves the ladder operators by

\[\begin{split}\xi \mapsto \xi + \begin{bmatrix} \alpha \\ \alpha^* \end{bmatrix},\end{split}\]

where \(\alpha \in \mathbb{C}^{d}\).

One must either specify \(\alpha\) only, or the combination of \(r\) and \(\phi\). When \(r\) and \(\phi\) are the given parameters, \(\alpha\) is calculated via:

\[\alpha = r e^{i\phi}\]
Parameters:
  • r (float) – The magnitude of phase space displacement.

  • phi (float) – The angle of phase space displacement

class PositionDisplacement(x: float)#

Position displacement gate. It affects only the \(\hat{x}\) quadrature.

Note

The specified displacement is automatically scaled by \(\sqrt{2 \hbar}\).

Parameters:

x (float) – The position displacement.

class MomentumDisplacement(p: float)#

Momentum displacement gate. It only affects the \(\hat{p}\) quadrature.

Note

The specified displacement is automatically scaled by \(\sqrt{2 \hbar}\).

Parameters:

p (float) – The momentum displacement.

class CubicPhase(gamma: float)#

Cubic Phase gate.

The definition of the Cubic Phase gate is

\[\operatorname{CP}(\gamma) = e^{i \hat{x}^3 \frac{\gamma}{3 \hbar}}\]

The Cubic Phase gate transforms the annihilation operator as

\[\operatorname{CP}^\dagger(\gamma) \hat{a} \operatorname{CP}(\gamma) = \hat{a} + i\frac{\gamma(\hat{a} +\hat{a}^\dagger)^2}{2\sqrt{2/\hbar}}\]

It transforms the \(\hat{p}\) quadrature as follows:

\[\operatorname{CP}^\dagger(\gamma) \hat{p} \operatorname{CP}(\gamma) = \hat{p} + \gamma \hat{x}^2.\]

Note

This is a non-linear gate, therefore it couldn’t be used with GaussianState. Using this gate requires a high cutoff to make the more accurate simulation.

Parameters:

gamma (float) – The Cubic Phase parameter.

class Kerr(xi: float)#

Kerr gate.

The definition of the Kerr gate is

\[K_i (\xi) = \exp \left ( i \xi n_i n_i \right ).\]

The Kerr gate transforms the annihilation operator as

\[K(\xi) a K(\xi)^\dagger = a \exp(- i \xi (1 + 2 n)).\]

Note

This is a non-linear gate, therefore it couldn’t be used with GaussianState.

Parameters:

xi (float) – The magnitude of the Kerr nonlinear term.

class CrossKerr(xi: float)#

Cross-Kerr gate.

The definition of the Cross-Kerr gate is

\[CK_{ij} (\xi) = \exp \left ( i \xi n_i n_j \right )\]

The Cross-Kerr gate transforms the annihilation operators as

\[\begin{split}CK_{ij} (\xi) a_i CK_{ij} (\xi) &= a_i \exp(- i \xi n_j) \\ CK_{ij} (\xi) a_j CK_{ij} (\xi) &= a_j \exp(- i \xi n_i)\end{split}\]

Note

This is a non-linear gate, therefore it couldn’t be used with GaussianState.

Parameters:

xi (float) – The magnitude of the Cross-Kerr nonlinear term.

class Graph(adjacency_matrix: ndarray, mean_photon_number: float = 1.0)#

Applies a graph given its adjacency matrix, see this article for more details. It decomposes the adjacency matrix of a graph into single mode squeezers and interferometers.

Parameters:
  • adjacency_matrix (numpy.ndarray) – A symmetric matrix with a size of \(N \times N\) and it can be real or complex.

  • mean_photon_number (float, optional) – The mean photon number \(\bar{n}\) for a mode. Defaults to \(1.0\).

Raises:

InvalidParameter – If the adjacency matrix is not invertible or not symmetric.