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:
EnumEnumeration for manual scheduling strategies derived from circuit structure.
- PARALLEL = 1¶
- MINIMIZE_SPACE = 2¶
- class graphqomb.circuit.BaseCircuit[source]¶
Bases:
ABCAbstract 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:
- class graphqomb.circuit.MBQCCircuit[source]¶
Bases:
BaseCircuitA circuit class composed solely of a unit gate set.
- property num_qubits: int¶
Get the number of qubits in the circuit.
- Returns:
The number of qubits in the circuit.
- Return type:
- phase_gadget(qubits, angle)[source]¶
Add a phase gadget to the circuit.
- Parameters:
qubits (
collections.abc.Sequence[int]) – The qubit indices.angle (
float) – The angle of the phase gadget
- class graphqomb.circuit.Circuit[source]¶
Bases:
BaseCircuitA class for circuits that include macro instructions.
- property num_qubits: int¶
Get the number of qubits in the circuit.
- Returns:
The number of qubits in the circuit.
- Return type:
- graphqomb.circuit.circuit2graph(circuit, schedule_strategy=CircuitScheduleStrategy.PARALLEL)[source]¶
Convert a circuit to a graph state, gflow, and scheduler.
- Parameters:
circuit (
BaseCircuit) – The quantum circuit to convert.schedule_strategy (
CircuitScheduleStrategy, optional) –Strategy for scheduling preparation and measurement times derived from the circuit, by default
CircuitScheduleStrategy.PARALLEL. The strategies are:CircuitScheduleStrategy.PARALLEL: schedule each qubit independently to reduce depthCircuitScheduleStrategy.MINIMIZE_SPACE: serialize operations to reduce prepared qubits
- 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:
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.
- class graphqomb.gates.J[source]¶
Class for the J gate.
- 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:
- matrix()[source]¶
Get the matrix representation of the gate.
- Returns:
Matrix representation of the gate.
- Return type:
- __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}\]
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- matrix()[source]¶
Get the
matrixrepresentation of the gate.- Returns:
Matrix representation of the gate.
- Return type:
- __init__(qubits)¶
- class graphqomb.gates.PhaseGadget[source]¶
Class for the PhaseGadget gate.
- angle¶
The angle of the PhaseGadget gate.
\[PhaseGadget(\theta) = \exp\left(-i\frac{\theta}{2}\prod_{j}Z_j\right)\]- Type:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- matrix()[source]¶
Get the
matrixrepresentation of the gate.- Returns:
Matrix representation of the gate.
- Return type:
- __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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __init__(qubit)¶
- class graphqomb.gates.Rx[source]¶
Class for the Rx gate.
- 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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __init__(qubit, angle)¶
- class graphqomb.gates.Ry[source]¶
Class for the Ry gate.
- 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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __init__(qubit, angle)¶
- class graphqomb.gates.Rz[source]¶
Class for the Rz gate.
- 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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __init__(qubit, angle)¶
- class graphqomb.gates.U3[source]¶
Class for the U3 gate.
- 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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __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}\]
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- matrix()[source]¶
Get the
matrixrepresentation of the gate.- Returns:
Matrix representation of the gate.
- Return type:
- __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}\]
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- matrix()[source]¶
Get the
matrixrepresentation of the gate.- Returns:
Matrix representation of the gate.
- Return type:
- __init__(qubits)¶
- class graphqomb.gates.CRz[source]¶
Class for the CRz gate.
- 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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- matrix()[source]¶
Get the
matrixrepresentation of the gate.- Returns:
Matrix representation of the gate.
- Return type:
- __init__(qubits, angle)¶
- class graphqomb.gates.CRx[source]¶
Class for the CRx gate.
- 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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- matrix()[source]¶
Get the
matrixrepresentation of the gate.- Returns:
Matrix representation of the gate.
- Return type:
- __init__(qubits, angle)¶
- class graphqomb.gates.CU3[source]¶
Class for the CU3 gate.
- 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:
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- matrix()[source]¶
Get the
matrixrepresentation of the gate.- Returns:
Matrix representation of the gate.
- Return type:
- __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}\]
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- matrix()[source]¶
Get the
matrixrepresentation of the gate.- Returns:
Matrix representation of the gate.
- Return type:
- __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}\]
- unit_gates()[source]¶
Get the
unit_gatesthat make up the gate.
- __init__(qubits)¶