gate

Contents

gate#

Photonic quantum gates

Classes

Barrier([nmode, wires, cutoff])

Barrier.

BeamSplitter([inputs, nmode, wires, cutoff, ...])

Beam Splitter.

BeamSplitterPhi([inputs, nmode, wires, ...])

Beam Splitter with fixed \(\theta\) at \(\pi/4\).

BeamSplitterSingle([inputs, nmode, wires, ...])

Beam Splitter with a single parameter.

BeamSplitterTheta([inputs, nmode, wires, ...])

Beam Splitter with fixed \(\phi\) at \(\pi/2\).

ControlledX([inputs, nmode, wires, cutoff, ...])

Controlled-X gate.

ControlledZ([inputs, nmode, wires, cutoff, ...])

Controlled-Z gate.

CrossKerr([inputs, nmode, wires, cutoff, ...])

Cross-Kerr gate.

CubicPhase([inputs, nmode, wires, cutoff, ...])

Cubic phase gate.

DelayBS([inputs, ntau, nmode, wires, ...])

Delay loop with BeamSplitterTheta and PhaseShift.

DelayMZI([inputs, ntau, nmode, wires, ...])

Delay loop with MZI.

Displacement([inputs, nmode, wires, cutoff, ...])

Displacement gate.

DisplacementMomentum([inputs, nmode, wires, ...])

Momentum Displacement gate.

DisplacementPosition([inputs, nmode, wires, ...])

Position Displacement gate.

DoubleGate([name, inputs, nmode, wires, ...])

A base class for two-mode photonic quantum gates.

Kerr([inputs, nmode, wires, cutoff, ...])

Kerr gate.

MZI([inputs, nmode, wires, cutoff, den_mat, ...])

Mach-Zehnder Interferometer.

PhaseShift([inputs, nmode, wires, cutoff, ...])

Phase Shifter.

QuadraticPhase([inputs, nmode, wires, ...])

Quadratic phase gate.

SingleGate([name, inputs, nmode, wires, ...])

A base class for single-mode photonic quantum gates.

Squeezing([inputs, nmode, wires, cutoff, ...])

Squeezing gate.

Squeezing2([inputs, nmode, wires, cutoff, ...])

Two-mode Squeezing gate.

UAnyGate(unitary[, nmode, wires, minmax, ...])

Arbitrary unitary gate.

class Barrier(nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None)[source]#

Bases: Gate

Barrier.

Parameters:
  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

extra_repr() str[source]#
forward(x: Any) Any[source]#

Perform a forward pass.

class BeamSplitter(inputs: Any = None, nmode: int = 2, wires: list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: DoubleGate

Beam Splitter.

See https://arxiv.org/abs/2004.11002 Eq.(42b)

Matrix Representation:

\[\begin{split}U_{\text{BS}}(\theta, \phi) = \begin{pmatrix} \cos\left(\theta\right) & -e^{-i\phi} \sin\left(\theta\right) \\ e^{i\phi} \sin\left(\theta\right) & \cos\left(\theta\right) \\ \end{pmatrix}\end{split}\]

Symplectic Transformation:

\[\begin{split}BS^\dagger(\theta, \phi) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} BS(\theta, \phi) = \begin{pmatrix} \mathrm{Re}(U_{\text{BS}}) & -\mathrm{Im}(U_{\text{BS}}) \\ \mathrm{Im}(U_{\text{BS}}) & \mathrm{Re}(U_{\text{BS}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameters of the gate (\(\theta\) and \(\phi\)). Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix(theta: Any, phi: Any) Tensor[source]#

Get the local unitary matrix acting on creation operators.

get_matrix_state(matrix: Tensor) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

See https://arxiv.org/pdf/2004.11002.pdf Eq.(74) and Eq.(75)

get_transform_xp(theta: Any, phi: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) tuple[Tensor, Tensor][source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local unitary matrix acting on creation operators.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class BeamSplitterPhi(inputs: Any = None, nmode: int = 2, wires: list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: BeamSplitter

Beam Splitter with fixed \(\theta\) at \(\pi/4\).

Matrix Representation:

\[\begin{split}U_{\text{BS}}(\phi) = \begin{pmatrix} \frac{\sqrt{2}}{2} & -\frac{\sqrt{2}}{2}e^{-i\phi} \\ \frac{\sqrt{2}}{2}e^{i\phi} & \frac{\sqrt{2}}{2} \\ \end{pmatrix}\end{split}\]

Symplectic Transformation:

\[\begin{split}BS^\dagger(\phi) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} BS(\phi) = \begin{pmatrix} \mathrm{Re}(U_{\text{BS}}) & -\mathrm{Im}(U_{\text{BS}}) \\ \mathrm{Im}(U_{\text{BS}}) & \mathrm{Re}(U_{\text{BS}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

class BeamSplitterSingle(inputs: Any = None, nmode: int = 2, wires: list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, convention: str = 'rx', requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: BeamSplitter

Beam Splitter with a single parameter.

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{BS-Rx}}(\theta) = \begin{pmatrix} \cos\left(\th\right) & i\sin\left(\th\right) \\ i\sin\left(\th\right) & \cos\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{BS-Ry}}(\theta) = \begin{pmatrix} \cos\left(\th\right) & -\sin\left(\th\right) \\ \sin\left(\th\right) & \cos\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{BS-H}}(\theta) = \begin{pmatrix} \cos\left(\th\right) & \sin\left(\th\right) \\ \sin\left(\th\right) & -\cos\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Symplectic Transformation:

\[\begin{split}BS^\dagger(\theta) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} BS(\theta) = \begin{pmatrix} \mathrm{Re}(U_{\text{BS}}) & -\mathrm{Im}(U_{\text{BS}}) \\ \mathrm{Im}(U_{\text{BS}}) & \mathrm{Re}(U_{\text{BS}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • convention (str) – The convention of the type of the beam splitter, including 'rx', 'ry' and 'h'. Default: 'rx'

  • requires_grad (bool) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix acting on creation operators.

get_transform_xp(theta: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) Tensor[source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local unitary matrix acting on creation operators.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class BeamSplitterTheta(inputs: Any = None, nmode: int = 2, wires: list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: BeamSplitter

Beam Splitter with fixed \(\phi\) at \(\pi/2\).

Matrix Representation:

\[\begin{split}U_{\text{BS}}(\theta) = \begin{pmatrix} \cos\left(\theta\right) & i\sin\left(\theta\right) \\ i\sin\left(\theta\right) & \cos\left(\theta\right) \\ \end{pmatrix}\end{split}\]

Symplectic Transformation:

\[\begin{split}BS^\dagger(\theta) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} BS(\theta) = \begin{pmatrix} \mathrm{Re}(U_{\text{BS}}) & -\mathrm{Im}(U_{\text{BS}}) \\ \mathrm{Im}(U_{\text{BS}}) & \mathrm{Re}(U_{\text{BS}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

class ControlledX(inputs: Any = None, nmode: int = 2, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: DoubleGate

Controlled-X gate.

Operator Representation:

\[CX(s) = e^{-i \frac{s}{\hbar} \hat{x}_1 \hat{p}_2}\]

Symplectic Transformation:

\[\begin{split}CX^\dagger(s) \begin{pmatrix} \hat{a}_1 \\ \hat{a}_2 \\ \hat{a}_1^\dagger \\ \hat{a}_2^\dagger \\ \end{pmatrix} CX(s) = \begin{pmatrix} 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{pmatrix} \begin{pmatrix} \hat{a}_1 \\ \hat{a}_2 \\ \hat{a}_1^\dagger \\ \hat{a}_2^\dagger \\ \end{pmatrix}\end{split}\]
\[\begin{split}CX^\dagger(s) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} CX(s) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ s & 1 & 0 & 0 \\ 0 & 0 & 1 & -s \\ 0 & 0 & 0 & 1 \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]

Decomposition Representation:

\[CX(s) = BS(\frac{\pi}{2} + \theta, 0) \left(S(r, 0) \otimes S(-r, 0)\right) BS(\theta, 0)\]

where \(\sin(2 \theta) = -\frac{1}{\cosh r}, \quad \cos(2 \theta) = -\tanh r, \quad \sinh(r) = -\frac{s}{2}\).

Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix(s: Any) Tensor[source]#

Get the local symplectic matrix acting on annihilation and creation operators.

get_matrix_state(s: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

get_transform_xp(s: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) Tensor[source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local symplectic matrix acting on annihilation and creation operators.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class ControlledZ(inputs: Any = None, nmode: int = 2, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: DoubleGate

Controlled-Z gate.

Operator Representation:

\[CZ(s) = e^{-i \frac{s}{\hbar} \hat{x}_1 \hat{x}_2}\]

Symplectic Transformation:

\[\begin{split}CZ^\dagger(s) \begin{pmatrix} \hat{a}_1 \\ \hat{a}_2 \\ \hat{a}_1^\dagger \\ \hat{a}_2^\dagger \\ \end{pmatrix} CZ(s) = \begin{pmatrix} 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{pmatrix} \begin{pmatrix} \hat{a}_1 \\ \hat{a}_2 \\ \hat{a}_1^\dagger \\ \hat{a}_2^\dagger \\ \end{pmatrix}\end{split}\]
\[\begin{split}CZ^\dagger(s) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} CZ(s) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & s & 1 & 0 \\ s & 0 & 0 & 1 \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]

Decomposition Representation:

\[CZ(s) = PS_2(\pi/2) CX(s) PS_2^\dagger(\pi/2)\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix(s: Any) Tensor[source]#

Get the local symplectic matrix acting on annihilation and creation operators.

get_matrix_state(s: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

get_transform_xp(s: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) Tensor[source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local symplectic matrix acting on annihilation and creation operators.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class CrossKerr(inputs: Any = None, nmode: int = 2, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: DoubleGate

Cross-Kerr gate.

Operator Representation:

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

Operator Transformation:

\[\begin{split}CK^\dagger(\kappa) \hat{a}_1 CK(\kappa) &= e^{i \kappa \hat{n}_2} \hat{a}_1 = \hat{a}_1 e^{i \kappa \hat{n}_2}, \\ CK^\dagger(\kappa) \hat{a}_2 CK(\kappa) &= e^{i \kappa \hat{n}_1} \hat{a}_2 = \hat{a}_2 e^{i \kappa \hat{n}_1}, \\ CK^\dagger(\kappa) \hat{a}_1^\dagger CK(\kappa) &= e^{-i \kappa \hat{n}_2} \hat{a}_1^\dagger = \hat{a}_1^\dagger e^{-i \kappa \hat{n}_2}, \\ CK^\dagger(\kappa) \hat{a}_2^\dagger CK(\kappa) &= e^{-i \kappa \hat{n}_1} \hat{a}_2^\dagger = \hat{a}_2^\dagger e^{-i \kappa \hat{n}_1}.\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix_state(kappa: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) Tensor[source]#

Convert inputs to torch.Tensor.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

class CubicPhase(inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: SingleGate

Cubic phase gate.

Operator Representation:

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

Operator Transformation:

\[CP^\dagger(\gamma) \hat{a} CP(\gamma) = \hat{a} + i\frac{\gamma(\hat{a} + \hat{a}^\dagger)^2}{2\sqrt{2/\hbar}}\]
\[\begin{split}CP^\dagger(\gamma) \hat{x} CP(\gamma) &= \hat{x}, \\ CP^\dagger(\gamma) \hat{p} CP(\gamma) &= \hat{p} + \gamma\hat{x}^2.\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix_state(gamma: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) Tensor[source]#

Convert inputs to torch.Tensor.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

class DelayBS(inputs: Any = None, ntau: int = 1, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, loop_gates: list | None = None, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: Delay

Delay loop with BeamSplitterTheta and PhaseShift.

Parameters:
  • inputs (Any) – The parameters of the gate. Default: None

  • ntau (int) – The number of modes in the delay loop. Default: 1

  • nmode (int) – The number of spatial modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • loop_gates (list | None) – The list of gates added to the delay loop. Default: None

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
property phi#
property theta#
class DelayMZI(inputs: Any = None, ntau: int = 1, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, loop_gates: list | None = None, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: Delay

Delay loop with MZI.

Parameters:
  • inputs (Any) – The parameters of the gate. Default: None

  • ntau (int) – The number of modes in the delay loop. Default: 1

  • nmode (int) – The number of spatial modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • loop_gates (list | None) – The list of gates added to the delay loop. Default: None

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
property phi#
property theta#
class Displacement(inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: SingleGate

Displacement gate.

Symplectic Transformation:

\[\begin{split}D^\dagger(r, \theta) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} D(r, \theta) = \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} + \frac{\sqrt{\hbar}}{\kappa} \begin{pmatrix} r\cos\theta \\ r\sin\theta \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameters of the gate (\(r\) and \(\theta\)). Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix(r: Any, theta: Any) Tensor[source]#

Get the local symplectic unitary matrix acting on annihilation and creation operators.

get_matrix_state(r: Any, theta: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

See https://arxiv.org/pdf/2004.11002.pdf Eq.(57) and Eq.(58)

get_transform_xp(r: Any, theta: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) tuple[Tensor, Tensor][source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local symplectic unitary matrix acting on annihilation and creation operators.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class DisplacementMomentum(inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: Displacement

Momentum Displacement gate.

Symplectic Transformation:

\[\begin{split}Z^\dagger(p) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} Z(p) = \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} + \begin{pmatrix} 0 \\ p \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

class DisplacementPosition(inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: Displacement

Position Displacement gate.

Symplectic Transformation:

\[\begin{split}X^\dagger(x) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} X(x) = \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} + \begin{pmatrix} x \\ 0 \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

class DoubleGate(name: str | None = None, inputs: Any = None, nmode: int = 2, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: Gate

A base class for two-mode photonic quantum gates.

Parameters:
  • name (str | None) – The name of the gate. Default: None

  • inputs (Any) – The parameters of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

class Kerr(inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: SingleGate

Kerr gate.

Operator Representation:

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

Operator Transformation:

\[\begin{split}K^\dagger(\kappa) \hat{a} K(\kappa) &= e^{i \kappa (2 \hat{a}^\dagger \hat{a} + 1)} \hat{a} = \hat{a} e^{i \kappa (2 \hat{a}^\dagger \hat{a} - 1)}, \\ K^\dagger(\kappa) \hat{a}^\dagger K(\kappa) &= \hat{a}^\dagger e^{-i \kappa (2 \hat{a}^\dagger \hat{a} + 1)} = e^{i \kappa (2 \hat{a}^\dagger \hat{a} + 1)} \hat{a}^\dagger.\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix_state(kappa: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) Tensor[source]#

Convert inputs to torch.Tensor.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

class MZI(inputs: Any = None, nmode: int = 2, wires: list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, phi_first: bool = True, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: BeamSplitter

Mach-Zehnder Interferometer.

Matrix Representation:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{MZI}}(\theta, \phi) = ie^{i\theta/2} \begin{pmatrix} e^{i\phi} \sin\left(\th\right) & \cos\left(\th\right) \\ e^{i\phi} \cos\left(\th\right) & -\sin\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]

or when phi_first is False:

\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_{\text{MZI}}(\theta, \phi) = ie^{i\theta/2} \begin{pmatrix} e^{i\phi} \sin\left(\th\right) & e^{i\phi} \cos\left(\th\right) \\ \cos\left(\th\right) & -\sin\left(\th\right) \\ \end{pmatrix}\end{split}\end{aligned}\end{align} \]

Symplectic Transformation:

\[\begin{split}MZI^\dagger(\theta, \phi) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} MZI(\theta, \phi) = \begin{pmatrix} \mathrm{Re}(U_{\text{MZI}}) & -\mathrm{Im}(U_{\text{MZI}}) \\ \mathrm{Im}(U_{\text{MZI}}) & \mathrm{Re}(U_{\text{MZI}}) \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameters of the gate (\(\theta\) and \(\phi\)). Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • phi_first (bool) – Whether \(\phi\) is the first phase shifter. Default: True

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

get_matrix(theta: Any, phi: Any) Tensor[source]#

Get the local unitary matrix acting on creation operators.

class PhaseShift(inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1, inv_mode: bool = False)[source]#

Bases: SingleGate

Phase Shifter.

Matrix Representation:

\[U_{\text{PS}}(\theta) = e^{i\theta}\]

Symplectic Transformation:

\[\begin{split}PS^\dagger(\theta) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} PS(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \\ \end{pmatrix} \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

  • inv_mode (bool) – Whether the rotation in the phase space is clockwise. Default: False

extra_repr() str[source]#
get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix acting on creation operators.

get_matrix_state(matrix: Tensor) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

get_transform_xp(theta: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) Tensor[source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local unitary matrix acting on creation operators.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class QuadraticPhase(inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: SingleGate

Quadratic phase gate.

Operator Representation:

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

Symplectic Transformation:

\[\begin{split}QP^\dagger(s) \begin{pmatrix} \hat{a} \\ \hat{a}^\dagger \\ \end{pmatrix} QP(s) = \begin{pmatrix} 1 + i \frac{s}{2} & i \frac{s}{2} \\ -i \frac{s}{2} & 1 - i \frac{s}{2} \\ \end{pmatrix} \begin{pmatrix} \hat{a} \\ \hat{a}^\dagger \\ \end{pmatrix}\end{split}\]
\[\begin{split}QP^\dagger(s) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} QP(s) = \begin{pmatrix} 1 & 0 \\ s & 1 \\ \end{pmatrix} \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix}\end{split}\]

Decomposition Representation:

\[QP(s) = PS(\theta) S(r e^{i \phi})\]

where \(\cosh(r) = \sqrt{1 + (\frac{s}{2})^2}, \quad \tan(\theta) = \frac{s}{2}, \quad \phi = -\sign(s)\frac{\pi}{2} - \theta\).

Parameters:
  • inputs (Any) – The parameter of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix(s: Any) Tensor[source]#

Get the local symplectic matrix acting on annihilation and creation operators.

get_matrix_state(s: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

get_transform_xp(s: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) Tensor[source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local symplectic matrix acting on annihilation and creation operators.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class SingleGate(name: str | None = None, inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: Gate

A base class for single-mode photonic quantum gates.

Parameters:
  • name (str | None) – The name of the gate. Default: None

  • inputs (Any) – The parameters of the gate. Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameter is nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

class Squeezing(inputs: Any = None, nmode: int = 1, wires: int | list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: SingleGate

Squeezing gate.

Symplectic Transformation:

\[\begin{split}S^\dagger(r, \theta) \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix} S(r, \theta) = \begin{pmatrix} \cosh r - \sinh r \cos\theta & -\sinh r \sin\theta \\ -\sinh r \sin\theta & \cosh r + \sinh r \cos\theta \\ \end{pmatrix} \begin{pmatrix} \hat{x} \\ \hat{p} \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameters of the gate (\(r\) and \(\theta\)). Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (int | list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix(r: Any, theta: Any) Tensor[source]#

Get the local symplectic matrix acting on annihilation and creation operators.

get_matrix_state(r: Any, theta: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

See https://arxiv.org/pdf/2004.11002.pdf Eq.(51) and Eq.(52)

get_transform_xp(r: Any, theta: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) tuple[Tensor, Tensor][source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local symplectic matrix acting on annihilation and creation operators.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class Squeezing2(inputs: Any = None, nmode: int = 2, wires: list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, requires_grad: bool = False, noise: bool = False, mu: float = 0, sigma: float = 0.1)[source]#

Bases: DoubleGate

Two-mode Squeezing gate.

Symplectic Transformation:

\[\begin{split}S_2^\dagger(r, \theta) \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix} S_2(r, \theta) = \begin{pmatrix} \cosh r & \cos\theta\sinh r & 0 & \sin\theta\sinh r \\ \cos\theta\sinh r & \cosh r & \sin\theta\sinh r & 0 \\ 0 & \sin\theta\sinh r & \cosh r & -\cos\theta\sinh r \\ \sin\theta\sinh r & 0 & -\cos\theta\sinh r & \cosh r \\ \end{pmatrix} \begin{pmatrix} \hat{x}_1 \\ \hat{x}_2 \\ \hat{p}_1 \\ \hat{p}_2 \\ \end{pmatrix}\end{split}\]
Parameters:
  • inputs (Any) – The parameters of the gate (\(r\) and \(\theta\)). Default: None

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 2

  • wires (list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • requires_grad (bool) – Whether the parameters are nn.Parameter or buffer. Default: False (which means buffer)

  • noise (bool) – Whether to introduce Gaussian noise. Default: False

  • mu (float) – The mean of Gaussian noise. Default: 0

  • sigma (float) – The standard deviation of Gaussian noise. Default: 0.1

extra_repr() str[source]#
get_matrix(r: Any, theta: Any) Tensor[source]#

Get the local symplectic matrix acting on annihilation and creation operators.

get_matrix_state(r: Any, theta: Any) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

See https://arxiv.org/pdf/2004.11002.pdf Eq.(64-67)

get_transform_xp(r: Any, theta: Any) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

init_para(inputs: Any = None) None[source]#

Initialize the parameters.

inputs_to_tensor(inputs: Any = None) tuple[Tensor, Tensor][source]#

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local symplectic matrix acting on annihilation and creation operators.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.

class UAnyGate(unitary: Any, nmode: int = 1, wires: list[int] | None = None, minmax: list[int] | None = None, cutoff: int | None = None, den_mat: bool = False, name: str = 'UAnyGate')[source]#

Bases: Gate

Arbitrary unitary gate.

Parameters:
  • unitary (Any) – Any given unitary matrix.

  • nmode (int) – The number of modes that the quantum operation acts on. Default: 1

  • wires (list[int] | None) – The indices of the modes that the quantum operation acts on. Default: None

  • minmax (list[int] | None) – The minimum and maximum indices of the modes that the quantum operation acts on. Only valid when wires is None. Default: None

  • cutoff (int | None) – The Fock space truncation. Default: None

  • den_mat (bool) – Whether to use density matrix representation. Default: False

  • name (str) – The name of the gate. Default: 'UAnyGate'

get_matrix_state(matrix: Tensor) Tensor[source]#

Get the local transformation matrix acting on Fock state tensors.

See https://arxiv.org/pdf/2004.11002.pdf Eq.(71)

get_transform_xp(matrix: Tensor) tuple[Tensor, Tensor][source]#

Get the local affine symplectic transformation acting on quadrature operators in xxpp order.

update_matrix_state() Tensor[source]#

Update the local transformation matrix acting on Fock state tensors.

update_transform_xp() tuple[Tensor, Tensor][source]#

Update the local affine symplectic transformation acting on quadrature operators in xxpp order.