Gates¶
The built-in quantum gates of Piquasso.
Gates can be characterized by a unitary operator \(U\), which describes the time evolution of quantum states as
where \(\rho\) is a density operator.
Gates with at most quadratic Hamiltonians are called linear gates. Evolution of the ladder operators by linear gates could be expressed in the form
where \(S_{(c)} \in \operatorname{Sp}(2d, \mathbb{R})\) is a symplectic matrix in the complex form, \(\boldsymbol{\beta} = [\boldsymbol{\alpha}, \overline{\boldsymbol{\alpha}}]\), \(\alpha \in \mathbb{C}^{d}\), and
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 \(\boldsymbol{\beta}\).
- class Interferometer(matrix: ndarray)¶
Applies a general interferometer gate.
The unitary operator corresponding to an interferometer can be written as
\[I(U) = \exp(i \hat{H}),\]where \(\hat{H}\) is a quadratic Hamiltonian
\[\begin{split}\hat{H} = \boldsymbol{\xi}^\dagger H \boldsymbol{\xi}, \qquad H = \frac{1}{2} \begin{bmatrix} A & \\ & \overline{A} \end{bmatrix},\end{split}\]where \(A\) is self-adjoint and \(\boldsymbol{\xi}\) is defined in Eq. (2). The interferometer is parametrized as \(U = e^{iA}\).
The interpretation of the interferometer matrix \(U\) is that it is the one-particle unitary matrix, i.e., the matrix which acts on single particles. Moreover, 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} & \overline{U} \end{bmatrix},\end{split}\]where \(U \in \mathbb{C}^{d \times d}\) is the interferometer matrix, and \(S_{(c)}\) is defined by Eq. (1).
- Parameters:
matrix (numpy.ndarray) – The unitary interferometer matrix, corresponding to a passive transformation on the one-particle subspace.
- class Beamsplitter(theta: float = 0.7853981633974483, phi: float = 0.0)¶
Applies a beamsplitter gate.
The unitary operator of the beamsplitter gate 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 beamsplitter transfer matrix is given by
\[\begin{split}U = \begin{bmatrix} t & -\overline{r} \\ r & t \end{bmatrix},\end{split}\]where \(t = \cos(\theta)\) and \(r = e^{i \phi} \sin(\theta)\). Moreover, the symplectic representation of the beamsplitter gate is
\[\begin{split}S_{(c)} = U \oplus \overline{U} = \begin{bmatrix} t & -\overline{r} & & \\ r & t & & \\ & & t & -r \\ & & \overline{r} & t \end{bmatrix},\end{split}\]where \(S_{(c)}\) is defined by Eq. (1).
- class Beamsplitter5050¶
Applies a 50:50 beamsplitter gate.
This gate corresponds to a regular beamsplitter gate
Beamsplitterwith parameters \(\theta = \frac{\pi}{4}\) and \(\phi = 0\).The beamsplitter transfer matrix is given by
\[\begin{split}U = \frac{1}{\sqrt{2}} \begin{bmatrix} 1 & -1 \\ 1 & 1 \end{bmatrix}.\end{split}\]
- 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}\]where \(S_{(c)}\) is defined by Eq. (1).
- 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}\) and \(S_{(c)}\) is defined by Eq. (1).
- class Fourier¶
Applies a Fourier gate.
The Fourier gate simply transforms the quadratures as follows:
\[\begin{split}F^\dagger \hat{x} F &= -\hat{p} \\ F^\dagger \hat{p} F &= \hat{x}\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}\]where \(S_{(c)}\) is defined by Eq. (1).
Note
Corresponds to the
Phaseshiftergate 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 \\ \overline{A} & \overline{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}\]and \(S_{(c)}\) is defined by Eq. (1).
- Parameters:
passive (numpy.ndarray) – The passive submatrix \(P\) of the symplectic matrix corresponding to the transformation.
active (numpy.ndarray) – The active submatrix \(A\) 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 single-mode squeezing gate.
The unitary operator corresponding to the squeezing gate is
\[S_{i} (z) = \exp \left ( \frac{1}{2}(\overline{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}\]where \(S_{(c)}\) is defined by Eq. (1). The unitary operator corresponding to the squeezing gate is
\[S(z) = \exp \left ( \frac{1}{2}(\overline{z} a_i^2 - z a_i^{\dagger 2}) \right ),\]where \(z = re^{i\phi}\).
- 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}\]where \(S_{(c)}\) is defined by Eq. (1).
- Parameters:
s (float) – The parameter quadratic phase gate.
- 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}(\overline{z} a_i a_j - z a_i^\dagger a_j^\dagger ) \right ).\]In the bosonic setting, 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}\]where \(S_{(c)}\) is defined by Eq. (1).
In the fermionic setting, an analoguous definition is used: the bosonic ladder operators are just exchanged to fermionic ones. For two fermionic modes, the action on \(\ket{00}\) and \(\ket{11}\) is simply given as
\[\begin{split}S_{12} (z) \ket{00} &= \cos (r/2) \ket{00} - e^{i \phi} \sin (r/2) \ket{11}, \\ S_{12} (z) \ket{11} &= \cos (r/2) \ket{11} + e^{-i \phi} \sin (r/2) \ket{00},\end{split}\]where \(z = r e^{i \phi}\).
Note
This gate is equivalent to
\[S_{ij} (z) = B_{ij}(\pi/4, 0) [S_i(-z) \otimes S_j(z)] B_{ij}(-\pi/4, 0).\]
- 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_{(c)} = \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}\]where \(S_{(c)}\) is defined by Eq. (1).
s (float): The parameter of the controlled-X gate.
- 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_{(c)} = \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}\]where \(S_{(c)}\) is defined by Eq. (1).
s (float): The parameter of the controlled-Z gate.
- class Displacement(r: float, phi: float | None = 0.0)¶
Displacement gate.
The displacement gate evolves the ladder operators by
\[\begin{split}\boldsymbol{\xi} \mapsto \boldsymbol{\xi} + \begin{bmatrix} \alpha \\ \overline{\alpha} \end{bmatrix},\end{split}\]where \(\alpha \in \mathbb{C}\) and \(\boldsymbol{\xi} = [a, a^\dagger]^T\) is a formal vector of the ladder operators.
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}.\]For more intuition, one can consider transforming the quadrature operators \(\hat{x}_j\) and \(\hat{p}_j\):
\[\begin{split}D^\dagger_j(\alpha) \begin{bmatrix} \hat{x}_j \\ \hat{p}_j \end{bmatrix} D_j(\alpha) = \begin{bmatrix} \hat{x}_j + \sqrt{2 \hbar} \mathrm{Re} \alpha I \\ \hat{p}_j + \sqrt{2 \hbar} \mathrm{Im} \alpha I \end{bmatrix}.\end{split}\]This means, that the parameter \(\alpha \in \mathbb{C}\) describes the shift of the quadrature operators in the two-dimensional phase space, i.e., the real part is responsible for a shift in position, and the imaginary part for a shift in momentum.
Note
The specified displacement is automatically scaled by \(\sqrt{2 \hbar}\).
- 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 ).\]Since the Kerr gate is non-linear, the ladder operators are not evolved into a linear combination of ladder operators, which can be attributed to the fact that the commutator \([a_j, \hat{n}^2_j]\) is not a linear combination of the ladder operators, i.e., \([a_j, \hat{n}^2_j] = a_j (2\hat{n}_j-I)\). Hence, the Kerr gate transforms the ladder operators as
\[\begin{split}K^\dagger_j(\kappa) a_j K_j(\kappa) &= a_j \exp\left(i \kappa \left( 2 \hat{n}_j - I\right)\right),\\ K^\dagger_j(\kappa) a_j^\dagger K_j(\kappa) &= a_j^\dagger \exp\left( -i \kappa \left(2 \hat{n}_j - I \right) \right).\end{split}\]Note
This is a non-linear gate, therefore it cannot be used with
GaussianState.- Parameters:
xi (float) – The magnitude of the Kerr nonlinear term.
- class SNAP(theta: ndarray)¶
Selective Number-dependent Arbitrary Phase (SNAP) gate.
The definition of the SNAP gate is
\[\operatorname{SNAP}(\vec{\theta}) = \sum_{n=0}^\infty e^{i \theta_n} |n\rangle \langle n|,\]where \(\vec{\theta} = (\theta_0, \theta_1, \dots)\) is a vector of angles. The SNAP gate transforms the annihilation operator as
\[\operatorname{SNAP}^\dagger(\vec{\theta}) a \operatorname{SNAP}(\vec{\theta}) = \sum_{n=0}^\infty e^{i (\theta_n - \theta_{n+1})} |n\rangle \langle n| a.\]Note
This is a non-linear gate, therefore it could not be used with
GaussianState.- Parameters:
theta (numpy.ndarray) – A vector of angles.
- 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}^\dagger (\xi) a_i CK_{ij} (\xi) &= a_i \exp(- i \xi n_j) \\ CK_{ij}^\dagger (\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 symmetric.