Quantum Circuit

Circuit

Circuit classes for encoding quantum operations.

This module provides:

  • BaseCircuit: An abstract base class for quantum circuits.

  • MBQCCircuit: A circuit class composed solely of a unit gate set.

  • Circuit: A class for circuits that include macro instructions.

  • CircuitScheduleStrategy: Scheduling strategies for circuit conversion.

  • circuit2graph: A function that converts a circuit to a graph state, gflow, and scheduler.

class graphqomb.circuit.CircuitScheduleStrategy[source]

Bases: Enum

Enumeration for manual scheduling strategies derived from circuit structure.

PARALLEL = 1
MINIMIZE_SPACE = 2
class graphqomb.circuit.BaseCircuit[source]

Bases: ABC

Abstract base class for quantum circuits.

This class defines the interface for quantum circuit objects. It enforces implementation of core methods that must be present in any subclass representing a specific type of quantum circuit.

abstract property num_qubits: int

Get the number of qubits in the circuit.

Returns:

The number of qubits in the circuit

Return type:

int

abstractmethod instructions()[source]

Get the list of gate instructions in the circuit.

Returns:

List of gate instructions in the circuit.

Return type:

list[Gate]

abstractmethod unit_instructions()[source]

Get the list of unit gate instructions in the circuit.

Returns:

List of unit gate instructions in the circuit.

Return type:

list[UnitGate]

class graphqomb.circuit.MBQCCircuit[source]

Bases: BaseCircuit

A circuit class composed solely of a unit gate set.

__init__(num_qubits)[source]
property num_qubits: int

Get the number of qubits in the circuit.

Returns:

The number of qubits in the circuit.

Return type:

int

instructions()[source]

Get the list of gate instructions in the circuit.

Returns:

List of gate instructions in the circuit.

Return type:

list[Gate]

unit_instructions()[source]

Get the list of unit gate instructions in the circuit.

Returns:

List of unit gate instructions in the circuit.

Return type:

list[UnitGate]

j(qubit, angle)[source]

Add a J gate to the circuit.

Parameters:
  • qubit (int) – The qubit index.

  • angle (float) – The angle of the J gate.

cz(qubit1, qubit2)[source]

Add a CZ gate to the circuit.

Parameters:
  • qubit1 (int) – The first qubit index.

  • qubit2 (int) – The second qubit index.

phase_gadget(qubits, angle)[source]

Add a phase gadget to the circuit.

Parameters:
class graphqomb.circuit.Circuit[source]

Bases: BaseCircuit

A class for circuits that include macro instructions.

__init__(num_qubits)[source]
property num_qubits: int

Get the number of qubits in the circuit.

Returns:

The number of qubits in the circuit.

Return type:

int

instructions()[source]

Get the list of gate instructions in the circuit.

Returns:

List of gate instructions in the circuit.

Return type:

list[Gate]

unit_instructions()[source]

Get the list of unit gate instructions in the circuit.

Returns:

The list of unit gate instructions in the circuit.

Return type:

list[UnitGate]

apply_macro_gate(gate)[source]

Apply a macro gate to the circuit.

Parameters:

gate (Gate) – The macro gate to apply.

graphqomb.circuit.circuit2graph(circuit, schedule_strategy=CircuitScheduleStrategy.PARALLEL)[source]

Convert a circuit to a graph state, gflow, and scheduler.

Parameters:
Returns:

The graph state, gflow, and scheduler converted from the circuit. The scheduler is configured with automatic time scheduling derived from circuit structure.

Return type:

tuple[GraphState, dict[int, set[int]], Scheduler]

Gate

Module for gates used in circuit representation.

This module provides:

  • Gate: Abstract class for gates.

  • UnitGate: Abstract class for unit gates.

  • J: Class for the J gate.

  • CZ: Class for the CZ gate.

  • PhaseGadget: Class for the PhaseGadget gate.

  • Identity: Class for the Identity gate.

  • X: Class for the X gate.

  • Y: Class for the Y gate.

  • Z: Class for the Z gate.

  • H: Class for the H gate.

  • S: Class for the S gate.

  • T: Class for the T gate.

  • Tdg: Class for the Tdg gate.

  • Rx: Class for the Rx gate.

  • Ry: Class for the Ry gate.

  • Rz: Class for the Rz gate.

  • U3: Class for the U3 gate.

  • CNOT: Class for the CNOT gate.

  • SWAP: Class for the SWAP gate.

  • CRz: Class for the CRz gate.

  • CRx: Class for the CRx gate.

  • CU3: Class for the CU3 gate.

  • Toffoli: Class for the Toffoli gate.

  • CCZ: Class for the CCZ gate.

class graphqomb.gates.Gate[source]

Abstract class for gates.

abstractmethod unit_gates()[source]

Get the unit gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

abstractmethod matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

class graphqomb.gates.SingleGate[source]

Base class for single qubit macro gates.

class graphqomb.gates.TwoQubitGate[source]

Base class for two qubit macro gates.

class graphqomb.gates.MultiGate[source]

Base class for multi qubit macro gates.

class graphqomb.gates.J[source]

Class for the J gate.

qubit

The qubit the gate acts on.

Type:

int

angle

The angle of the J gate.

\[\begin{split}J = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & e^{i\theta} \\ 1 & -e^{i\theta} \end{pmatrix}\end{split}\]
Type:

float

unit_gates()[source]

Get the unit gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit, angle)
class graphqomb.gates.CZ[source]

Class for the CZ gate.

qubits

The qubits the gate acts on.

\[\begin{split}CZ = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}\end{split}\]
Type:

tuple[int, int]

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubits)
class graphqomb.gates.PhaseGadget[source]

Class for the PhaseGadget gate.

qubits

The qubits the gate acts on.

Type:

list[int]

angle

The angle of the PhaseGadget gate.

\[PhaseGadget(\theta) = \exp\left(-i\frac{\theta}{2}\prod_{j}Z_j\right)\]
Type:

float

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubits, angle)
graphqomb.gates.UnitGate: TypeAlias = graphqomb.gates.J | graphqomb.gates.CZ | graphqomb.gates.PhaseGadget

Unit gate type

class graphqomb.gates.Identity[source]

Class for the Identity gate.

qubit

The qubit the gate acts on.

\[\begin{split}I = \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix}\end{split}\]
Type:

int

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Identity matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit)
class graphqomb.gates.X[source]

Class for the X gate.

qubit

The qubit the gate acts on.

\[\begin{split}X = \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix}\end{split}\]
Type:

int

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

X gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit)
class graphqomb.gates.Y[source]

Class for the Y gate.

qubit

The qubit the gate acts on.

\[\begin{split}Y = \begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix}\end{split}\]
Type:

int

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Y gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit)
class graphqomb.gates.Z[source]

Class for the Z gate.

qubit

The qubit the gate acts on.

\[\begin{split}Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}\end{split}\]
Type:

int

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Z gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit)
class graphqomb.gates.H[source]

Class for the H gate.

qubit

The qubit the gate acts on.

\[\begin{split}H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\end{split}\]
Type:

int

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

H gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit)
class graphqomb.gates.S[source]

Class for the S gate.

qubit

The qubit the gate acts on.

\[\begin{split}S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\end{split}\]
Type:

int

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

S gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit)
class graphqomb.gates.T[source]

Class for the T gate.

qubit

The qubit the gate acts on.

\[\begin{split}T = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}\end{split}\]
Type:

int

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

T gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit)
class graphqomb.gates.Tdg[source]

Class for the Tdg gate.

qubit

The qubit the gate acts on.

\[\begin{split}T^\dagger = \begin{pmatrix} 1 & 0 \\ 0 & e^{-i\pi/4} \end{pmatrix}\end{split}\]
Type:

int

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Tdg gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit)
class graphqomb.gates.Rx[source]

Class for the Rx gate.

qubit

The qubit the gate acts on.

Type:

int

angle

The angle of the Rx gate.

\[\begin{split}R_x(\theta) = \begin{pmatrix} \cos(\theta/2) & -i\sin(\theta/2) \\ -i\sin(\theta/2) & \cos(\theta/2) \end{pmatrix}\end{split}\]
Type:

float

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Rx gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit, angle)
class graphqomb.gates.Ry[source]

Class for the Ry gate.

qubit

The qubit the gate acts on.

Type:

int

angle

The angle of the Ry gate.

\[\begin{split}R_y(\theta) = \begin{pmatrix} \cos(\theta/2) & -\sin(\theta/2) \\ \sin(\theta/2) & \cos(\theta/2) \end{pmatrix}\end{split}\]
Type:

float

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Ry gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit, angle)
class graphqomb.gates.Rz[source]

Class for the Rz gate.

qubit

The qubit the gate acts on.

Type:

int

angle

The angle of the Rz gate.

\[\begin{split}R_z(\theta) = \begin{pmatrix} e^{-i\theta/2} & 0 \\ 0 & e^{i\theta/2} \end{pmatrix}\end{split}\]
Type:

float

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Rz gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit, angle)
class graphqomb.gates.U3[source]

Class for the U3 gate.

qubit

The qubit the gate acts on.

Type:

int

angle1

The first angle of the U3 gate.

Type:

float

angle2

The second angle of the U3 gate.

Type:

float

angle3

The third angle of the U3 gate.

\[\begin{split}U3(\theta, \phi, \lambda) = \begin{pmatrix} \cos(\theta/2) & -e^{i\lambda}\sin(\theta/2) \\ e^{i\phi}\sin(\theta/2) & e^{i(\phi+\lambda)}\cos(\theta/2) \end{pmatrix}\end{split}\]
Type:

float

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

U3 gate matrix.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubit, angle1, angle2, angle3)
class graphqomb.gates.CNOT[source]

Class for the CNOT gate.

qubits

The qubits the gate acts on [control target].

\[\begin{split}CNOT = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}\end{split}\]
Type:

tuple[int, int]

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubits)
class graphqomb.gates.SWAP[source]

Class for the SWAP gate.

qubits

The qubits the gate acts on [control target].

\[\begin{split}SWAP = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]
Type:

tuple[int, int]

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubits)
class graphqomb.gates.CRz[source]

Class for the CRz gate.

qubits

The qubits the gate acts on [control target].

Type:

tuple[int, int]

angle

The angle of the CRz gate.

\[\begin{split}CR_z(\theta) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{-i\theta/2} & 0 \\ 0 & 0 & 0 & e^{i\theta/2} \end{pmatrix}\end{split}\]
Type:

float

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubits, angle)
class graphqomb.gates.CRx[source]

Class for the CRx gate.

qubits

The qubits the gate acts on [control target].

Type:

tuple[int, int]

angle

The angle of the CRx gate.

\[\begin{split}CR_x(\theta) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos(\theta/2) & -i\sin(\theta/2) \\ 0 & 0 & -i\sin(\theta/2) & \cos(\theta/2) \end{pmatrix}\end{split}\]
Type:

float

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubits, angle)
class graphqomb.gates.CU3[source]

Class for the CU3 gate.

qubits

The qubits the gate acts on.

Type:

tuple[int, int]

angle1

The first angle of the CU3 gate.

Type:

float

angle2

The second angle of the CU3 gate.

Type:

float

angle3

The third angle of the CU3 gate.

\[\begin{split}CU3(\theta, \phi, \lambda) = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos(\theta/2) & -e^{i\lambda}\sin(\theta/2) \\ 0 & 0 & e^{i\phi}\sin(\theta/2) & e^{i(\phi+\lambda)}\cos(\theta/2) \end{pmatrix}\end{split}\]
Type:

float

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubits, angle1, angle2, angle3)
class graphqomb.gates.Toffoli[source]

Class for the Toffoli gate.

qubits

The qubits the gate acts on [control1, control2, target].

\[\begin{split}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}\]
Type:

list[int]

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]

__init__(qubits)
class graphqomb.gates.CCZ[source]

Class for the CCZ gate.

qubits

The qubits the gate acts on [control1, control2, target].

\[\begin{split}CCZ = \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 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 & -1 \end{pmatrix}\end{split}\]
Type:

list[int]

unit_gates()[source]

Get the unit_gates that make up the gate.

Returns:

List of unit gates that make up the gate.

Return type:

list[UnitGate]

__init__(qubits)
matrix()[source]

Get the matrix representation of the gate.

Returns:

Matrix representation of the gate.

Return type:

numpy.typing.NDArray[numpy.complex128]