gate#
Quantum gates
Classes
|
A base class for customized gates. |
|
Barrier. |
|
CNOT gate. |
|
Combined single-qubit gate. |
|
A base class for two-qubit controlled gates. |
|
A base class for two-qubit gates. |
|
Fredkin gate. |
|
Hadamard gate. |
|
Hamiltonian gate. |
|
Identity gate. |
|
Imaginary Swap gate. |
|
Latent gate. |
|
Move, a two-qubit operation representing a reset of the second qubit followed by a swap. |
|
A base class for two-qubit gates with parameters. |
|
A base class for single-qubit gates with parameters. |
|
PauliX gate. |
|
PauliY gate. |
|
PauliZ gate. |
|
Phase shift gate. |
|
Matrix J to project the measurement basis. |
|
Reconfigurable Beam Splitter gate. |
|
Reset. |
|
Rx gate, rotation around x-axis. |
|
Rxx gate. |
|
Rxy gate. |
|
Ry gate, rotation around y-axis. |
|
Ryy gate. |
|
Rz gate, rotation around z-axis. |
|
Rzz gate. |
|
S dagger gate. |
|
S gate. |
|
A base class for single-qubit gates. |
|
Swap gate. |
|
T dagger gate. |
|
T gate. |
|
Toffoli gate. |
|
A base class for three-qubit gates. |
|
U3 gate, a generic single-qubit rotation gate with 3 angles. |
|
Arbitrary unitary gate. |
|
Wire Cut. |
- class ArbitraryGate(name: str | None = None, nqubit: int = 1, wires: int | list[int] | None = None, minmax: list[int] | None = None, controls: int | list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
GateA base class for customized gates.
- Parameters:
name (str | None) – The name of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneminmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Only valid when
wiresisNone. Default:Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- inverse() ArbitraryGate[source]#
Get the inversed gate.
- class Barrier(nqubit: int = 1, wires: int | list[int] | None = None, name: str = 'Barrier')[source]#
Bases:
GateBarrier.
- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonename (str) – The name of the gate. Default:
'Barrier'
- class CNOT(nqubit: int = 2, wires: list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
DoubleControlGateCNOT gate.
Matrix Representation:
\[\begin{split}\text{CNOT} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class CombinedSingleGate(gates: list[SingleGate], name: str | None = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGateCombined single-qubit gate.
- Parameters:
gates (list[SingleGate]) – The list of single-qubit gates.
name (str | None) – The name of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- add(gate: SingleGate) None[source]#
Add a single-qubit gate to the list and update the local unitary matrix.
- inverse() CombinedSingleGate[source]#
Get the inversed gate.
- class DoubleControlGate(name: str | None = None, nqubit: int = 2, wires: list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
DoubleGateA base class for two-qubit controlled gates.
- Parameters:
name (str | None) – The name of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class DoubleGate(name: str | None = None, nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
GateA base class for two-qubit gates.
- Parameters:
name (str | None) – The name of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class Fredkin(nqubit: int = 3, wires: list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
TripleGateFredkin gate.
Matrix Representation:
\[\begin{split}\text{Fredkin} = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 3
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class Hadamard(nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGateHadamard gate.
Matrix Representation:
\[\begin{split}H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class HamiltonianGate(hamiltonian: Any, t: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, minmax: list[int] | None = None, controls: int | list[int] | None = None, name: str = 'HamiltonianGate', den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ArbitraryGateHamiltonian gate.
- Parameters:
hamiltonian (Any) – The Hamiltonian. It can be a list, e.g.,
[[0.5, 'x0y1'], [-1, 'z3y1']]for \(0.5 * \sigma^x_0 \otimes \sigma^y_1 - \sigma^y_1 \otimes \sigma^z_3\). It can also be a torch.Tensor whenwiresorminmaxis specified.t (Any) – The evolution time. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Only valid when
hamiltonianis not a list. Default:Noneminmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Only valid when
hamiltonianis not a list andwiresisNone. Default:Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonename (str) – The name of the gate. Default:
'HamiltonianGate'den_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Identity(nqubit: int = 1, wires: int | list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
GateIdentity gate.
Matrix Representation:
\[\begin{split}I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class ImaginarySwap(nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
DoubleGateImaginary Swap gate.
Matrix Representation:
\[\begin{split}\text{iSWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & i & 0 \\ 0 & i & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class LatentGate(inputs: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, minmax: list[int] | None = None, controls: int | list[int] | None = None, name: str = 'LatentGate', den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ArbitraryGateLatent gate.
- Parameters:
inputs (Any) – Any given real matrix.
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneminmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Only valid when
wiresisNone. Default:Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonename (str) – The name of the gate. Default:
'LatentGate'den_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Move(nqubit: int = 2, wires: list[int] | None = None, postselect: int | None = 0, tsr_mode: bool = False)[source]#
Bases:
DoubleGateMove, a two-qubit operation representing a reset of the second qubit followed by a swap.
- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonepostselect (int | None) – The postselected value. Default: 0 (
Nonemeans no postselection, which is not compatible with vmap)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class ParametricDoubleGate(name: str | None = None, inputs: Any = None, nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
DoubleGateA base class for two-qubit gates with parameters.
- Parameters:
name (str | None) – The name of the gate. Default:
Noneinputs (Any) – The parameters of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:False(which meansbuffer)
- inverse() ParametricDoubleGate[source]#
Get the inversed gate.
- class ParametricSingleGate(name: str | None = None, inputs: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
SingleGateA base class for single-qubit gates with parameters.
- Parameters:
name (str | None) – The name of the gate. Default:
Noneinputs (Any) – The parameters of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:False(which meansbuffer)
- inverse() ParametricSingleGate[source]#
Get the inversed gate.
- class PauliX(nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGatePauliX gate.
Matrix Representation:
\[\begin{split}X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class PauliY(nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGatePauliY gate.
Matrix Representation:
\[\begin{split}Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class PauliZ(nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGatePauliZ gate.
Matrix Representation:
\[\begin{split}Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class PhaseShift(inputs: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricSingleGatePhase shift gate.
Matrix Representation:
\[\begin{split}P(\theta) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\theta} \end{pmatrix}\end{split}\]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class ProjectionJ(inputs: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, plane: str = 'xy', controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricSingleGateMatrix J to project the measurement basis.
The matrix \(J(\theta)\) transforms the measurement in the XY, YZ, or ZX plane to Z measurement. The transformation means \(M(\theta)|\psi\rangle = M_z J(\theta)|\psi\rangle\), where \(M_z\) is the Z-basis measurement.
Matrix Representation:
\[\begin{split}J_{\text{XY}}(\theta) = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & e^{-i\theta} \\ 1 & -e^{-i\theta} \end{pmatrix}\end{split}\]\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}J_{\text{YZ}}(\theta) = \frac{1}{\sqrt{2}} \begin{pmatrix} \cos(\th) + \sin(\th) & -i(\cos(\th) - \sin(\th)) \\ \cos(\th) - \sin(\th) & i(\cos(\th) + \sin(\th)) \end{pmatrix}\end{split}\end{aligned}\end{align} \]\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}J_{\text{ZX}}(\theta) = \begin{pmatrix} \cos(\th) & \sin(\th) \\ \sin(\th) & -\cos(\th) \end{pmatrix}\end{split}\end{aligned}\end{align} \]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneplane (str) – The measurement plane (
'xy','yz', or'zx'). Default:'xy'controls (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class ReconfigurableBeamSplitter(inputs: Any = None, nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricDoubleGateReconfigurable Beam Splitter gate.
Matrix Representation:
\[\begin{split}\text{RBS}(\theta) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\left(\theta\right) & \sin\left(\theta\right) & 0 \\ 0 & -\sin\left(\theta\right) & \cos\left(\theta\right) & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Reset(nqubit: int = 1, wires: int | list[int] | None = None, postselect: int | None = 0, tsr_mode: bool = False)[source]#
Bases:
GateReset.
- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonepostselect (int | None) – The postselected value. Default: 0 (
Nonemeans no postselection, which is not compatible with vmap)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class Rx(inputs: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricSingleGateRx gate, rotation around x-axis.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_x(\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} \]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Rxx(inputs: Any = None, nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricDoubleGateRxx gate.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_{xx}(\theta) = \exp\left(-i \th X{\otimes}X\right) = \begin{pmatrix} \cos\left(\th\right) & 0 & 0 & -i\sin\left(\th\right) \\ 0 & \cos\left(\th\right) & -i\sin\left(\th\right) & 0 \\ 0 & -i\sin\left(\th\right) & \cos\left(\th\right) & 0 \\ -i\sin\left(\th\right) & 0 & 0 & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Rxy(inputs: Any = None, nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricDoubleGateRxy gate.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_{xy}(\theta) = \exp\left(-i \th X{\otimes}Y\right) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & \cos\left(\th\right) & -i\sin\left(\th\right) & 0 \\ 0 & -i\sin\left(\th\right) & \cos\left(\th\right) & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\end{aligned}\end{align} \]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Ry(inputs: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricSingleGateRy gate, rotation around y-axis.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_y(\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} \]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Ryy(inputs: Any = None, nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricDoubleGateRyy gate.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_{yy}(\theta) = \exp\left(-i \th Y{\otimes}Y\right) = \begin{pmatrix} \cos\left(\th\right) & 0 & 0 & i\sin\left(\th\right) \\ 0 & \cos\left(\th\right) & -i\sin\left(\th\right) & 0 \\ 0 & -i\sin\left(\th\right) & \cos\left(\th\right) & 0 \\ i\sin\left(\th\right) & 0 & 0 & \cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Rz(inputs: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricSingleGateRz gate, rotation around z-axis.
Matrix Representation:
\[\begin{split}R_z(\theta) = \begin{pmatrix} e^{-i\frac{\theta}{2}} & 0 \\ 0 & e^{i\frac{\theta}{2}} \end{pmatrix}\end{split}\]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class Rzz(inputs: Any = None, nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricDoubleGateRzz gate.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}R_{zz}(\theta) = \exp\left(-i \th Z{\otimes}Z\right) = \begin{pmatrix} e^{-i \th} & 0 & 0 & 0 \\ 0 & e^{i \th} & 0 & 0 \\ 0 & 0 & e^{i \th} & 0 \\ 0 & 0 & 0 & e^{-i \th} \end{pmatrix}\end{split}\end{aligned}\end{align} \]- Parameters:
inputs (Any) – The parameter of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameter is
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class SDaggerGate(nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGateS dagger gate.
Matrix Representation:
\[\begin{split}S^{\dagger} = \begin{pmatrix} 1 & 0 \\ 0 & -i \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class SGate(nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGateS gate.
Matrix Representation:
\[\begin{split}S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- inverse() SDaggerGate[source]#
Get the inversed gate.
- class SingleGate(name: str | None = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
GateA base class for single-qubit gates.
- Parameters:
name (str | None) – The name of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- op_dist_state(x: DistributedQubitState) DistributedQubitState[source]#
Perform a forward pass of a gate for a distributed state vector.
- class Swap(nqubit: int = 2, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
DoubleGateSwap gate.
Matrix Representation:
\[\begin{split}\text{SWAP} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 2
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- op_dist_state(x: DistributedQubitState) DistributedQubitState[source]#
Perform a forward pass of a gate for a distributed state vector.
- class TDaggerGate(nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGateT dagger gate.
Matrix Representation:
\[\begin{split}T^{\dagger} = \begin{pmatrix} 1 & 0 \\ 0 & e^{-i\pi/4} \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class TGate(nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
SingleGateT gate.
Matrix Representation:
\[\begin{split}T = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- inverse() TDaggerGate[source]#
Get the inversed gate.
- class Toffoli(nqubit: int = 3, wires: list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
TripleGateToffoli gate.
Matrix Representation:
\[\begin{split}\text{Toffoli} = \begin{pmatrix} 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \end{pmatrix}\end{split}\]- Parameters:
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 3
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class TripleGate(name: str | None = None, nqubit: int = 3, wires: list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
GateA base class for three-qubit gates.
- Parameters:
name (str | None) – The name of the gate. Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 3
wires (list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False
- class U3Gate(inputs: Any = None, nqubit: int = 1, wires: int | list[int] | None = None, controls: int | list[int] | None = None, condition: bool = False, den_mat: bool = False, tsr_mode: bool = False, requires_grad: bool = False)[source]#
Bases:
ParametricSingleGateU3 gate, a generic single-qubit rotation gate with 3 angles.
Matrix Representation:
\[ \begin{align}\begin{aligned}\newcommand{\th}{\frac{\theta}{2}}\\\begin{split}U_3(\theta, \phi, \lambda) = \begin{pmatrix} \cos\left(\th\right) & -e^{i\lambda}\sin\left(\th\right) \\ e^{i\phi}\sin\left(\th\right) & e^{i(\phi+\lambda)}\cos\left(\th\right) \end{pmatrix}\end{split}\end{aligned}\end{align} \]- Parameters:
inputs (Any) – The parameters of the gate (\(\theta\), \(\phi\) and \(\lambda\)). Default:
Nonenqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonecondition (bool) – Whether to use
controlsas conditional measurement. Default:Falseden_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
Falserequires_grad (bool) – Whether the parameters are
nn.Parameterorbuffer. Default:False(which meansbuffer)
- class UAnyGate(unitary: Any, nqubit: int = 1, wires: int | list[int] | None = None, minmax: list[int] | None = None, controls: int | list[int] | None = None, name: str = 'UAnyGate', den_mat: bool = False, tsr_mode: bool = False)[source]#
Bases:
ArbitraryGateArbitrary unitary gate.
- Parameters:
unitary (Any) – Any given unitary matrix.
nqubit (int) – The number of qubits that the quantum operation acts on. Default: 1
wires (int | list[int] | None) – The indices of the qubits that the quantum operation acts on. Default:
Noneminmax (list[int] | None) – The minimum and maximum indices of the qubits that the quantum operation acts on. Only valid when
wiresisNone. Default:Nonecontrols (int | list[int] | None) – The indices of the control qubits. Default:
Nonename (str) – The name of the gate. Default:
'UAnyGate'den_mat (bool) – Whether the quantum operation acts on density matrices or state vectors. Default:
False(which means state vectors)tsr_mode (bool) – Whether the quantum operation is in tensor mode, which means the input and output are represented by a tensor of shape \((\text{batch}, 2, ..., 2)\). Default:
False