cqlib.circuits.gates package

Submodules

cqlib.circuits.gates.gate module

Quantum Gate

class cqlib.circuits.gates.gate.ControlledGate(name: str, num_qubits: int, control_index: list[int], base_gate: Gate, params: List[Parameter | float | complex], label: str | None = None)

Bases: Gate

A quantum gate with one or more control qubits.

This class represents a quantum gate that has control qubits in addition to target qubits.

class cqlib.circuits.gates.gate.Gate(name: str, num_qubits: int, params: List[Parameter | float | complex], label: str | None = None)

Bases: Instruction

Quantum Gate

This class represents a general quantum gate. It is a subclass of the Instruction class.

cqlib.circuits.gates.h module

Hadamard gate.

class cqlib.circuits.gates.h.H(label: str | None = None)

Bases: Gate

Hadamard gate.

The Hadamard gate is a single-qubit gate that creates a superposition state. It transforms the basis states |0⟩ and |1⟩ into an equal superposition of both states.

cqlib.circuits.gates.i module

Identity Gate (I) represents no operation on the qubit for a specified time period t (in nanoseconds, ns). The time t is given in integer units of 0.5 ns. For example, when t=1, the duration is 0.5 ns.

class cqlib.circuits.gates.i.I(t: int, label: str | None = None)

Bases: Gate

Identity gate (I gate), represents no operation on a qubit over a time period.

The Identity gate leaves the state of the qubit unchanged. It is useful for timing and synchronization purposes in quantum circuits.

cqlib.circuits.gates.rx module

Defines the Rx (rotation around the X-axis) and CRx (Controlled-RX) gate.

class cqlib.circuits.gates.rx.CRX(theta: float | Parameter, label: str | None = None)

Bases: ControlledGate

Controlled-RX (CRX) gate, which is a two-qubit quantum gate.

This gate applies a controlled rotation around the x-axis on the target qubit depending on the state of the control qubit. It is represented by the matrix: [[ 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) ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CRX gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the CRX gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.rx.RX(theta: float | Parameter, label: str | None = None)

Bases: Gate

Rx gate applies a rotation around the x-axis of the Bloch sphere by a specified angle.

This gate is represented by the matrix: [[ cos(theta/2), -i*sin(theta/2) ], [ -i*sin(theta/2), cos(theta/2) ]]

cqlib.circuits.gates.rxy module

Defines the Rxy (rotation around the X-axis and Y-axis) gate.

class cqlib.circuits.gates.rxy.RXY(phi: float | Parameter, theta: float | Parameter, label: str | None = None)

Bases: Gate

Rxy gate.

This gate represents a rotation around both the X-axis by an angle phi and the Y-axis by an angle theta. It combines rotations around two axes, making it a versatile tool for manipulating qubit states.

cqlib.circuits.gates.ry module

Defines the Ry (rotation around the Y-axis) gate.

class cqlib.circuits.gates.ry.CRY(theta: float | Parameter, label: str | None = None)

Bases: ControlledGate

Controlled-Ry (CRY) gate, which is a two-qubit quantum gate.

This gate applies a controlled rotation around the y-axis on the target qubit depending on the state of the control qubit. It is represented by the matrix: [[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, cos(theta/2), -sin(theta/2) ], [ 0, 0, sin(theta/2), cos(theta/2) ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CRY gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the CRY gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.ry.RY(theta: float | Parameter, label: str | None = None)

Bases: Gate

Ry gate applies a rotation around the y-axis of the Bloch sphere by a specified angle.

This gate is represented by the matrix: [[ cos(theta/2), -sin(theta/2) ], [ sin(theta/2), cos(theta/2) ]]

cqlib.circuits.gates.rz module

Defines the Rz (rotation around the Z-axis) and CRz (Controlled-Rz) gate.

class cqlib.circuits.gates.rz.CRZ(theta: float | Parameter, label: str | None = None)

Bases: ControlledGate

Controlled-Rz (CRZ) gate, which is a two-qubit quantum gate.

This gate applies a controlled rotation around the z-axis on the target qubit depending on the state of the control qubit. It is represented by the matrix: [[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, exp(-i*theta/2), 0 ], [ 0, 0, 0, exp(i*theta/2) ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CRZ gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the CRZ gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.rz.RZ(theta: float | Parameter, label: str | None = None)

Bases: Gate

Rz gate applies a rotation around the z-axis of the Bloch sphere by a specified angle.

This gate is represented by the matrix: [[ exp(-i*theta/2), 0 ], [ 0, exp(i*theta/2) ]]

cqlib.circuits.gates.s module

The S, SD(S dagger) gates.

class cqlib.circuits.gates.s.S(label: str | None = None)

Bases: Gate

The S (Phase) gate, which applies a phase of pi/2.

This gate is represented by the matrix: [[ 1, 0 ], [ 0, i ]]

class cqlib.circuits.gates.s.SD(label: str | None = None)

Bases: Gate

Implements the SD gate (S dagger), which applies a phase of -pi/2.

This gate is represented by the matrix: [[ 1, 0 ], [ 0, -i ]]

cqlib.circuits.gates.swap module

Swap gate.

class cqlib.circuits.gates.swap.SWAP(label: str | None = None)

Bases: Gate

The Swap gate.

The SWAP gate exchanges the states of two qubits. It is represented by the following matrix: [[ 1, 0, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 0, 1 ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the SWAP gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the SWAP gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

cqlib.circuits.gates.t module

The T, TD(T dagger) gates.

class cqlib.circuits.gates.t.T(label: str | None = None)

Bases: Gate

The T (Phase) gate, which applies a phase of pi/4.

This gate is represented by the matrix: [[ 1, 0 ], [ 0, exp(i*pi/4) ]]

class cqlib.circuits.gates.t.TD(label: str | None = None)

Bases: Gate

Implements the TD gate (T dagger), which applies a phase of -pi/4.

This gate is represented by the matrix: [[ 1, 0 ], [ 0, exp(-i*pi/4) ]]

cqlib.circuits.gates.x module

Defines the Pauli X gate and its variants:

X2P (rotations around the x-axis by pi/2), X2M (rotations around the x-axis by -pi/2). Also includes the controlled versions CX (Controlled-X), CCX (Controlled-CX, also known as Toffoli gate).

Classes:

X: Pauli X gate, acts as a quantum NOT gate. CX: Controlled-X gate (CNOT), flips the target qubit if the control qubit is in the state |1>. CCX: Controlled-CX gate (Toffoli gate), flips the target qubit if both control qubits are in the state |1>. X2P: Rotates around the x-axis of the Bloch sphere by pi/2. X2M: Rotates around the x-axis of the Bloch sphere by -pi/2.

cqlib.circuits.gates.x.CCNOT

alias of CCX

class cqlib.circuits.gates.x.CCX(label: str | None = None)

Bases: ControlledGate

Controlled-CX gate, which is a three-qubit quantum gate.

Also known as the Toffoli gate, it flips the target qubit if both control qubits are in the state |1>.

It is represented by the 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 ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CCX gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly three qubits.

Returns:

A list of InstructionData objects representing the CCX gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly three.

cqlib.circuits.gates.x.CNOT

alias of CX

class cqlib.circuits.gates.x.CX(label: str | None = None)

Bases: ControlledGate

Controlled-X gate, which is a two-qubit quantum gate.

Also known as the CNOT gate, it flips the target qubit if the control qubit is in the state |1>.

It is represented by the matrix: [[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 0, 1 ], [ 0, 0, 1, 0 ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CX gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the CX gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.x.X(label: str | None = None)

Bases: Gate

Pauli X gate.

This gate acts as a quantum NOT gate, flipping the state of a qubit. It is represented by the matrix: [[ 0, 1 ], [ 1, 0 ]]

class cqlib.circuits.gates.x.X2M(label: str | None = None)

Bases: Gate

Implements the X2M gate, which applies a rotation around the x-axis of the Bloch sphere by -pi/2.

This gate is represented by the matrix: sqrt(1/2) * [[ 1, i ], [ i, 1 ]]

class cqlib.circuits.gates.x.X2P(label: str | None = None)

Bases: Gate

Implements the X2P gate, which applies a rotation around the x-axis of the Bloch sphere by pi/2.

This gate is represented by the matrix: sqrt(1/2) * [[ 1, -i ],[ -i, 1 ]]

cqlib.circuits.gates.xy module

XY gate and its variants XY2P and XY2M, which perform rotations around the x-axis and y-axis by specific angles.

Classes:

XY: Performs a composite rotation around the Z and Y axes, described by a specific sequence. XY2P: Rotates around the X-axis and Y-axis by pi/2. XY2M: Rotates around the X-axis and Y-axis by -pi/2.

class cqlib.circuits.gates.xy.XY(theta: float | Parameter, label: str | None = None)

Bases: Gate

Implements the XY gate, a composite quantum gate that performs a specific series

of rotations around the Z and Y axes.

The XY gate is constructed from the following sequence of operations: 1. Rz(pi/2 - theta): Rotation around the Z-axis by (pi/2 - theta) radians. 2. Y: Pauli Y gate that rotates the qubit around the Y-axis by pi radians. 3. Rz(theta - pi/2): Rotation around the Z-axis by (theta - pi/2) radians.

class cqlib.circuits.gates.xy.XY2M(theta: float | Parameter, label: str | None = None)

Bases: Gate

XY2M gate performs a rotation around the X-axis by -pi/2, modulated by a phase theta around the Y-axis.

class cqlib.circuits.gates.xy.XY2P(theta: float | Parameter, label: str | None = None)

Bases: Gate

XY2P gate performs a rotation around the X-axis by pi/2, modulated by a

phase theta around the Y-axis.

cqlib.circuits.gates.y module

Defines the Pauli Y gate and its variants: Y2P (rotations around the y-axis by pi/2) and Y2M (rotations around the y-axis by -pi/2).

Classes:

Y: Pauli Y gate, acts as a quantum bit flip and phase shift gate. Y2P: Performs a rotation around the y-axis by pi/2. Y2M: Performs a rotation around the y-axis by -pi/2.

class cqlib.circuits.gates.y.CY(label: str | None = None)

Bases: ControlledGate

CY gate.

This gate acts as both a bit flip and a phase shift on a qubit. It is represented by the matrix: [[ 1, 0, 0, 0],

[ 0, 0, 0, -i], [ 0, 0, 1, 0], [ 0, i, 0, 0]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CY gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly three qubits.

class cqlib.circuits.gates.y.Y(label: str | None = None)

Bases: Gate

Pauli Y gate.

This gate acts as both a bit flip and a phase shift on a qubit. It is represented by the matrix: [[ 0, -i ], [ i, 0 ]]

class cqlib.circuits.gates.y.Y2M(label: str | None = None)

Bases: Gate

Y2M gate performs a rotation around the Y-axis of the Bloch sphere by -pi/2.

This rotation is useful for undoing specific quantum operations or preparing quantum states. It is represented by the matrix: sqrt(1/2) * [[ 1, 1 ], [ -1, 1 ]]

class cqlib.circuits.gates.y.Y2P(label: str | None = None)

Bases: Gate

Y2P gate performs a rotation around the y-axis of the Bloch sphere by pi/2.

This rotation is useful for creating specific quantum states or for quantum state manipulation. It is represented by the matrix: sqrt(1/2) * [[ 1, -1 ], [ 1, 1 ]]

cqlib.circuits.gates.z module

Defines the Pauli Z gate and Controlled-Z (CZ) gate, fundamental elements in quantum circuits for phase manipulation.

Classes:

Z: Pauli Z gate, applies a phase shift of pi to the state |1>. CZ: Controlled-Z gate, applies a phase shift of pi to the target qubit only if the control qubit is in the state |1>.

class cqlib.circuits.gates.z.CZ(label: str | None = None)

Bases: ControlledGate

Controlled-Z (CZ) gate, which is a two-qubit quantum gate.

This gate applies a phase shift of pi to the target qubit only if the control qubit is in the state |1>. It is represented by the matrix: [[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, -1 ]]

class cqlib.circuits.gates.z.Z(label: str | None = None)

Bases: Gate

Pauli Z gate.

This gate applies a phase shift of pi to the quantum state |1>. It is represented by the matrix: [[ 1, 0 ], [ 0, -1 ]]

Module contents

Quantum gates

cqlib.circuits.gates.CCNOT

alias of CCX

class cqlib.circuits.gates.CCX(label: str | None = None)

Bases: ControlledGate

Controlled-CX gate, which is a three-qubit quantum gate.

Also known as the Toffoli gate, it flips the target qubit if both control qubits are in the state |1>.

It is represented by the 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 ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CCX gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly three qubits.

Returns:

A list of InstructionData objects representing the CCX gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly three.

cqlib.circuits.gates.CNOT

alias of CX

class cqlib.circuits.gates.CRX(theta: float | Parameter, label: str | None = None)

Bases: ControlledGate

Controlled-RX (CRX) gate, which is a two-qubit quantum gate.

This gate applies a controlled rotation around the x-axis on the target qubit depending on the state of the control qubit. It is represented by the matrix: [[ 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) ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CRX gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the CRX gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.CRY(theta: float | Parameter, label: str | None = None)

Bases: ControlledGate

Controlled-Ry (CRY) gate, which is a two-qubit quantum gate.

This gate applies a controlled rotation around the y-axis on the target qubit depending on the state of the control qubit. It is represented by the matrix: [[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, cos(theta/2), -sin(theta/2) ], [ 0, 0, sin(theta/2), cos(theta/2) ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CRY gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the CRY gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.CRZ(theta: float | Parameter, label: str | None = None)

Bases: ControlledGate

Controlled-Rz (CRZ) gate, which is a two-qubit quantum gate.

This gate applies a controlled rotation around the z-axis on the target qubit depending on the state of the control qubit. It is represented by the matrix: [[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, exp(-i*theta/2), 0 ], [ 0, 0, 0, exp(i*theta/2) ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CRZ gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the CRZ gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.CX(label: str | None = None)

Bases: ControlledGate

Controlled-X gate, which is a two-qubit quantum gate.

Also known as the CNOT gate, it flips the target qubit if the control qubit is in the state |1>.

It is represented by the matrix: [[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 0, 1 ], [ 0, 0, 1, 0 ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CX gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the CX gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.CY(label: str | None = None)

Bases: ControlledGate

CY gate.

This gate acts as both a bit flip and a phase shift on a qubit. It is represented by the matrix: [[ 1, 0, 0, 0],

[ 0, 0, 0, -i], [ 0, 0, 1, 0], [ 0, i, 0, 0]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the CY gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly three qubits.

class cqlib.circuits.gates.CZ(label: str | None = None)

Bases: ControlledGate

Controlled-Z (CZ) gate, which is a two-qubit quantum gate.

This gate applies a phase shift of pi to the target qubit only if the control qubit is in the state |1>. It is represented by the matrix: [[ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, -1 ]]

class cqlib.circuits.gates.FSIM(theta: float | Parameter | None = None, phi: float | Parameter | None = None, label: str | None = None)

Bases: Gate

FSIM gate class for quantum circuit operations.

The FSIM (Fermionic Simulation) gate is a two-qubit gate used to simulate fermionic interactions in quantum systems. This gate is commonly used in quantum chemistry simulations.

is_supported_by_qcis = True
class cqlib.circuits.gates.H(label: str | None = None)

Bases: Gate

Hadamard gate.

The Hadamard gate is a single-qubit gate that creates a superposition state. It transforms the basis states |0⟩ and |1⟩ into an equal superposition of both states.

class cqlib.circuits.gates.I(t: int, label: str | None = None)

Bases: Gate

Identity gate (I gate), represents no operation on a qubit over a time period.

The Identity gate leaves the state of the qubit unchanged. It is useful for timing and synchronization purposes in quantum circuits.

class cqlib.circuits.gates.RX(theta: float | Parameter, label: str | None = None)

Bases: Gate

Rx gate applies a rotation around the x-axis of the Bloch sphere by a specified angle.

This gate is represented by the matrix: [[ cos(theta/2), -i*sin(theta/2) ], [ -i*sin(theta/2), cos(theta/2) ]]

class cqlib.circuits.gates.RXY(phi: float | Parameter, theta: float | Parameter, label: str | None = None)

Bases: Gate

Rxy gate.

This gate represents a rotation around both the X-axis by an angle phi and the Y-axis by an angle theta. It combines rotations around two axes, making it a versatile tool for manipulating qubit states.

class cqlib.circuits.gates.RY(theta: float | Parameter, label: str | None = None)

Bases: Gate

Ry gate applies a rotation around the y-axis of the Bloch sphere by a specified angle.

This gate is represented by the matrix: [[ cos(theta/2), -sin(theta/2) ], [ sin(theta/2), cos(theta/2) ]]

class cqlib.circuits.gates.RZ(theta: float | Parameter, label: str | None = None)

Bases: Gate

Rz gate applies a rotation around the z-axis of the Bloch sphere by a specified angle.

This gate is represented by the matrix: [[ exp(-i*theta/2), 0 ], [ 0, exp(i*theta/2) ]]

class cqlib.circuits.gates.S(label: str | None = None)

Bases: Gate

The S (Phase) gate, which applies a phase of pi/2.

This gate is represented by the matrix: [[ 1, 0 ], [ 0, i ]]

class cqlib.circuits.gates.SD(label: str | None = None)

Bases: Gate

Implements the SD gate (S dagger), which applies a phase of -pi/2.

This gate is represented by the matrix: [[ 1, 0 ], [ 0, -i ]]

class cqlib.circuits.gates.SWAP(label: str | None = None)

Bases: Gate

The Swap gate.

The SWAP gate exchanges the states of two qubits. It is represented by the following matrix: [[ 1, 0, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 0, 1 ]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence) list

Convert the SWAP gate to a sequence of QCIS instructions.

Parameters:

qubits (list | tuple) – The list or tuple of qubits the gate acts on. It requires exactly two qubits.

Returns:

A list of InstructionData objects representing the SWAP gate in QCIS.

Return type:

list

Raises:

ValueError – If the number of qubits is not exactly two.

class cqlib.circuits.gates.T(label: str | None = None)

Bases: Gate

The T (Phase) gate, which applies a phase of pi/4.

This gate is represented by the matrix: [[ 1, 0 ], [ 0, exp(i*pi/4) ]]

class cqlib.circuits.gates.TD(label: str | None = None)

Bases: Gate

Implements the TD gate (T dagger), which applies a phase of -pi/4.

This gate is represented by the matrix: [[ 1, 0 ], [ 0, exp(-i*pi/4) ]]

class cqlib.circuits.gates.U(theta: float | Parameter, phi: float | Parameter, lam: float | Parameter, label: str | None = None)

Bases: Gate

U gate in quantum computing

It is represented by the matrix: U(theta,phi,lam)=

[ [ cos(theta/2), -exp(i * lam) * sin(theta/2)],

[ exp(i * phi) * sin(theta/2), exp(i * (phi+lam)) * cos(theta/2)]]

is_supported_by_qcis = False
to_qcis(qubits: Sequence[Qubit]) list[cqlib.circuits.instruction_data.InstructionData]

Convert the U gate to a sequence of QCIS instructions.

class cqlib.circuits.gates.X(label: str | None = None)

Bases: Gate

Pauli X gate.

This gate acts as a quantum NOT gate, flipping the state of a qubit. It is represented by the matrix: [[ 0, 1 ], [ 1, 0 ]]

class cqlib.circuits.gates.X2M(label: str | None = None)

Bases: Gate

Implements the X2M gate, which applies a rotation around the x-axis of the Bloch sphere by -pi/2.

This gate is represented by the matrix: sqrt(1/2) * [[ 1, i ], [ i, 1 ]]

class cqlib.circuits.gates.X2P(label: str | None = None)

Bases: Gate

Implements the X2P gate, which applies a rotation around the x-axis of the Bloch sphere by pi/2.

This gate is represented by the matrix: sqrt(1/2) * [[ 1, -i ],[ -i, 1 ]]

class cqlib.circuits.gates.XY(theta: float | Parameter, label: str | None = None)

Bases: Gate

Implements the XY gate, a composite quantum gate that performs a specific series

of rotations around the Z and Y axes.

The XY gate is constructed from the following sequence of operations: 1. Rz(pi/2 - theta): Rotation around the Z-axis by (pi/2 - theta) radians. 2. Y: Pauli Y gate that rotates the qubit around the Y-axis by pi radians. 3. Rz(theta - pi/2): Rotation around the Z-axis by (theta - pi/2) radians.

class cqlib.circuits.gates.XY2M(theta: float | Parameter, label: str | None = None)

Bases: Gate

XY2M gate performs a rotation around the X-axis by -pi/2, modulated by a phase theta around the Y-axis.

class cqlib.circuits.gates.XY2P(theta: float | Parameter, label: str | None = None)

Bases: Gate

XY2P gate performs a rotation around the X-axis by pi/2, modulated by a

phase theta around the Y-axis.

class cqlib.circuits.gates.Y(label: str | None = None)

Bases: Gate

Pauli Y gate.

This gate acts as both a bit flip and a phase shift on a qubit. It is represented by the matrix: [[ 0, -i ], [ i, 0 ]]

class cqlib.circuits.gates.Y2M(label: str | None = None)

Bases: Gate

Y2M gate performs a rotation around the Y-axis of the Bloch sphere by -pi/2.

This rotation is useful for undoing specific quantum operations or preparing quantum states. It is represented by the matrix: sqrt(1/2) * [[ 1, 1 ], [ -1, 1 ]]

class cqlib.circuits.gates.Y2P(label: str | None = None)

Bases: Gate

Y2P gate performs a rotation around the y-axis of the Bloch sphere by pi/2.

This rotation is useful for creating specific quantum states or for quantum state manipulation. It is represented by the matrix: sqrt(1/2) * [[ 1, -1 ], [ 1, 1 ]]

class cqlib.circuits.gates.Z(label: str | None = None)

Bases: Gate

Pauli Z gate.

This gate applies a phase shift of pi to the quantum state |1>. It is represented by the matrix: [[ 1, 0 ], [ 0, -1 ]]