bowtie_qgt.bowtie_circuits¶
Utility functions for Bowtie Quantum Geometric Tensor computations.
This module provides helper functions for computing parameter and observable bowtie circuits, which are essential for quantum geometric tensor calculations.
- bowtie_qgt.bowtie_circuits.parameter_bowtie(dag, target_parameter)[source]¶
Compute the auxiliary bowtie circuit for a given parameter.
The bowtie circuit is constructed by: 1. Finding the gate containing the target parameter 2. Computing the light cone of that gate 3. Sandwiching the generator of the rotation gate between the light cone
circuit and its inverse
- Parameters:
dag (
DAGCircuit) – The directed acyclic graph representation of the quantum circuit.target_parameter (
Parameter) – The parameter for which to compute the bowtie circuit.
- Return type:
- Returns:
The full parameter bowtie circuit, which may contain some idle quantum registers that can be removed using remove_idle_qwires.
- Raises:
ValueError – If the target parameter is not found in any gate in the circuit.
Example
>>> from qiskit import QuantumCircuit >>> from qiskit.circuit import Parameter >>> from qiskit.converters import circuit_to_dag >>> theta = Parameter('θ') >>> qc = QuantumCircuit(2) >>> qc.rx(theta, 0) >>> dag = circuit_to_dag(qc) >>> bowtie = parameter_bowtie(dag, theta)
- bowtie_qgt.bowtie_circuits.observable_bowtie(qc, bit_terms, indices)[source]¶
Compute the auxiliary bowtie circuit for a given observable.
The bowtie circuit is constructed by: 1. Computing the light cone of the observable 2. Sandwiching the Pauli gate corresponding to the observable between
the light cone circuit and its inverse
- Parameters:
qc (
QuantumCircuit) – The quantum circuit for which to compute the observable bowtie.bit_terms (
str) – Pauli string representing the observable terms (e.g., “XYZ” for X⊗Y⊗Z). The string is reversed internally to match Qiskit’s qubit ordering convention.indices (
list[int]) – List of qubit indices on which the Pauli terms act, ordered to correspond with the bit_terms string.
- Return type:
- Returns:
The full observable bowtie circuit, which may contain some idle quantum registers that can be removed using remove_idle_qwires.
Example
>>> from qiskit import QuantumCircuit >>> qc = QuantumCircuit(3) >>> qc.h(0) >>> qc.cx(0, 1) >>> bowtie = observable_bowtie(qc, "ZZ", [0, 1])
Note
TODO: Use DAG representation instead of circuit representation for consistency with parameter_bowtie.
- bowtie_qgt.bowtie_circuits.remove_idle_qwires(qc)[source]¶
Remove idle quantum wires from a circuit.
This function identifies and removes quantum wires (qubits) that have no operations applied to them throughout the circuit, returning a reduced circuit and the indices of the active wires.
- Parameters:
qc (
QuantumCircuit) – The quantum circuit from which to remove idle wires.- Returns:
The reduced quantum circuit with idle wires removed
A tuple of indices indicating which qubits from the original circuit remain in the reduced circuit (in order)
- Return type:
A tuple containing
Example
>>> from qiskit import QuantumCircuit >>> qc = QuantumCircuit(5) >>> qc.h(0) >>> qc.cx(0, 2) >>> reduced_qc, active_indices = remove_idle_qwires(qc) >>> print(f"Active qubits: {active_indices}") Active qubits: (0, 2) >>> print(f"Reduced circuit has {reduced_qc.num_qubits} qubits") Reduced circuit has 2 qubits
Circuit Manipulation Functions¶
parameter_bowtie¶
- bowtie_qgt.bowtie_circuits.parameter_bowtie(dag, target_parameter)[source]¶
Compute the auxiliary bowtie circuit for a given parameter.
The bowtie circuit is constructed by: 1. Finding the gate containing the target parameter 2. Computing the light cone of that gate 3. Sandwiching the generator of the rotation gate between the light cone
circuit and its inverse
- Parameters:
dag (
DAGCircuit) – The directed acyclic graph representation of the quantum circuit.target_parameter (
Parameter) – The parameter for which to compute the bowtie circuit.
- Return type:
- Returns:
The full parameter bowtie circuit, which may contain some idle quantum registers that can be removed using remove_idle_qwires.
- Raises:
ValueError – If the target parameter is not found in any gate in the circuit.
Example
>>> from qiskit import QuantumCircuit >>> from qiskit.circuit import Parameter >>> from qiskit.converters import circuit_to_dag >>> theta = Parameter('θ') >>> qc = QuantumCircuit(2) >>> qc.rx(theta, 0) >>> dag = circuit_to_dag(qc) >>> bowtie = parameter_bowtie(dag, theta)
observable_bowtie¶
- bowtie_qgt.bowtie_circuits.observable_bowtie(qc, bit_terms, indices)[source]¶
Compute the auxiliary bowtie circuit for a given observable.
The bowtie circuit is constructed by: 1. Computing the light cone of the observable 2. Sandwiching the Pauli gate corresponding to the observable between
the light cone circuit and its inverse
- Parameters:
qc (
QuantumCircuit) – The quantum circuit for which to compute the observable bowtie.bit_terms (
str) – Pauli string representing the observable terms (e.g., “XYZ” for X⊗Y⊗Z). The string is reversed internally to match Qiskit’s qubit ordering convention.indices (
list[int]) – List of qubit indices on which the Pauli terms act, ordered to correspond with the bit_terms string.
- Return type:
- Returns:
The full observable bowtie circuit, which may contain some idle quantum registers that can be removed using remove_idle_qwires.
Example
>>> from qiskit import QuantumCircuit >>> qc = QuantumCircuit(3) >>> qc.h(0) >>> qc.cx(0, 1) >>> bowtie = observable_bowtie(qc, "ZZ", [0, 1])
Note
TODO: Use DAG representation instead of circuit representation for consistency with parameter_bowtie.
remove_idle_qwires¶
- bowtie_qgt.bowtie_circuits.remove_idle_qwires(qc)[source]¶
Remove idle quantum wires from a circuit.
This function identifies and removes quantum wires (qubits) that have no operations applied to them throughout the circuit, returning a reduced circuit and the indices of the active wires.
- Parameters:
qc (
QuantumCircuit) – The quantum circuit from which to remove idle wires.- Returns:
The reduced quantum circuit with idle wires removed
A tuple of indices indicating which qubits from the original circuit remain in the reduced circuit (in order)
- Return type:
A tuple containing
Example
>>> from qiskit import QuantumCircuit >>> qc = QuantumCircuit(5) >>> qc.h(0) >>> qc.cx(0, 2) >>> reduced_qc, active_indices = remove_idle_qwires(qc) >>> print(f"Active qubits: {active_indices}") Active qubits: (0, 2) >>> print(f"Reduced circuit has {reduced_qc.num_qubits} qubits") Reduced circuit has 2 qubits
Internal Functions¶
- bowtie_qgt.bowtie_circuits._extend_lightcone(dag, light_cone, light_cone_ops)[source]¶
Extend the light cone backwards through the circuit.
This method takes an initial light cone at the end of the DAGCircuit and extends it backwards by identifying operations that do not commute with the light cone operations. Operations that commute are removed.
- Parameters:
- Return type:
- Returns:
The modified DAGCircuit with operations outside the light cone removed.
Note
This function modifies the input DAG in place and also returns it.