qml.labs.zxopt.full_reduce¶
- full_reduce(tape)[source]¶
ZX-based T gate reduction on an arbitrary PennyLane circuit.
This implements the full pipeline for T gate optimizations in pyzx.
This pipeline performs, in that order
In particular, this pipeline does not apply
todd()
and thus is not restricted to (Clifford + T) circuits. The latter two functions are simply to retrieve the circuit from the ZX graph.- Parameters:
tape (QNode or QuantumTape or Callable) – Input PennyLane circuit.
- Returns:
T gate optimized PennyLane circuit. See
qml.transform
for the different output formats depending on the input type.- Return type:
qnode (QNode) or quantum function (Callable) or tuple[List[QuantumTape], function]
See also
Example
Let us optimize a circuit with
T
as well asRZ
gates.from pennylane.labs.zxopt import full_reduce circ = qml.tape.QuantumScript([ qml.CNOT((0, 1)), qml.T(0), qml.CNOT((3, 2)), qml.T(1), qml.CNOT((1, 2)), qml.T(2), qml.RZ(0.5, 1), qml.CNOT((1, 2)), qml.T(1), qml.CNOT((3, 2)), qml.T(0), qml.CNOT((0, 1)), ], []) print(f"Circuit before:") print(qml.drawer.tape_text(circ, wire_order=range(4))) (new_circ,), _ = full_reduce(circ) print(f"Circuit after full_reduce:") print(qml.drawer.tape_text(new_circ, wire_order=range(4)))
Circuit before: 0: ─╭●──T──T───────────╭●─┤ 1: ─╰X──T─╭●──RZ─╭●──T─╰X─┤ 2: ─╭X────╰X──T──╰X─╭X────┤ 3: ─╰●──────────────╰●────┤ Circuit after full_reduce: 0: ──S─╭●──────────────╭●─┤ 1: ────╰X──RZ─╭●────╭●─╰X─┤ 2: ─╭●────────│─────│──╭●─┤ 3: ─╰X────────╰X──T─╰X─╰X─┤
The original circuit has five
T
gates which are reduced to just one.