combine_single_qubit_gates#
- combine_single_qubit_gates(qc: QuantumCircuit) QuantumCircuit[source]#
Combine adjacent single-qubit gates into unitary operations.
This pass scans the circuit instruction-by-instruction and accumulates consecutive single-qubit gates on each qubit. When an interruption is encountered (multi-qubit gate, allocation, measurement, …) the pending gates are flushed: their unitaries are multiplied together and emitted as a single operation, cancelling any sequences that reduce to the identity.
Recursive processing
Composite gates (gates with a
definition) are processed recursively so that single-qubit gate sequences inside compound operations are also combined.Controlled operations whose
base_operationcarries a definition are handled analogously: the base definition is combined in place and the controlled wrapper is preserved.This pass is designed as a local optimisation that reduces gate count and depth without changing the overall circuit semantics. It is especially useful after transpilation passes that may introduce redundant single-qubit rotations.
- Parameters:
- qcQuantumCircuit
The input circuit.
- Returns:
- QuantumCircuit
A new circuit with adjacent single-qubit gates combined.
Examples
>>> from qrisp import PassManager, combine_single_qubit_gates >>> from qrisp import QuantumCircuit >>> qc = QuantumCircuit(1) >>> qc.x(0) >>> qc.z(0) >>> qc.h(0) # X, Z, Y on the same qubit >>> pm = PassManager() >>> pm += combine_single_qubit_gates >>> optimized_qc = pm.run(qc) >>> # X, Z, Y combined into a single U3 gate >>> print(optimized_qc) ┌──────────────┐ qb_64: ┤ U3(π/2,3π,0) ├ └──────────────┘