gate

Contents

gate#

Quantum gates

Classes

ArbitraryGate([name, nqubit, wires, minmax, ...])

A base class for customized gates.

Barrier([nqubit, wires, name])

Barrier.

CNOT([nqubit, wires, den_mat, tsr_mode])

CNOT gate.

CombinedSingleGate(gates[, name, nqubit, ...])

Combined single-qubit gate.

DoubleControlGate([name, nqubit, wires, ...])

A base class for two-qubit controlled gates.

DoubleGate([name, nqubit, wires, controls, ...])

A base class for two-qubit gates.

Fredkin([nqubit, wires, den_mat, tsr_mode])

Fredkin gate.

Hadamard([nqubit, wires, controls, ...])

Hadamard gate.

HamiltonianGate(hamiltonian[, t, nqubit, ...])

Hamiltonian gate.

Identity([nqubit, wires, den_mat, tsr_mode])

Identity gate.

ImaginarySwap([nqubit, wires, controls, ...])

Imaginary Swap gate.

LatentGate([inputs, nqubit, wires, minmax, ...])

Latent gate.

Move([nqubit, wires, postselect, tsr_mode])

Move, a two-qubit operation representing a reset of the second qubit followed by a swap.

ParametricDoubleGate([name, inputs, nqubit, ...])

A base class for two-qubit gates with parameters.

ParametricSingleGate([name, inputs, nqubit, ...])

A base class for single-qubit gates with parameters.

PauliX([nqubit, wires, controls, condition, ...])

PauliX gate.

PauliY([nqubit, wires, controls, condition, ...])

PauliY gate.

PauliZ([nqubit, wires, controls, condition, ...])

PauliZ gate.

PhaseShift([inputs, nqubit, wires, ...])

Phase shift gate.

ProjectionJ([inputs, nqubit, wires, plane, ...])

Matrix J to project the measurement basis.

ReconfigurableBeamSplitter([inputs, nqubit, ...])

Reconfigurable Beam Splitter gate.

Reset([nqubit, wires, postselect, tsr_mode])

Reset.

Rx([inputs, nqubit, wires, controls, ...])

Rx gate, rotation around x-axis.

Rxx([inputs, nqubit, wires, controls, ...])

Rxx gate.

Rxy([inputs, nqubit, wires, controls, ...])

Rxy gate.

Ry([inputs, nqubit, wires, controls, ...])

Ry gate, rotation around y-axis.

Ryy([inputs, nqubit, wires, controls, ...])

Ryy gate.

Rz([inputs, nqubit, wires, controls, ...])

Rz gate, rotation around z-axis.

Rzz([inputs, nqubit, wires, controls, ...])

Rzz gate.

SDaggerGate([nqubit, wires, controls, ...])

S dagger gate.

SGate([nqubit, wires, controls, condition, ...])

S gate.

SingleGate([name, nqubit, wires, controls, ...])

A base class for single-qubit gates.

Swap([nqubit, wires, controls, condition, ...])

Swap gate.

TDaggerGate([nqubit, wires, controls, ...])

T dagger gate.

TGate([nqubit, wires, controls, condition, ...])

T gate.

Toffoli([nqubit, wires, den_mat, tsr_mode])

Toffoli gate.

TripleGate([name, nqubit, wires, controls, ...])

A base class for three-qubit gates.

U3Gate([inputs, nqubit, wires, controls, ...])

U3 gate, a generic single-qubit rotation gate with 3 angles.

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

Arbitrary unitary gate.

WireCut([nqubit, wires])

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: Gate

A base class for customized gates.

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

  • 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: None

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

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • 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

get_unitary() Tensor[source]#

Get the global unitary matrix.

inverse() ArbitraryGate[source]#

Get the inversed gate.

class Barrier(nqubit: int = 1, wires: int | list[int] | None = None, name: str = 'Barrier')[source]#

Bases: Gate

Barrier.

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: None

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

forward(x: Any) Any[source]#

Perform a forward pass.

pattern(nodes: list[int], ancilla: list[int]) Sequential[source]#

Get the MBQC pattern.

class CNOT(nqubit: int = 2, wires: list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#

Bases: DoubleControlGate

CNOT 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: None

  • 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

pattern(nodes: list[int], ancilla: list[int]) Sequential[source]#

Get the MBQC pattern.

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: SingleGate

Combined single-qubit gate.

Parameters:
  • gates (list[SingleGate]) – The list of single-qubit gates.

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

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

add(gate: SingleGate) None[source]#

Add a single-qubit gate to the list and update the local unitary matrix.

get_derivative(inputs: Any) Tensor[source]#

Get the derivatives of the local unitary matrix.

get_matrix() Tensor[source]#

Get the local unitary matrix.

inverse() CombinedSingleGate[source]#

Get the inversed gate.

update_matrix() Tensor[source]#

Update the local unitary matrix.

update_npara() None[source]#

Update the number of parameters.

class DoubleControlGate(name: str | None = None, nqubit: int = 2, wires: list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#

Bases: DoubleGate

A base class for two-qubit controlled gates.

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

  • 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: None

  • 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

get_unitary() Tensor[source]#

Get the global unitary matrix.

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: Gate

A base class for two-qubit gates.

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

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

get_unitary() Tensor[source]#

Get the global unitary matrix.

class Fredkin(nqubit: int = 3, wires: list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#

Bases: TripleGate

Fredkin 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: None

  • 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

get_unitary() Tensor[source]#

Get the global unitary matrix.

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: SingleGate

Hadamard 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

pattern(nodes: int | list[int], ancilla: int | list[int]) Sequential[source]#

Get the MBQC pattern.

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: ArbitraryGate

Hamiltonian 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 when wires or minmax is specified.

  • t (Any) – The evolution time. Default: None

  • 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. Only valid when hamiltonian is not a list. Default: None

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

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • name (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: False

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

get_derivative(t: Any) Tensor[source]#

Get the derivative of the local unitary matrix.

get_matrix(hamiltonian: Any, t: Any) Tensor[source]#

Get the local unitary matrix.

get_minmax(hamiltonian: list) list[int][source]#

Get minmax according to the Hamiltonian.

init_para(inputs: list | None = None) None[source]#

Initialize the parameters.

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

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local unitary matrix.

class Identity(nqubit: int = 1, wires: int | list[int] | None = None, den_mat: bool = False, tsr_mode: bool = False)[source]#

Bases: Gate

Identity 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: None

  • 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

forward(x: Any) Any[source]#

Perform a forward pass.

get_unitary() Tensor[source]#

Get the global unitary matrix.

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: DoubleGate

Imaginary 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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: ArbitraryGate

Latent 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: None

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

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • name (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: False

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

get_derivative(latent: Any) Tensor[source]#

Get the derivatives of the local unitary matrix.

get_matrix(inputs: Any) Tensor[source]#

Get the local unitary matrix.

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.

class Move(nqubit: int = 2, wires: list[int] | None = None, postselect: int | None = 0, tsr_mode: bool = False)[source]#

Bases: DoubleGate

Move, 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: None

  • postselect (int | None) – The postselected value. Default: 0 (None means 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

forward(x: Tensor) Tensor[source]#

Perform a forward pass.

qpd(label: int | None = None) MoveQPD[source]#

Get the quasiprobability-decomposition representation.

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: DoubleGate

A base class for two-qubit gates with parameters.

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

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

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

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

Get the derivative of the local unitary matrix.

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

Initialize the parameters.

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

Convert inputs to torch.Tensor.

inverse() ParametricDoubleGate[source]#

Get the inversed gate.

update_matrix() Tensor[source]#

Update the local unitary matrix.

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: SingleGate

A base class for single-qubit gates with parameters.

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

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

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

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

Get the derivative of the local unitary matrix.

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

Initialize the parameters.

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

Convert inputs to torch.Tensor.

inverse() ParametricSingleGate[source]#

Get the inversed gate.

update_matrix() Tensor[source]#

Update the local unitary matrix.

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: SingleGate

PauliX 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

pattern(nodes: int | list[int], ancilla: list[int]) Sequential[source]#

Get the MBQC pattern.

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: SingleGate

PauliY 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

pattern(nodes: int | list[int], ancilla: list[int]) Sequential[source]#

Get the MBQC pattern.

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: SingleGate

PauliZ 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

pattern(nodes: int | list[int], ancilla: list[int]) Sequential[source]#

Get the MBQC pattern.

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: ParametricSingleGate

Phase 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

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

Convert inputs to torch.Tensor.

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: ParametricSingleGate

Matrix 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: None

  • 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: None

  • plane (str) – The measurement plane ('xy', 'yz', or 'zx'). Default: 'xy'

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

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

Get the local unitary matrix.

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: ParametricDoubleGate

Reconfigurable 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

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

Convert inputs to torch.Tensor.

class Reset(nqubit: int = 1, wires: int | list[int] | None = None, postselect: int | None = 0, tsr_mode: bool = False)[source]#

Bases: Gate

Reset.

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: None

  • postselect (int | None) – The postselected value. Default: 0 (None means 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

op_state(x: Tensor) Tensor[source]#

Perform a forward pass for state vectors.

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: ParametricSingleGate

Rx 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

pattern(nodes: int | list[int], ancilla: list[int], angle: Any, requires_grad: bool = False) Sequential[source]#

Get the MBQC pattern.

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: ParametricDoubleGate

Rxx 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

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: ParametricDoubleGate

Rxy 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

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: ParametricSingleGate

Ry 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

pattern(nodes: int | list[int], ancilla: list[int], angle: Any, requires_grad: bool = False) Sequential[source]#

Get the MBQC pattern.

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: ParametricDoubleGate

Ryy 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

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: ParametricSingleGate

Rz 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

pattern(nodes: int | list[int], ancilla: list[int], angle: Any, requires_grad: bool = False) Sequential[source]#

Get the MBQC pattern.

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: ParametricDoubleGate

Rzz 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

get_matrix(theta: Any) Tensor[source]#

Get the local unitary matrix.

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: SingleGate

S 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

inverse() SGate[source]#

Get the inversed gate.

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: SingleGate

S 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

inverse() SDaggerGate[source]#

Get the inversed gate.

pattern(nodes: int | list[int], ancilla: list[int]) Sequential[source]#

Get the MBQC pattern.

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: Gate

A base class for single-qubit gates.

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

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

get_unitary() Tensor[source]#

Get the global unitary matrix.

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: DoubleGate

Swap 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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: SingleGate

T 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

inverse() TGate[source]#

Get the inversed gate.

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: SingleGate

T 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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: TripleGate

Toffoli 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: None

  • 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

get_unitary() Tensor[source]#

Get the global unitary matrix.

pattern(nodes: list[int], ancilla: list[int]) Sequential[source]#

Get the MBQC pattern.

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: Gate

A base class for three-qubit gates.

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

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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: ParametricSingleGate

U3 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: None

  • 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: None

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • condition (bool) – Whether to use controls as conditional measurement. Default: False

  • 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

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

extra_repr() str[source]#
get_derivative(inputs: Any) Tensor[source]#

Get the derivatives of the local unitary matrix.

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

Get the local unitary matrix.

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

Initialize the parameters.

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

Convert inputs to torch.Tensor.

update_matrix() Tensor[source]#

Update the local unitary matrix.

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: ArbitraryGate

Arbitrary 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: None

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

  • controls (int | list[int] | None) – The indices of the control qubits. Default: None

  • name (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

update_matrix() Tensor[source]#

Update the local unitary matrix.

class WireCut(nqubit: int = 1, wires: int | list[int] = 0)[source]#

Bases: Barrier

Wire Cut.

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

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