graphix.instruction module

Instruction classes.

repr_angle(angle: Expression | float) → str[source]

Return the representation string of an angle in radians.

This is used for pretty-printing instructions with angle parameters. Delegates to pretty_print.angle_to_str().

class InstructionKind(*values)[source]

Bases: Enum

Tag for instruction kind.

CCX = 1
RZZ = 2
CNOT = 3
SWAP = 4
CZ = 5
H = 6
S = 7
X = 8
Y = 9
Z = 10
J = 11
I = 12
M = 13
RX = 14
RY = 15
RZ = 16
SDG = 17
T = 18
TDG = 19
SX = 20
SXDG = 21
CY = 22
P = 23
U = 24
CJ = 25
CP = 26
CRX = 27
CRY = 28
CRZ = 29
CU = 30
CSWAP = 31
GPHASE = 32
class InstructionVisitor[source]

Bases: object

Visitor for instruction.

This base class can be subclassed to rewrite instructions by overriding some of the following functions:

  • visit_qubit: rewrite qubit indices.

  • visit_angle: rewrite angles.

  • visit_axis: rewrite axes.

visit_qubit(qubit: int) → int[source]

Rewrite a qubit index.

visit_angle(angle: Expression | float) → Expression | float[source]

Rewrite an angle.

visit_axis(axis: Axis) → Axis[source]

Rewrite an axis.

class BaseInstruction[source]

Bases: ABC, DataclassReprMixin

Base class for circuit instructions.

abstractmethod visit(visitor: InstructionVisitor, *, copy: bool = False) → Self[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

class CCX(target: int, controls: tuple[int, int])[source]

Bases: _KindChecker, BaseInstruction

Toffoli circuit instruction.

The CCX gate applies the matrix

\[\begin{split}\left[\begin{matrix} 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{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order controls[0], controls[1], target.

controls

Index of the control qubits.

Type:

tuple[int, int]

target

Index of the target qubit.

Type:

int

target: int
controls: tuple[int, int]
kind: ClassVar[Literal[InstructionKind.CCX]] = 1
visit(visitor: InstructionVisitor, *, copy: bool = False) → CCX[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(target: int, controls: tuple[int, int]) → None
class RZZ(target: int, control: int, angle: Expression | float)[source]

Bases: _KindChecker, BaseInstruction

RZZ circuit instruction.

The \(\mathrm{RZZ}(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \mathrm e^{-\mathrm i \frac \theta 2} & 0 & 0 & 0\\ 0 & \mathrm e^{\mathrm i \frac \theta 2} & 0 & 0\\ 0 & 0 & \mathrm e^{\mathrm i \frac \theta 2} & 0\\ 0 & 0 & 0 & \mathrm e^{-\mathrm i \frac \theta 2} \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

We have \(\mathrm{RZZ}(\theta) = \mathrm{CNOT} (I \otimes \mathrm{RZ}(\theta)) \mathrm{CNOT}\).

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

target: int
control: int
angle: Expression | float
kind: ClassVar[Literal[InstructionKind.RZZ]] = 2
visit(visitor: InstructionVisitor, *, copy: bool = False) → RZZ[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(target: int, control: int, angle: Expression | float) → None
class ControlledSingleTargetInstruction(target: int, control: int)[source]

Bases: BaseInstruction

Base class for controlled single-target circuit instructions.

target: int
control: int
visit(visitor: InstructionVisitor, *, copy: bool = False) → Self[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(target: int, control: int) → None
class CY(target: int, control: int)[source]

Bases: _KindChecker, ControlledSingleTargetInstruction

CY circuit instruction.

The CY gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & -\mathrm i\\ 0 & 0 & \mathrm i & 0 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

kind: ClassVar[Literal[InstructionKind.CY]] = 22
__init__(target: int, control: int) → None
class CNOT(target: int, control: int)[source]

Bases: _KindChecker, ControlledSingleTargetInstruction

CNOT circuit instruction.

The CNOT gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

kind: ClassVar[Literal[InstructionKind.CNOT]] = 3
__init__(target: int, control: int) → None
class CZ(targets: tuple[int, int])[source]

Bases: _KindChecker, BaseInstruction

CZ circuit instruction.

The CZ gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & -1 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order targets[0], targets[1].

targets

Index of the target qubits.

Type:

tuple[int, int]

targets: tuple[int, int]
kind: ClassVar[Literal[InstructionKind.CZ]] = 5
visit(visitor: InstructionVisitor, *, copy: bool = False) → CZ[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(targets: tuple[int, int]) → None
class SWAP(targets: tuple[int, int])[source]

Bases: _KindChecker, BaseInstruction

SWAP circuit instruction.

The SWAP gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order targets[0], targets[1].

targets

Index of the target qubits.

Type:

tuple[int, int]

targets: tuple[int, int]
kind: ClassVar[Literal[InstructionKind.SWAP]] = 4
visit(visitor: InstructionVisitor, *, copy: bool = False) → SWAP[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(targets: tuple[int, int]) → None
class CSWAP(control: int, targets: tuple[int, int])[source]

Bases: _KindChecker, BaseInstruction

CSWAP circuit instruction.

The CSWAP gate applies the matrix

\[\begin{split}\left[\begin{matrix} 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{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, targets[0], targets[1].

control

Index of the control qubit.

Type:

int

targets

Indices of the two target qubits.

Type:

tuple[int, int]

control: int
targets: tuple[int, int]
kind: ClassVar[Literal[InstructionKind.CSWAP]] = 31
visit(visitor: InstructionVisitor, *, copy: bool = False) → CSWAP[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(control: int, targets: tuple[int, int]) → None
class SingleTargetInstruction(target: int)[source]

Bases: BaseInstruction

Base class for single-target circuit instructions.

target: int
visit(visitor: InstructionVisitor, *, copy: bool = False) → Self[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(target: int) → None
class H(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

H circuit instruction.

The Hadamard gate applies the matrix \(\frac 1 {\sqrt 2}\left[\begin{matrix}1 & 1\\1 & -1\end{matrix}\right]\).

kind: ClassVar[Literal[InstructionKind.H]] = 6
__init__(target: int) → None
class S(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

S circuit instruction.

The S gate applies the matrix \(\left[\begin{matrix}1 & 0\\0 & \mathrm i\end{matrix}\right]\).

kind: ClassVar[Literal[InstructionKind.S]] = 7
__init__(target: int) → None
class SDG(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

SDG circuit instruction.

The \(S^\dagger\) gate applies the matrix \(\left[\begin{matrix}1 & 0\\0 & - \mathrm i\end{matrix}\right]\).

We have \(S^\dagger = \mathrm e^{\mathrm i \frac \pi 4} R_Z(-\frac \pi 2)\).

kind: ClassVar[Literal[InstructionKind.SDG]] = 17
__init__(target: int) → None
class T(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

T circuit instruction.

The \(T\) gate applies the matrix \(\left[\begin{matrix}1 & 0\\0 & \mathrm e^{\mathrm i \frac \pi 4}\end{matrix}\right]\).

We have \(T = \mathrm e^{\mathrm i \frac \pi 8} R_Z(\frac \pi 4)\).

kind: ClassVar[Literal[InstructionKind.T]] = 18
__init__(target: int) → None
class TDG(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

TDG circuit instruction.

The \(T^\dagger\) gate applies the matrix \(\left[\begin{matrix}1 & 0\\0 & \mathrm e^{- \mathrm i \frac \pi 4}\end{matrix}\right]\).

We have \(T^\dagger = \mathrm e^{\mathrm i \frac \pi 8} R_Z(- \frac \pi 4)\).

kind: ClassVar[Literal[InstructionKind.TDG]] = 19
__init__(target: int) → None
class SX(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

SX circuit instruction.

The \(SX\) (\(\sqrt X\)) gate applies the matrix \(\frac 1 2 \left[\begin{matrix}1 + \mathrm i & 1 - \mathrm i\\1 - \mathrm i & 1 + \mathrm i\end{matrix}\right]\).

We have \(SX = \mathrm e^{\mathrm i \frac \pi 4} R_X(\frac \pi 2)\).

kind: ClassVar[Literal[InstructionKind.SX]] = 20
__init__(target: int) → None
class SXDG(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

SXDG circuit instruction.

The \(SX^\dagger\) (\({\sqrt X}^\dagger\)) gate applies the matrix \(\frac 1 2 \left[\begin{matrix}1 - \mathrm i & 1 + \mathrm i\\1 + \mathrm i & 1 - \mathrm i\end{matrix}\right]\).

We have \(SX^\dagger = \mathrm e^{\mathrm i \frac \pi 4} R_X(-\frac \pi 2)\).

kind: ClassVar[Literal[InstructionKind.SXDG]] = 21
__init__(target: int) → None
class X(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

X circuit instruction.

The X gate applies the matrix \(\left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right]\).

kind: ClassVar[Literal[InstructionKind.X]] = 8
__init__(target: int) → None
class Y(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

Y circuit instruction.

The Y gate applies the matrix \(\left[\begin{matrix}0 & -\mathrm i\\\mathrm i & 0\end{matrix}\right]\).

kind: ClassVar[Literal[InstructionKind.Y]] = 9
__init__(target: int) → None
class Z(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

Z circuit instruction.

The Z gate applies the matrix \(\left[\begin{matrix}1 & 0\\\mathrm 0 & -1\end{matrix}\right]\).

kind: ClassVar[Literal[InstructionKind.Z]] = 10
__init__(target: int) → None
class I(target: int)[source]

Bases: _KindChecker, SingleTargetInstruction

I circuit instruction.

The identity gate applies the matrix \(\left[\begin{matrix}1 & 0\\\mathrm 0 & 1\end{matrix}\right]\).

kind: ClassVar[Literal[InstructionKind.I]] = 12
__init__(target: int) → None
class M(target: int, axis: Axis)[source]

Bases: _KindChecker, BaseInstruction

M circuit instruction.

target: int
axis: Axis
kind: ClassVar[Literal[InstructionKind.M]] = 13
visit(visitor: InstructionVisitor, *, copy: bool = False) → M[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(target: int, axis: Axis) → None
class RotationInstruction(target: int, angle: Expression | float)[source]

Bases: BaseInstruction

Base class for rotation instructions.

target: int
angle: Expression | float
visit(visitor: InstructionVisitor, *, copy: bool = False) → Self[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(target: int, angle: Expression | float) → None
class P(target: int, angle: Expression | float)[source]

Bases: _KindChecker, RotationInstruction

P rotation circuit instruction.

The \(P(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0\\ 0 & \mathrm e^{\mathrm i \theta} \end{matrix}\right]\end{split}\]

We have \(P(\theta) = \mathrm e^{\theta/2} R_Z(\theta)\).

kind: ClassVar[Literal[InstructionKind.P]] = 23
__init__(target: int, angle: Expression | float) → None
class RX(target: int, angle: Expression | float)[source]

Bases: _KindChecker, RotationInstruction

X rotation circuit instruction.

The \(RX(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \cos \frac \theta 2 & -\mathrm i \sin \frac \theta 2\\ -\mathrm i \sin \frac \theta 2 & \cos \frac \theta 2 \end{matrix}\right]\end{split}\]
kind: ClassVar[Literal[InstructionKind.RX]] = 14
__init__(target: int, angle: Expression | float) → None
class RY(target: int, angle: Expression | float)[source]

Bases: _KindChecker, RotationInstruction

Y rotation circuit instruction.

The \(RY(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \cos \frac \theta 2 & - \sin \frac \theta 2\\ \sin \frac \theta 2 & \cos \frac \theta 2 \end{matrix}\right]\end{split}\]
kind: ClassVar[Literal[InstructionKind.RY]] = 15
__init__(target: int, angle: Expression | float) → None
class RZ(target: int, angle: Expression | float)[source]

Bases: _KindChecker, RotationInstruction

Z rotation circuit instruction.

The \(RZ(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \mathrm e^{-\mathrm i \frac \theta 2} & 0\\ 0 & \mathrm e^{\mathrm i \frac \theta 2} \end{matrix}\right]\end{split}\]
kind: ClassVar[Literal[InstructionKind.RZ]] = 16
__init__(target: int, angle: Expression | float) → None
class J(target: int, angle: Expression | float)[source]

Bases: _KindChecker, RotationInstruction

J circuit instruction.

The \(J(\theta)\) gate applies the matrix

\[\begin{split}\frac 1 {\sqrt 2} \left[\begin{matrix} 1 & \mathrm e^{\mathrm i \theta}\\ 1 & - \mathrm e^{\mathrm i \theta} \end{matrix}\right]\end{split}\]

We have \(J(\theta) = \mathrm e^{\mathrm i \theta/2} H \mathrm{RZ}(\theta)\).

kind: ClassVar[Literal[InstructionKind.J]] = 11
__init__(target: int, angle: Expression | float) → None
class U(target: int, theta: Expression | float, phi: Expression | float, lambda_: Expression | float)[source]

Bases: _KindChecker, BaseInstruction

U circuit instruction.

The \(U(\theta, \phi, \lambda)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \cos \frac \theta 2 & - \mathrm e^{\mathrm i\lambda} \sin \frac \theta 2 \\ \mathrm e^{\mathrm i \phi} \sin \frac \theta 2 & \mathrm e^{\mathrm i (\phi + \lambda)} \cos \frac \theta 2 \end{matrix}\right]\end{split}\]

It can be decomposed as

\[U(\theta, \phi, \lambda) = \mathrm e^{\mathrm i\frac{\phi + \lambda}{2}} R_Z(\phi) R_Y(\theta) R_Z(\lambda) = \mathrm e^{\mathrm i\frac{\theta}{2}} H J\left(\phi + \frac{\pi}{2}\right) J(\theta) J\left(\lambda - \frac{\pi}{2}\right)\]
target: int
theta: Expression | float
phi: Expression | float
lambda_: Expression | float
kind: ClassVar[Literal[InstructionKind.U]] = 24
visit(visitor: InstructionVisitor, *, copy: bool = False) → Self[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(target: int, theta: Expression | float, phi: Expression | float, lambda_: Expression | float) → None
class CU(control: int, target: int, theta: Expression | float, phi: Expression | float, lambda_: Expression | float, gamma: Expression | float)[source]

Bases: _KindChecker, BaseInstruction

Controlled-U circuit instruction.

The \(CU(\theta, \phi, \lambda, \gamma)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \mathrm e^{\mathrm i\gamma} \cos\left(\frac{\theta}{2}\right) & -\mathrm e^{\mathrm i(\gamma + \lambda)} \sin\left(\frac{\theta}{2}\right) \\ 0 & 0 & \mathrm e^{\mathrm i(\gamma + \phi)} \sin\left(\frac{\theta}{2}\right) & \mathrm e^{\mathrm i(\gamma + \phi + \lambda)} \cos\left(\frac{\theta}{2}\right) \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

It can be decomposed as

\[CU(\theta, \phi, \lambda, \gamma) = \left(P\left(\frac{\gamma - \theta} 2\right) \otimes I\right) CJ(0) CJ\left(\phi + \frac \pi 2\right) CJ(\theta) CJ\left(\lambda - \frac \pi 2\right)\]
control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

theta

Rotation angle around the Y axis.

Type:

ParameterizedAngle

phi

Rotation angle around the Z axis after the Y rotation.

Type:

ParameterizedAngle

lambda_

Rotation angle around the Z axis before the Y rotation.

Type:

ParameterizedAngle

gamma

Global phase angle.

Type:

ParameterizedAngle

control: int
target: int
theta: Expression | float
phi: Expression | float
lambda_: Expression | float
gamma: Expression | float
kind: ClassVar[Literal[InstructionKind.CU]] = 30
visit(visitor: InstructionVisitor, *, copy: bool = False) → Self[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(control: int, target: int, theta: Expression | float, phi: Expression | float, lambda_: Expression | float, gamma: Expression | float) → None
class ControlledRotationInstruction(target: int, control: int, angle: Expression | float)[source]

Bases: BaseInstruction

Base class for rotation instructions.

target: int
control: int
angle: Expression | float
visit(visitor: InstructionVisitor, *, copy: bool = False) → Self[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(target: int, control: int, angle: Expression | float) → None
class CP(target: int, control: int, angle: Expression | float)[source]

Bases: _KindChecker, ControlledRotationInstruction

Controlled-P circuit instruction.

The \(CP(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & \mathrm e^{\mathrm i \theta} \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Phase angle.

Type:

ParameterizedAngle

kind: ClassVar[Literal[InstructionKind.CP]] = 26
__init__(target: int, control: int, angle: Expression | float) → None
class CRX(target: int, control: int, angle: Expression | float)[source]

Bases: _KindChecker, ControlledRotationInstruction

Controlled-X rotation circuit instruction.

The \(CRX(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \cos \frac \theta 2 & -\mathrm i \sin \frac \theta 2\\ 0 & 0 & -\mathrm i \sin \frac \theta 2 & \cos \frac \theta 2 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

kind: ClassVar[Literal[InstructionKind.CRX]] = 27
__init__(target: int, control: int, angle: Expression | float) → None
class CRY(target: int, control: int, angle: Expression | float)[source]

Bases: _KindChecker, ControlledRotationInstruction

Controlled-Y rotation circuit instruction.

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \cos \frac \theta 2 & - \sin \frac \theta 2\\ 0 & 0 & \sin \frac \theta 2 & \cos \frac \theta 2 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

kind: ClassVar[Literal[InstructionKind.CRY]] = 28
__init__(target: int, control: int, angle: Expression | float) → None
class CRZ(target: int, control: int, angle: Expression | float)[source]

Bases: _KindChecker, ControlledRotationInstruction

Controlled-Z rotation circuit instruction.

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \mathrm e^{-\mathrm i \frac \theta 2} & 0\\ 0 & 0 & 0 & \mathrm e^{\mathrm i \frac \theta 2} \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

kind: ClassVar[Literal[InstructionKind.CRZ]] = 29
__init__(target: int, control: int, angle: Expression | float) → None
class CJ(target: int, control: int, angle: Expression | float)[source]

Bases: _KindChecker, ControlledRotationInstruction

Controlled-J circuit instruction.

The \(CJ(\alpha)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \frac 1 {\sqrt 2} & \frac 1 {\sqrt 2} \mathrm e^{\mathrm i \alpha}\\ 0 & 0 & \frac 1 {\sqrt 2} & - \frac 1 {\sqrt 2} \mathrm e^{\mathrm i \alpha} \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

Following Lemmas 4.3 and 5.1 of Barenco et al. (1995), we define:

\[\begin{split}\begin{aligned} A &= R_Y\left(\frac \pi 4\right),\\ B &= R_Y\left(- \frac \pi 4\right) R_Z(- \delta),\\ C &= R_Z(\delta),\\ \delta &= \frac {\alpha + \pi} 2 \end{aligned}\end{split}\]

These operators satisfy \(ABC = I\) and \(AXBXC = \mathrm e^{-\mathrm i \delta} J(\alpha)\).

Consequently, \(CJ(\alpha)\) can be decomposed as:

\[CJ(\alpha) = (P(\delta) \otimes I) \, (I \otimes A) \, CX \, (I \otimes B) \, CX \, (I \otimes C)\]
control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

References

Barenco, A., Bennett, C. H., Cleve, R., DiVincenzo, D. P., Margolus, N., Shor, P., Sleator, T., Smolin, J. A., & Weinfurter, H. (1995). Elementary gates for quantum computation. Physical Review A, 52(5), 3457-3467. https://doi.org/10.1103/physreva.52.3457

kind: ClassVar[Literal[InstructionKind.CJ]] = 25
__init__(target: int, control: int, angle: Expression | float) → None
class GPHASE(angle: Expression | float)[source]

Bases: _KindChecker, BaseInstruction

GPHASE circuit instruction.

angle

Phase angle.

Type:

ParameterizedAngle

angle: Expression | float
kind: ClassVar[Literal[InstructionKind.GPHASE]] = 32
visit(visitor: InstructionVisitor, *, copy: bool = False) → GPHASE[source]

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

__init__(angle: Expression | float) → None
class Instruction[source]

Bases: object

Grouping of all instructions for namespace exposure.

Notes

This class is not meant to be instantiated, but rather serves as a namespace for all instructions except RZZ. The type alias for “any command” is InstructionKind.

class I(target: int)

Bases: _KindChecker, SingleTargetInstruction

I circuit instruction.

The identity gate applies the matrix \(\left[\begin{matrix}1 & 0\\\mathrm 0 & 1\end{matrix}\right]\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.I]] = 12
class X(target: int)

Bases: _KindChecker, SingleTargetInstruction

X circuit instruction.

The X gate applies the matrix \(\left[\begin{matrix}0 & 1\\1 & 0\end{matrix}\right]\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.X]] = 8
class Y(target: int)

Bases: _KindChecker, SingleTargetInstruction

Y circuit instruction.

The Y gate applies the matrix \(\left[\begin{matrix}0 & -\mathrm i\\\mathrm i & 0\end{matrix}\right]\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.Y]] = 9
class Z(target: int)

Bases: _KindChecker, SingleTargetInstruction

Z circuit instruction.

The Z gate applies the matrix \(\left[\begin{matrix}1 & 0\\\mathrm 0 & -1\end{matrix}\right]\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.Z]] = 10
class H(target: int)

Bases: _KindChecker, SingleTargetInstruction

H circuit instruction.

The Hadamard gate applies the matrix \(\frac 1 {\sqrt 2}\left[\begin{matrix}1 & 1\\1 & -1\end{matrix}\right]\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.H]] = 6
class S(target: int)

Bases: _KindChecker, SingleTargetInstruction

S circuit instruction.

The S gate applies the matrix \(\left[\begin{matrix}1 & 0\\0 & \mathrm i\end{matrix}\right]\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.S]] = 7
class SDG(target: int)

Bases: _KindChecker, SingleTargetInstruction

SDG circuit instruction.

The \(S^\dagger\) gate applies the matrix \(\left[\begin{matrix}1 & 0\\0 & - \mathrm i\end{matrix}\right]\).

We have \(S^\dagger = \mathrm e^{\mathrm i \frac \pi 4} R_Z(-\frac \pi 2)\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.SDG]] = 17
class T(target: int)

Bases: _KindChecker, SingleTargetInstruction

T circuit instruction.

The \(T\) gate applies the matrix \(\left[\begin{matrix}1 & 0\\0 & \mathrm e^{\mathrm i \frac \pi 4}\end{matrix}\right]\).

We have \(T = \mathrm e^{\mathrm i \frac \pi 8} R_Z(\frac \pi 4)\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.T]] = 18
class TDG(target: int)

Bases: _KindChecker, SingleTargetInstruction

TDG circuit instruction.

The \(T^\dagger\) gate applies the matrix \(\left[\begin{matrix}1 & 0\\0 & \mathrm e^{- \mathrm i \frac \pi 4}\end{matrix}\right]\).

We have \(T^\dagger = \mathrm e^{\mathrm i \frac \pi 8} R_Z(- \frac \pi 4)\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.TDG]] = 19
class SX(target: int)

Bases: _KindChecker, SingleTargetInstruction

SX circuit instruction.

The \(SX\) (\(\sqrt X\)) gate applies the matrix \(\frac 1 2 \left[\begin{matrix}1 + \mathrm i & 1 - \mathrm i\\1 - \mathrm i & 1 + \mathrm i\end{matrix}\right]\).

We have \(SX = \mathrm e^{\mathrm i \frac \pi 4} R_X(\frac \pi 2)\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.SX]] = 20
class SXDG(target: int)

Bases: _KindChecker, SingleTargetInstruction

SXDG circuit instruction.

The \(SX^\dagger\) (\({\sqrt X}^\dagger\)) gate applies the matrix \(\frac 1 2 \left[\begin{matrix}1 - \mathrm i & 1 + \mathrm i\\1 + \mathrm i & 1 - \mathrm i\end{matrix}\right]\).

We have \(SX^\dagger = \mathrm e^{\mathrm i \frac \pi 4} R_X(-\frac \pi 2)\).

__init__(target: int) → None
kind: ClassVar[Literal[InstructionKind.SXDG]] = 21
class J(target: int, angle: Expression | float)

Bases: _KindChecker, RotationInstruction

J circuit instruction.

The \(J(\theta)\) gate applies the matrix

\[\begin{split}\frac 1 {\sqrt 2} \left[\begin{matrix} 1 & \mathrm e^{\mathrm i \theta}\\ 1 & - \mathrm e^{\mathrm i \theta} \end{matrix}\right]\end{split}\]

We have \(J(\theta) = \mathrm e^{\mathrm i \theta/2} H \mathrm{RZ}(\theta)\).

__init__(target: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.J]] = 11
class P(target: int, angle: Expression | float)

Bases: _KindChecker, RotationInstruction

P rotation circuit instruction.

The \(P(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0\\ 0 & \mathrm e^{\mathrm i \theta} \end{matrix}\right]\end{split}\]

We have \(P(\theta) = \mathrm e^{\theta/2} R_Z(\theta)\).

__init__(target: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.P]] = 23
class RX(target: int, angle: Expression | float)

Bases: _KindChecker, RotationInstruction

X rotation circuit instruction.

The \(RX(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \cos \frac \theta 2 & -\mathrm i \sin \frac \theta 2\\ -\mathrm i \sin \frac \theta 2 & \cos \frac \theta 2 \end{matrix}\right]\end{split}\]
__init__(target: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.RX]] = 14
class RY(target: int, angle: Expression | float)

Bases: _KindChecker, RotationInstruction

Y rotation circuit instruction.

The \(RY(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \cos \frac \theta 2 & - \sin \frac \theta 2\\ \sin \frac \theta 2 & \cos \frac \theta 2 \end{matrix}\right]\end{split}\]
__init__(target: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.RY]] = 15
class RZ(target: int, angle: Expression | float)

Bases: _KindChecker, RotationInstruction

Z rotation circuit instruction.

The \(RZ(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \mathrm e^{-\mathrm i \frac \theta 2} & 0\\ 0 & \mathrm e^{\mathrm i \frac \theta 2} \end{matrix}\right]\end{split}\]
__init__(target: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.RZ]] = 16
class U(target: int, theta: Expression | float, phi: Expression | float, lambda_: Expression | float)

Bases: _KindChecker, BaseInstruction

U circuit instruction.

The \(U(\theta, \phi, \lambda)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \cos \frac \theta 2 & - \mathrm e^{\mathrm i\lambda} \sin \frac \theta 2 \\ \mathrm e^{\mathrm i \phi} \sin \frac \theta 2 & \mathrm e^{\mathrm i (\phi + \lambda)} \cos \frac \theta 2 \end{matrix}\right]\end{split}\]

It can be decomposed as

\[U(\theta, \phi, \lambda) = \mathrm e^{\mathrm i\frac{\phi + \lambda}{2}} R_Z(\phi) R_Y(\theta) R_Z(\lambda) = \mathrm e^{\mathrm i\frac{\theta}{2}} H J\left(\phi + \frac{\pi}{2}\right) J(\theta) J\left(\lambda - \frac{\pi}{2}\right)\]
__init__(target: int, theta: Expression | float, phi: Expression | float, lambda_: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.U]] = 24
visit(visitor: InstructionVisitor, *, copy: bool = False) → Self

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

target: int
theta: Expression | float
phi: Expression | float
lambda_: Expression | float
class CJ(target: int, control: int, angle: Expression | float)

Bases: _KindChecker, ControlledRotationInstruction

Controlled-J circuit instruction.

The \(CJ(\alpha)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \frac 1 {\sqrt 2} & \frac 1 {\sqrt 2} \mathrm e^{\mathrm i \alpha}\\ 0 & 0 & \frac 1 {\sqrt 2} & - \frac 1 {\sqrt 2} \mathrm e^{\mathrm i \alpha} \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

Following Lemmas 4.3 and 5.1 of Barenco et al. (1995), we define:

\[\begin{split}\begin{aligned} A &= R_Y\left(\frac \pi 4\right),\\ B &= R_Y\left(- \frac \pi 4\right) R_Z(- \delta),\\ C &= R_Z(\delta),\\ \delta &= \frac {\alpha + \pi} 2 \end{aligned}\end{split}\]

These operators satisfy \(ABC = I\) and \(AXBXC = \mathrm e^{-\mathrm i \delta} J(\alpha)\).

Consequently, \(CJ(\alpha)\) can be decomposed as:

\[CJ(\alpha) = (P(\delta) \otimes I) \, (I \otimes A) \, CX \, (I \otimes B) \, CX \, (I \otimes C)\]
control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

References

Barenco, A., Bennett, C. H., Cleve, R., DiVincenzo, D. P., Margolus, N., Shor, P., Sleator, T., Smolin, J. A., & Weinfurter, H. (1995). Elementary gates for quantum computation. Physical Review A, 52(5), 3457-3467. https://doi.org/10.1103/physreva.52.3457

__init__(target: int, control: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.CJ]] = 25
class CP(target: int, control: int, angle: Expression | float)

Bases: _KindChecker, ControlledRotationInstruction

Controlled-P circuit instruction.

The \(CP(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & \mathrm e^{\mathrm i \theta} \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Phase angle.

Type:

ParameterizedAngle

__init__(target: int, control: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.CP]] = 26
class CRX(target: int, control: int, angle: Expression | float)

Bases: _KindChecker, ControlledRotationInstruction

Controlled-X rotation circuit instruction.

The \(CRX(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \cos \frac \theta 2 & -\mathrm i \sin \frac \theta 2\\ 0 & 0 & -\mathrm i \sin \frac \theta 2 & \cos \frac \theta 2 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

__init__(target: int, control: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.CRX]] = 27
class CRY(target: int, control: int, angle: Expression | float)

Bases: _KindChecker, ControlledRotationInstruction

Controlled-Y rotation circuit instruction.

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \cos \frac \theta 2 & - \sin \frac \theta 2\\ 0 & 0 & \sin \frac \theta 2 & \cos \frac \theta 2 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

__init__(target: int, control: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.CRY]] = 28
class CRZ(target: int, control: int, angle: Expression | float)

Bases: _KindChecker, ControlledRotationInstruction

Controlled-Z rotation circuit instruction.

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & \mathrm e^{-\mathrm i \frac \theta 2} & 0\\ 0 & 0 & 0 & \mathrm e^{\mathrm i \frac \theta 2} \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

__init__(target: int, control: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.CRZ]] = 29
class CU(control: int, target: int, theta: Expression | float, phi: Expression | float, lambda_: Expression | float, gamma: Expression | float)

Bases: _KindChecker, BaseInstruction

Controlled-U circuit instruction.

The \(CU(\theta, \phi, \lambda, \gamma)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \mathrm e^{\mathrm i\gamma} \cos\left(\frac{\theta}{2}\right) & -\mathrm e^{\mathrm i(\gamma + \lambda)} \sin\left(\frac{\theta}{2}\right) \\ 0 & 0 & \mathrm e^{\mathrm i(\gamma + \phi)} \sin\left(\frac{\theta}{2}\right) & \mathrm e^{\mathrm i(\gamma + \phi + \lambda)} \cos\left(\frac{\theta}{2}\right) \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

It can be decomposed as

\[CU(\theta, \phi, \lambda, \gamma) = \left(P\left(\frac{\gamma - \theta} 2\right) \otimes I\right) CJ(0) CJ\left(\phi + \frac \pi 2\right) CJ(\theta) CJ\left(\lambda - \frac \pi 2\right)\]
control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

theta

Rotation angle around the Y axis.

Type:

ParameterizedAngle

phi

Rotation angle around the Z axis after the Y rotation.

Type:

ParameterizedAngle

lambda_

Rotation angle around the Z axis before the Y rotation.

Type:

ParameterizedAngle

gamma

Global phase angle.

Type:

ParameterizedAngle

__init__(control: int, target: int, theta: Expression | float, phi: Expression | float, lambda_: Expression | float, gamma: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.CU]] = 30
visit(visitor: InstructionVisitor, *, copy: bool = False) → Self

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

control: int
target: int
theta: Expression | float
phi: Expression | float
lambda_: Expression | float
gamma: Expression | float
class CNOT(target: int, control: int)

Bases: _KindChecker, ControlledSingleTargetInstruction

CNOT circuit instruction.

The CNOT gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

__init__(target: int, control: int) → None
kind: ClassVar[Literal[InstructionKind.CNOT]] = 3
class CY(target: int, control: int)

Bases: _KindChecker, ControlledSingleTargetInstruction

CY circuit instruction.

The CY gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & -\mathrm i\\ 0 & 0 & \mathrm i & 0 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

__init__(target: int, control: int) → None
kind: ClassVar[Literal[InstructionKind.CY]] = 22
class CZ(targets: tuple[int, int])

Bases: _KindChecker, BaseInstruction

CZ circuit instruction.

The CZ gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & -1 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order targets[0], targets[1].

targets

Index of the target qubits.

Type:

tuple[int, int]

__init__(targets: tuple[int, int]) → None
kind: ClassVar[Literal[InstructionKind.CZ]] = 5
visit(visitor: InstructionVisitor, *, copy: bool = False) → CZ

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

targets: tuple[int, int]
class CCX(target: int, controls: tuple[int, int])

Bases: _KindChecker, BaseInstruction

Toffoli circuit instruction.

The CCX gate applies the matrix

\[\begin{split}\left[\begin{matrix} 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{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order controls[0], controls[1], target.

controls

Index of the control qubits.

Type:

tuple[int, int]

target

Index of the target qubit.

Type:

int

__init__(target: int, controls: tuple[int, int]) → None
kind: ClassVar[Literal[InstructionKind.CCX]] = 1
visit(visitor: InstructionVisitor, *, copy: bool = False) → CCX

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

target: int
controls: tuple[int, int]
class RZZ(target: int, control: int, angle: Expression | float)

Bases: _KindChecker, BaseInstruction

RZZ circuit instruction.

The \(\mathrm{RZZ}(\theta)\) gate applies the matrix

\[\begin{split}\left[\begin{matrix} \mathrm e^{-\mathrm i \frac \theta 2} & 0 & 0 & 0\\ 0 & \mathrm e^{\mathrm i \frac \theta 2} & 0 & 0\\ 0 & 0 & \mathrm e^{\mathrm i \frac \theta 2} & 0\\ 0 & 0 & 0 & \mathrm e^{-\mathrm i \frac \theta 2} \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, target.

We have \(\mathrm{RZZ}(\theta) = \mathrm{CNOT} (I \otimes \mathrm{RZ}(\theta)) \mathrm{CNOT}\).

control

Index of the control qubit.

Type:

int

target

Index of the target qubit.

Type:

int

angle

Rotation angle.

Type:

ParameterizedAngle

__init__(target: int, control: int, angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.RZZ]] = 2
visit(visitor: InstructionVisitor, *, copy: bool = False) → RZZ

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

target: int
control: int
angle: Expression | float
class SWAP(targets: tuple[int, int])

Bases: _KindChecker, BaseInstruction

SWAP circuit instruction.

The SWAP gate applies the matrix

\[\begin{split}\left[\begin{matrix} 1 & 0 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 0 & 1 \end{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order targets[0], targets[1].

targets

Index of the target qubits.

Type:

tuple[int, int]

__init__(targets: tuple[int, int]) → None
kind: ClassVar[Literal[InstructionKind.SWAP]] = 4
visit(visitor: InstructionVisitor, *, copy: bool = False) → SWAP

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

targets: tuple[int, int]
class CSWAP(control: int, targets: tuple[int, int])

Bases: _KindChecker, BaseInstruction

CSWAP circuit instruction.

The CSWAP gate applies the matrix

\[\begin{split}\left[\begin{matrix} 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{matrix}\right]\end{split}\]

in the computational basis. The basis states use big-endian ordering, with the most significant qubit first. The qubits are numbered in the order control, targets[0], targets[1].

control

Index of the control qubit.

Type:

int

targets

Indices of the two target qubits.

Type:

tuple[int, int]

__init__(control: int, targets: tuple[int, int]) → None
kind: ClassVar[Literal[InstructionKind.CSWAP]] = 31
visit(visitor: InstructionVisitor, *, copy: bool = False) → CSWAP

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

control: int
targets: tuple[int, int]
class M(target: int, axis: Axis)

Bases: _KindChecker, BaseInstruction

M circuit instruction.

__init__(target: int, axis: Axis) → None
kind: ClassVar[Literal[InstructionKind.M]] = 13
visit(visitor: InstructionVisitor, *, copy: bool = False) → M

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

target: int
axis: Axis
class GPHASE(angle: Expression | float)

Bases: _KindChecker, BaseInstruction

GPHASE circuit instruction.

angle

Phase angle.

Type:

ParameterizedAngle

__init__(angle: Expression | float) → None
kind: ClassVar[Literal[InstructionKind.GPHASE]] = 32
visit(visitor: InstructionVisitor, *, copy: bool = False) → GPHASE

Rewrite the instruction according to the given visitor.

Parameters:
  • visitor (InstructionVisitor) – The visitor specifying the rewriting.

  • copy (bool, optional) – If True, the current instruction remains unchanged, and a new instruction is returned. The default is False, meaning that changes are performed in place.

Returns:

The rewritten instruction. Equal to self if copy is False.

Return type:

Self

angle: Expression | float
__init__() → None[source]