|
Sequential Quantum Gate Decomposer
v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
|

Public Member Functions | |
| def | __init__ (self, qbit_num) |
| def | add_adaptive (self, target_qbit, control_qbit) |
| def | add_CCX (self, target_qbit, control_qbits) |
| def | add_CH (self, target_qbit, control_qbit) |
| def | add_Circuit (self, gate) |
| def | add_CNOT (self, target_qbit, control_qbit) |
| def | add_CP (self, target_qbit, control_qbit) |
| def | add_CR (self, target_qbit, control_qbit) |
| def | add_CROT (self, target_qbit, control_qbit) |
| def | add_CRX (self, target_qbit, control_qbit) |
| def | add_CRY (self, target_qbit, control_qbit) |
| def | add_CRZ (self, target_qbit, control_qbit) |
| def | add_CSWAP (self, target_qbits, control_qbits) |
| def | add_CU (self, target_qbit, control_qbit) |
| def | add_CZ (self, target_qbit, control_qbit) |
| def | add_Gate (self, qgd_gate) |
| def | add_GENERAL (self, operation_mtx, target_qbits=None, control_qbits=None, is_f32=False) |
| def | add_H (self, target_qbit) |
| def | add_R (self, target_qbit) |
| def | add_RX (self, target_qbit) |
| def | add_RXX (self, target_qbits, target_qbit2=-1) |
| def | add_RY (self, target_qbit) |
| def | add_RYY (self, target_qbits, target_qbit2=-1) |
| def | add_RZ (self, target_qbit) |
| def | add_RZZ (self, target_qbits, target_qbit2=-1) |
| def | add_S (self, target_qbit) |
| def | add_Sdg (self, target_qbit) |
| def | add_SWAP (self, target_qbits, target_qbit2=-1) |
| def | add_SX (self, target_qbit) |
| def | add_SXdg (self, target_qbit) |
| def | add_SYC (self, target_qbit, control_qbit) |
| def | add_T (self, target_qbit) |
| def | add_Tdg (self, target_qbit) |
| def | add_U1 (self, target_qbit) |
| def | add_U2 (self, target_qbit) |
| def | add_U3 (self, target_qbit) |
| def | add_X (self, target_qbit) |
| def | add_Y (self, target_qbit) |
| def | add_Z (self, target_qbit) |
| def | apply_derivate_to (self, parameters_mtx, unitary_mtx, parallel=1, is_f32=False) |
| def | apply_from_right (self, parameters_mtx, unitary_mtx, parallel=1, is_f32=False) |
| def | apply_to (self, parameters_mtx, unitary_mtx, parallel=1, is_f32=False) |
| def | apply_to_combined (self, parameters_mtx, unitary_mtx, parallel=1, is_f32=False) |
| def | apply_to_list (self, inputs, parameters_mtx, parallel=1, is_f32=False) |
| def | get_Children (self, gate) |
| def | get_Gate_Nums (self) |
| def | get_Gates (self) |
| def | get_Matrix (self, parameters_mtx, is_f32=False) |
| def | get_Parameter_Num (self) |
| def | get_Parameter_Start_Index (self) |
| def | get_Parents (self, gate) |
| def | get_Qbit_Num (self) |
| def | get_Qbits (self) |
| def | get_Second_Renyi_Entropy (self, parameters=None, input_state=None, qubit_list=None) |
| def | Remap_Qbits (self, qbit_map, qbit_num=None) |
| def | set_min_fusion (self, min_fusion) |
A QGD Python interface class for the Gates_Block.
Definition at line 70 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.__init__ | ( | self, | |
| qbit_num | |||
| ) |
Constructor of the class.
Args:
qbit_num: The number of qubits spanning the operations
Definition at line 73 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.add_adaptive | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add an adaptive gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 308 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.add_CCX | ( | self, | |
| target_qbit, | |||
| control_qbits | |||
| ) |
Add a CCX gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbits: Control qubits (list of int or tuple) - at least 2 control qubits required
Note:
control_qbits can be a list or tuple. Example:
- add_CCX(0, [1,2]) -> standard CCX with 2 controls
Definition at line 466 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CH | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CH gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 175 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_Circuit | ( | self, | |
| gate | |||
| ) |
Add a block of operations (subcircuit) to the front of the gate structure.
Args:
gate: A qgd_Circuit instance representing the subcircuit to add
Definition at line 490 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.add_CNOT | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CNOT gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 153 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CP | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CP gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 374 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CR | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CR gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 330 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CROT | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CROT gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 319 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CRX | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CRX gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 363 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CRY | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CRY gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 341 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CRZ | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CRZ gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 352 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CSWAP | ( | self, | |
| target_qbits, | |||
| control_qbits | |||
| ) |
Add a CSWAP (Fredkin) gate to the front of the gate structure.
Args:
target_qbits: Target qubits (list of int) - exactly 2 for standard CSWAP
control_qbits: Control qubit(s) (int or list of int) - exactly 1 for standard CSWAP
Note:
Accepts both list and single integer inputs for control_qbits. Examples:
- add_CSWAP([0,1], 2) -> control_qbits becomes [2] (standard Fredkin gate)
- add_CSWAP([0,1], [2]) -> control_qbits stays [2] (standard Fredkin gate)
Currently only supports exactly 1 control qubit (standard Fredkin gate).
Definition at line 437 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CU | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CU gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 186 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_CZ | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a CZ gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 164 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_Gate | ( | self, | |
| qgd_gate | |||
| ) |
Add a generic gate to the circuit.
Args:
qgd_gate: A gate object from the gates_Wrapper module
Raises:
Exception: If the gate type is not implemented
Definition at line 769 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_GENERAL | ( | self, | |
| operation_mtx, | |||
target_qbits = None, |
|||
control_qbits = None, |
|||
is_f32 = False |
|||
| ) |
Add a GENERAL_OPERATION gate from an explicit unitary matrix.
Args:
operation_mtx: Square operation matrix with shape (2**qbit_num, 2**qbit_num)
target_qbits: Optional list of target qubits used as metadata
control_qbits: Optional list of control qubits used as metadata
is_f32: If True, interpret operation_mtx as complex64
Definition at line 500 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.add_H | ( | self, | |
| target_qbit | |||
| ) |
Add a Hadamard gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 208 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_R | ( | self, | |
| target_qbit | |||
| ) |
Add a R gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 123 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_RX | ( | self, | |
| target_qbit | |||
| ) |
Add a RX gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 113 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_RXX | ( | self, | |
| target_qbits, | |||
target_qbit2 = -1 |
|||
| ) |
Add a RXX gate to the front of the gate structure.
Args:
target_qbits: List of target qubits (list of int) - at least 2 qubits required
target_qbit2: Optional second qubit if target_qbits is a single int
Definition at line 398 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_RY | ( | self, | |
| target_qbit | |||
| ) |
Add a RY gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 133 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_RYY | ( | self, | |
| target_qbits, | |||
target_qbit2 = -1 |
|||
| ) |
Add a RYY gate to the front of the gate structure.
Args:
target_qbits: List of target qubits (list of int) - at least 2 qubits required
target_qbit2: Optional second qubit if target_qbits is a single int
Definition at line 411 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_RZ | ( | self, | |
| target_qbit | |||
| ) |
Add a RZ gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 143 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_RZZ | ( | self, | |
| target_qbits, | |||
target_qbit2 = -1 |
|||
| ) |
Add a RZZ gate to the front of the gate structure.
Args:
target_qbits: List of target qubits (list of int) - at least 2 qubits required
target_qbit2: Optional second qubit if target_qbits is a single int
Definition at line 424 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_S | ( | self, | |
| target_qbit | |||
| ) |
Add a S gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 268 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_Sdg | ( | self, | |
| target_qbit | |||
| ) |
Add a Sdg gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 278 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_SWAP | ( | self, | |
| target_qbits, | |||
target_qbit2 = -1 |
|||
| ) |
Add a SWAP gate to the front of the gate structure.
Args:
target_qbits: List of target qubits (list of int) - at least 2 qubits required
target_qbit2: Optional second qubit if target_qbits is a single int
Definition at line 385 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_SX | ( | self, | |
| target_qbit | |||
| ) |
Add a SX gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 248 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_SXdg | ( | self, | |
| target_qbit | |||
| ) |
Add a SXdg gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 258 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_SYC | ( | self, | |
| target_qbit, | |||
| control_qbit | |||
| ) |
Add a SYC gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
control_qbit: Control qubit index (int)
Definition at line 197 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_T | ( | self, | |
| target_qbit | |||
| ) |
Add a T gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 288 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_Tdg | ( | self, | |
| target_qbit | |||
| ) |
Add a Tdg gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 298 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_U1 | ( | self, | |
| target_qbit | |||
| ) |
Add a U1 gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 83 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_U2 | ( | self, | |
| target_qbit | |||
| ) |
Add a U2 gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 93 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_U3 | ( | self, | |
| target_qbit | |||
| ) |
Add a U3 gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 103 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_X | ( | self, | |
| target_qbit | |||
| ) |
Add a X gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 218 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_Y | ( | self, | |
| target_qbit | |||
| ) |
Add a Y gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 228 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.add_Z | ( | self, | |
| target_qbit | |||
| ) |
Add a Z gate to the front of the gate structure.
Args:
target_qbit: Target qubit index (int)
Definition at line 238 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.apply_derivate_to | ( | self, | |
| parameters_mtx, | |||
| unitary_mtx, | |||
parallel = 1, |
|||
is_f32 = False |
|||
| ) |
Evaluate the derivative of the circuit on an input matrix w.r.t. all free parameters.
Args:
parameters_mtx: Parameter array (float64 or float32 when is_f32=True)
unitary_mtx: Input matrix (complex128 or complex64 when is_f32=True)
parallel: Parallel execution mode (int, optional, default=1)
is_f32: Use float32/complex64 precision (bool, optional, default=False)
Returns:
list of numpy arrays: One matrix per free parameter (complex128 or complex64 when is_f32=True)
Definition at line 583 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.apply_from_right | ( | self, | |
| parameters_mtx, | |||
| unitary_mtx, | |||
parallel = 1, |
|||
is_f32 = False |
|||
| ) |
Apply the gate circuit from the right on the input matrix.
Args:
parameters_mtx: Parameter array (numpy array) for parametric gates
unitary_mtx: Input matrix (numpy array) to be transformed
parallel: Parallel execution mode (int, optional, default=1)
is_f32: Use float32/complex64 precision (bool, optional, default=False)
Definition at line 559 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.apply_to | ( | self, | |
| parameters_mtx, | |||
| unitary_mtx, | |||
parallel = 1, |
|||
is_f32 = False |
|||
| ) |
Apply the gate circuit operation on the input matrix.
Args:
parameters_mtx: Parameter array (numpy array) for parametric gates
unitary_mtx: Input matrix (numpy array) to be transformed
parallel: Parallel execution mode (int, optional, default=1)
is_f32: Use float32/complex64 precision (bool, optional, default=False)
Definition at line 546 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.apply_to_combined | ( | self, | |
| parameters_mtx, | |||
| unitary_mtx, | |||
parallel = 1, |
|||
is_f32 = False |
|||
| ) |
Evaluate forward circuit action and all derivatives in one call.
Return format is a list where element 0 is the forward apply_to result,
and elements 1..N are derivatives w.r.t. each free parameter.
Args:
parameters_mtx: Parameter array (float64 or float32 when is_f32=True)
unitary_mtx: Input matrix (complex128 or complex64 when is_f32=True)
parallel: Parallel execution mode (int, optional, default=1)
is_f32: Use float32/complex64 precision (bool, optional, default=False)
Returns:
list of numpy arrays: [forward_output, derivative_0, derivative_1, ...]
Definition at line 597 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.apply_to_list | ( | self, | |
| inputs, | |||
| parameters_mtx, | |||
parallel = 1, |
|||
is_f32 = False |
|||
| ) |
Apply the circuit to a list of input matrices with float32/float64 dispatch.
Args:
inputs: List of numpy arrays to transform in-place (complex128 or complex64 when is_f32=True)
parameters_mtx: Parameter array (float64 or float32 when is_f32=True)
parallel: Parallel execution mode (int, optional, default=1)
is_f32: Use float32/complex64 precision (bool, optional, default=False)
Definition at line 572 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Children | ( | self, | |
| gate | |||
| ) |
Get the list of child gate indices.
The children gates can be obtained from the list of gates involved in the circuit.
Args:
gate: Gate index (int) for which to retrieve child gates
Returns:
list: List of child gate indices
Definition at line 754 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Gate_Nums | ( | self | ) |
Get statistics on the gate counts in the circuit.
Returns:
dict: Dictionary containing the gate type counts
Definition at line 700 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Gates | ( | self | ) |
Get the list of gates (or subcircuits) in the circuit.
Returns:
list: List of gate objects in the circuit
Definition at line 691 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Matrix | ( | self, | |
| parameters_mtx, | |||
is_f32 = False |
|||
| ) |
Retrieve the matrix representation of the circuit operation.
Args:
parameters_mtx: Parameter array (numpy array) for parametric gates
is_f32: If True, use float32 precision (default False)
Returns:
numpy.ndarray: The matrix representation of the circuit
Definition at line 517 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Parameter_Num | ( | self | ) |
Get the number of free parameters in the gate structure.
Returns:
int: The number of free parameters
Definition at line 536 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Parameter_Start_Index | ( | self | ) |
Get the starting index of the parameters in the parameter array.
The starting index corresponds to the circuit in which the current gate is incorporated.
Returns:
int: The starting index of parameters
Definition at line 727 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Parents | ( | self, | |
| gate | |||
| ) |
Get the list of parent gate indices.
The parent gates can be obtained from the list of gates involved in the circuit.
Args:
gate: Gate index (int) for which to retrieve parent gates
Returns:
list: List of parent gate indices
Definition at line 739 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Qbit_Num | ( | self | ) |
Get the number of qubits in the circuit.
Returns:
int: The number of qubits
Definition at line 664 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.get_Qbits | ( | self | ) |
Get the list of qubits involved in the circuit.
Returns:
list: List of qubit indices involved in the circuit
Definition at line 673 of file qgd_Circuit.py.
| def squander.gates.qgd_Circuit.qgd_Circuit.get_Second_Renyi_Entropy | ( | self, | |
parameters = None, |
|||
input_state = None, |
|||
qubit_list = None |
|||
| ) |
Calculate the second Rényi entropy of the quantum circuit.
Args:
parameters: Parameter array (float64 numpy array, optional)
input_state: Input quantum state (complex numpy array, optional). If None, |0> is created
qubit_list: Subset of qubits for which the Rényi entropy should be calculated (list, optional)
Returns:
float: The calculated second Rényi entropy
Definition at line 616 of file qgd_Circuit.py.


| def squander.gates.qgd_Circuit.qgd_Circuit.Remap_Qbits | ( | self, | |
| qbit_map, | |||
qbit_num = None |
|||
| ) |
Remap the qubits in the circuit.
Args:
qbit_map: Dictionary mapping initial qubit indices to remapped qubit indices
Format: {int(initial_qbit): int(remapped_qbit)}
qbit_num: Number of qubits in the remapped circuit (int, optional).
Can be different from the original circuit. If None, uses the original number
Returns:
qgd_Circuit: A newly created, remapped circuit instance
Definition at line 709 of file qgd_Circuit.py.

| def squander.gates.qgd_Circuit.qgd_Circuit.set_min_fusion | ( | self, | |
| min_fusion | |||
| ) |
Set the minimum fusion parameter in the circuit.
Args:
min_fusion: Minimum fusion value (int)
Definition at line 682 of file qgd_Circuit.py.
1.8.13