mindquantum.algorithm.compiler.U3Fusion
- class mindquantum.algorithm.compiler.U3Fusion(rule_name='U3Fusion', log_level=0, with_global_phase=False)[source]
Fuse consecutive single qubit gates into one U3 gate.
This rule scans through the circuit and combines consecutive single qubit gates acting on the same qubit into a single U3 gate. For standalone single qubit gates, they will also be converted to U3 form.
Optionally, it can also track and include the global phase.
- Parameters
Examples
>>> from mindquantum.algorithm.compiler import U3Fusion, DAGCircuit >>> from mindquantum.core.circuit import Circuit >>> circ = Circuit().rx(1.0, 0).ry(0.5, 0).rz(0.7, 0) >>> circ ┏━━━━━━━┓ ┏━━━━━━━━━┓ ┏━━━━━━━━━┓ q0: ──┨ RX(1) ┠─┨ RY(1/2) ┠─┨ RZ(0.7) ┠─── ┗━━━━━━━┛ ┗━━━━━━━━━┛ ┗━━━━━━━━━┛ >>> dag_circ = DAGCircuit(circ) >>> compiler = U3Fusion() >>> compiler.do(dag_circ) >>> dag_circ.to_circuit() ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ q0: ──┨ U3(θ=1.0768, φ=-0.5722, λ=0.995) ┠─── ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
- do(dag_circuit: DAGCircuit)[source]
Apply single qubit gate fusion to the circuit.
- Parameters
dag_circuit (DAGCircuit) – Input circuit in DAG form
- Returns
True if any fusion was performed, False otherwise
- Return type