CV quantum operations

Module name: pennylane.ops.cv

This section contains the available built-in continuous-variable quantum operations supported by PennyLane, as well as their conventions.

Note

For the Heisenberg matrix representation of CV operations, we use the ordering \((\hat{\mathbb{1}}, \hat{x}, \hat{p})\) for single modes and \((\hat{\mathbb{1}}, \hat{x}_1, \hat{p}_2, \hat{x}_1,\hat{p}_2)\) for two modes .

Gates

Rotation(phi, wires) Phase space rotation
Squeezing(r, phi, wires) Phase space squeezing.
Displacement(a, phi, wires) Phase space displacement.
Beamsplitter(theta, phi, wires) Beamsplitter interaction.
TwoModeSqueezing(r, phi, wires) Phase space two-mode squeezing.
QuadraticPhase(s, wires) Quadratic phase shift.
ControlledAddition(s, wires) Controlled addition operation.
ControlledPhase(s, wires) Controlled phase operation.
Kerr(kappa, wires) Kerr interaction.
CrossKerr(kappa, wires) Cross-Kerr interaction.
CubicPhase(gamma, wires) Cubic phase shift.
Interferometer(U, wires) A linear interferometer transforming the bosonic operators according to the unitary matrix \(U\).

State preparation

CoherentState(a, phi, wires) Prepares a coherent state.
SqueezedState(r, phi, wires) Prepares a squeezed vacuum state.
DisplacedSqueezedState(a, phi_a, r, phi_r, wires) Prepares a displaced squeezed vacuum state.
ThermalState(nbar, wires) Prepares a thermal state.
GaussianState(r, V, wires) Prepare subsystems in a given Gaussian state.
FockState(n, wires) Prepares a single Fock state.
FockStateVector(state, wires) Prepare subsystems using the given ket vector in the Fock basis.
FockDensityMatrix(state, wires) Prepare subsystems using the given density matrix in the Fock basis.
CatState(a, phi, p, wires) Prepares a cat state.

Code details

class Rotation(phi, wires)[source]

Phase space rotation

\[R(\phi) = \exp\left(i \phi \ad \a\right)=\exp\left(i \frac{\phi}{2} \left(\frac{\x^2+ \p^2}{\hbar}-\I\right)\right).\]

Details:

  • Number of wires: 1

  • Number of parameters: 1

  • Gradient recipe: \(\frac{d}{dr}R(r) = \frac{1}{2} \left[R(\phi+\pi/2) - R(\phi-\pi/2)\right]\)

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0 & 0\\ 0 & \cos\phi & -\sin\phi\\ 0 & \sin\phi & \cos\phi \end{bmatrix}\end{split}\]
Parameters:phi (float) – the rotation angle
class Squeezing(r, phi, wires)[source]

Phase space squeezing.

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

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

Details:

  • Number of wires: 1

  • Number of parameters: 2

  • Gradient recipe: \(\frac{d}{dr}S(r,\phi) = \frac{1}{2\sinh s} \left[S(r+s, \phi) - S(r-s, \phi)\right]\), where \(s\) is an arbitrary real number (\(0.1\) by default).

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cosh r - \cos\phi \sinh r & -\sin\phi\sinh r \\ 0 & -\sin\phi\sinh r & \cosh r+\cos\phi\sinh r \end{bmatrix}\end{split}\]
Parameters:
  • r (float) – squeezing amount
  • phi (float) – squeezing phase angle \(\phi\)
  • wires (Sequence[int] or int) – the wire the operation acts on
class Displacement(a, phi, wires)[source]

Phase space displacement.

\[D(a,\phi) = D(\alpha) = \exp(\alpha \ad -\alpha^* \a) = \exp\left(-i\sqrt{\frac{2}{\hbar}}(\re(\alpha) \hat{p} -\im(\alpha) \hat{x})\right).\]

where \(\alpha = ae^{i\phi}\) has magnitude \(a\geq 0\) and phase \(\phi\). The result of applying a displacement to the vacuum is a coherent state \(D(\alpha)\ket{0} = \ket{\alpha}\).

Details:

  • Number of wires: 1

  • Number of parameters: 2

  • Gradient recipe: \(\frac{d}{dr}D(a,\phi) = \frac{1}{2s} \left[D(a+s, \phi) - D(a-s, \phi)\right]\), where \(s\) is an arbitrary real number (\(0.1\) by default)

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0 & 0 \\ 2a\cos\phi & 1 & 0 \\ 2a\sin\phi & 0 & 1\end{bmatrix}\end{split}\]
Parameters:
  • a (float) – displacement magnitude \(a=|\alpha|\)
  • phi (float) – phase angle \(\phi\)
  • wires (Sequence[int] or int) – the wire the operation acts on
class Beamsplitter(theta, phi, wires)[source]

Beamsplitter interaction.

\[B(\theta,\phi) = \exp\left(\theta (e^{i \phi} \a \hat{b}^\dagger -e^{-i \phi}\ad \hat{b}) \right).\]

Details:

  • Number of wires: 2

  • Number of parameters: 2

  • Gradient recipe: \(\frac{d}{dr}B(r,\phi) = \frac{1}{2} \left[B(\theta+\pi/2, \phi) - B(\theta-\pi/2, \phi)\right]\)

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0 & 0 & 0 & 0\\ 0 & \cos\theta & 0 & -\cos\phi\sin\theta & -\sin\phi\sin\theta \\ 0 & 0 & \cos\theta & \sin\phi\sin\theta & -\cos\phi\sin\theta\\ 0 & \cos\phi\sin\theta & -\sin\phi\sin\theta & \cos\theta & 0\\ 0 & \sin\phi\sin\theta & \cos\phi\sin\theta & 0 & \cos\theta \end{bmatrix}\end{split}\]
Parameters:
  • theta (float) – Transmittivity angle \(\theta\). The transmission amplitude of the beamsplitter is \(t = \cos(\theta)\). The value \(\theta=\pi/4\) gives the 50-50 beamsplitter.
  • phi (float) – Phase angle \(\phi\). The reflection amplitude of the beamsplitter is \(r = e^{i\phi}\sin(\theta)\). The value \(\phi = \pi/2\) gives the symmetric beamsplitter.
  • wires (Sequence[int] or int) – the wire the operation acts on
class TwoModeSqueezing(r, phi, wires)[source]

Phase space two-mode squeezing.

\[S_2(z) = \exp\left(z^* \a \hat{b} -z \ad \hat{b}^\dagger \right) = \exp\left(r (e^{-i\phi} \a\hat{b} -e^{i\phi} \ad \hat{b}^\dagger \right).\]

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

Details:

  • Number of wires: 2

  • Number of parameters: 2

  • Gradient recipe: \(\frac{d}{dr}S_2(r,\phi) = \frac{1}{2\sinh s} \left[S_2(r+s, \phi) - S_2(r-s, \phi)\right]\), where \(s\) is an arbitrary real number (\(0.1\) by default).

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 0 & \cosh r & 0 & \sinh r \cos \phi & \sinh r \sin \phi\\ 0 & 0 & \cosh r & \sinh r \sin \phi & -\sinh r \cos \phi\\ 0 & \sinh r \cos \phi & \sinh r \sin \phi & \cosh r & 0\\ 0 & \sinh r \sin \phi & -\sinh r \cos \phi & 0 & \cosh r \end{bmatrix}\end{split}\]
Parameters:
  • r (float) – squeezing amount
  • phi (float) – squeezing phase angle \(\phi\)
  • wires (Sequence[int] or int) – the wire the operation acts on
class QuadraticPhase(s, wires)[source]

Quadratic phase shift.

\[P(s) = e^{i \frac{s}{2} \hat{x}^2/\hbar}.\]

Details:

  • Number of wires: 1

  • Number of parameters: 1

  • Gradient recipe: None (uses finite difference)

  • Gradient recipe: \(\frac{d}{dr}S_2(r,\phi) = \frac{1}{2\sinh s} \left[S_2(r+s, \phi) - S_2(r-s, \phi)\right]\), where \(s\) is an arbitrary real number (\(0.1\) by default).

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & s & 1 \\ \end{bmatrix}\end{split}\]
Parameters:
  • s (float) – parameter
  • wires (Sequence[int] or int) – the wire the operation acts on
class ControlledAddition(s, wires)[source]

Controlled addition operation.

\[\text{CX}(s) = \int dx \ket{x}\bra{x} \otimes D\left({\frac{1}{\sqrt{2\hbar}}}s x\right) = e^{-i s \: \hat{x} \otimes \hat{p}/\hbar}.\]

Details:

  • Number of wires: 2

  • Number of parameters: 1

  • Gradient recipe: None (uses finite difference)

  • Gradient recipe: \(\frac{d}{dr}S_2(r,\phi) = \frac{1}{2\sinh s} \left[S_2(r+s, \phi) - S_2(r-s, \phi)\right]\), where \(s\) is an arbitrary real number (\(0.1\) by default).

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & -s \\ 0 & s & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 1 \end{bmatrix}\end{split}\]
Parameters:
  • s (float) – addition multiplier
  • wires (Sequence[int] or int) – the wire the operation acts on
class ControlledPhase(s, wires)[source]

Controlled phase operation.

\[\text{CX}(s) = \iint dx dy \: e^{i sxy/\hbar} \ket{x,y}\bra{x,y} = e^{i s \: \hat{x} \otimes \hat{x}/\hbar}.\]

Details:

  • Number of wires: 2

  • Number of parameters: 1

  • Gradient recipe: None (uses finite difference)

  • Gradient recipe: \(\frac{d}{dr}S_2(r,\phi) = \frac{1}{2\sinh s} \left[S_2(r+s, \phi) - S_2(r-s, \phi)\right]\), where \(s\) is an arbitrary real number (\(0.1\) by default).

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & s & 0 \\ 0 & 0 & 0 & 1 & 0 \\ 0 & s & 0 & 0 & 1 \end{bmatrix}\end{split}\]
Parameters:
  • s (float) – phase shift multiplier
  • wires (Sequence[int] or int) – the wire the operation acts on
class Kerr(kappa, wires)[source]

Kerr interaction.

\[K(\kappa) = e^{i \kappa \hat{n}^2}.\]

Details:

  • Number of wires: 1
  • Number of parameters: 1
  • Gradient recipe: None (uses finite difference)
Parameters:
  • kappa (float) – parameter
  • wires (Sequence[int] or int) – the wire the operation acts on
class CrossKerr(kappa, wires)[source]

Cross-Kerr interaction.

\[CK(\kappa) = e^{i \kappa \hat{n}_1\hat{n}_2}.\]

Details:

  • Number of wires: 2
  • Number of parameters: 1
  • Gradient recipe: None (uses finite difference)
Parameters:
  • kappa (float) – parameter
  • wires (Sequence[int] or int) – the wire the operation acts on
class CubicPhase(gamma, wires)[source]

Cubic phase shift.

\[V(\gamma) = e^{i \frac{\gamma}{3} \hat{x}^3/\hbar}.\]

Details:

  • Number of wires: 1
  • Number of parameters: 1
  • Gradient recipe: None (uses finite difference)
Parameters:
  • gamma (float) – parameter
  • wires (Sequence[int] or int) – the wire the operation acts on
class Interferometer(U, wires)[source]

A linear interferometer transforming the bosonic operators according to the unitary matrix \(U\).

Note

This operation implements a fixed linear interferometer given a known unitary matrix.

If you instead wish to parameterize the interferometer, and calculate the gradient/optimize with respect to these parameters, consider instead the pennylane.template.Interferometer() template, which constructs an interferometer from a combination of beamsplitters and rotation gates.

Details:

  • None (applied to the entire subsystem)

  • Number of parameters: 1

  • Gradient recipe: None (uses finite difference)

  • Heisenberg representation:

    \[\begin{split}M = \begin{bmatrix} 1 & 0\\ 0 & S\\ \end{bmatrix}\end{split}\]

where \(S\) is the Gaussian symplectic transformation representing the interferometer.

Parameters:
  • U (array) – A shape (len(wires), len(wires)) complex unitary matrix
  • wires (Sequence[int] or int) – the wires the operation acts on
class CoherentState(a, phi, wires)[source]

Prepares a coherent state.

Details:

  • Number of wires: 1
  • Number of parameters: 2
  • Gradient recipe: None (uses finite difference)
Parameters:
  • a (float) – displacement magnitude \(r=|\alpha|\)
  • phi (float) – phase angle \(\phi\)
  • wires (Sequence[int] or int) – the wire the operation acts on
class SqueezedState(r, phi, wires)[source]

Prepares a squeezed vacuum state.

Details:

  • Number of wires: 1
  • Number of parameters: 2
  • Gradient recipe: None (uses finite difference)
Parameters:
  • r (float) – squeezing magnitude
  • phi (float) – squeezing angle \(\phi\)
  • wires (Sequence[int] or int) – the wire the operation acts on
class DisplacedSqueezedState(a, phi_a, r, phi_r, wires)[source]

Prepares a displaced squeezed vacuum state.

A displaced squeezed state is prepared by squeezing a vacuum state, and then applying a displacement operator,

\[\ket{\alpha,z} = D(\alpha)\ket{0,z} = D(\alpha)S(z)\ket{0},\]

with the displacement parameter \(\alpha=ae^{i\phi_a}\) and the squeezing parameter \(z=re^{i\phi_r}\).

Details:

  • Number of wires: 1
  • Number of parameters: 3
  • Gradient recipe: None (uses finite difference)
Parameters:
  • a (float) – displacement magnitude \(a=|\alpha|\)
  • phi_a (float) – displacement angle \(\phi_a\)
  • r (float) – squeezing magnitude \(r=|z|\)
  • phi_r (float) – squeezing angle \(\phi_r\)
  • wires (Sequence[int] or int) – the wire the operation acts on
class ThermalState(nbar, wires)[source]

Prepares a thermal state.

Details:

  • Number of wires: 1
  • Number of parameters: 1
  • Gradient recipe: None (uses finite difference)
Parameters:
  • nbar (float) – mean thermal population of the mode
  • wires (Sequence[int] or int) – the wire the operation acts on
class GaussianState(r, V, wires)[source]

Prepare subsystems in a given Gaussian state.

Details:

  • Number of wires: None (applied to the entire subsystem)
  • Number of parameters: 1
  • Gradient recipe: None (uses finite difference)
Parameters:
  • r (array) – a length \(2N\) vector of means, of the form \((\x_0,\dots,\x_{N-1},\p_0,\dots,\p_{N-1})\)
  • V (array) – the \(2N\times 2N\) (real and positive definite) covariance matrix
class FockState(n, wires)[source]

Prepares a single Fock state.

Details:

  • Number of wires: 1
  • Number of parameters: 1
  • Gradient recipe: None (not differentiable)
Parameters:
  • n (int) – Fock state to prepare
  • wires (Sequence[int] or int) – the wire the operation acts on
class FockStateVector(state, wires)[source]

Prepare subsystems using the given ket vector in the Fock basis.

Details:

  • Number of wires: None (applied to the entire subsystem)
  • Number of parameters: 1
  • Gradient recipe: None (uses finite difference)
Parameters:state (array) – a single ket vector, for single mode state preparation, or a multimode ket, with one array dimension per mode
class FockDensityMatrix(state, wires)[source]

Prepare subsystems using the given density matrix in the Fock basis.

Details:

  • Number of wires: None (applied to the entire subsystem)
  • Number of parameters: 1
  • Gradient recipe: None (uses finite difference)
Parameters:state (array) – a single mode matrix \(\rho_{ij}\), or a multimode tensor \(\rho_{ij,kl,\dots,mn}\), with two indices per mode
class CatState(a, phi, p, wires)[source]

Prepares a cat state.

A cat state is the coherent superposition of two coherent states,

\[\ket{\text{cat}(\alpha)} = \frac{1}{N} (\ket{\alpha} +e^{ip\pi} \ket{-\alpha}),\]

where \(\ket{\pm\alpha} = D(\pm\alpha)\ket{0}\) are coherent states with displacement parameters \(\pm\alpha=\pm ae^{i\phi}\) and \(N = \sqrt{2 (1+\cos(p\pi)e^{-2|\alpha|^2})}\) is the normalization factor.

Details:

  • Number of wires: 1
  • Number of parameters: 3
  • Gradient recipe: None (uses finite difference)
Parameters:
  • a (float) – displacement magnitude \(a=|\alpha|\)
  • phi (float) – displacement angle \(\phi\)
  • p (float) – parity, where \(p=0\) corresponds to an even cat state, and \(p=1\) an odd cat state.
  • wires (Sequence[int] or int) – the wire the operation acts on