qml.transforms.zx.push_hadamards¶
- push_hadamards(tape)[source]¶
Push Hadamard gates as far as possible to one side to cancel them and create fewer larger phase-polynomial blocks, improving the effectiveness of phase-polynomial optimization techniques.
This transform optimizes circuits composed of phase-polynomial blocks and Hadamard gates. This strategy works by commuting Hadamard gates through the circuit. To preserve the overall unitary, this process relies on commutation rules that can transform the gates a Hadamard moves past. For instance, pushing a Hadamard through a CNOT gate will convert the latter into a CZ gate. Consequently, the final optimized circuit may have, in some cases, a significantly different internal gate structure.
The transform also applies some basic simplification rules to phase-polynomial blocks themselves to merge phase gates together when possible (e.g. T^4 = S^2 = Z).
The implementation is based on the pyzx.basic_optimization pass.
- Parameters:
tape (QNode or QuantumScript or Callable) – the input circuit to be transformed.
- Returns:
the transformed circuit as described in
qml.transform
.- Return type:
qnode (QNode) or quantum function (Callable) or tuple[List[QuantumScript], function]
- Raises:
ModuleNotFoundError – if the required
pyzx
package is not installed.TypeError – if the input quantum circuit is not a phase-polynomial + Hadamard circuit.
Example:
import pennylane as qml import pennylane.transforms.zx as zx dev = qml.device("default.qubit") @zx.push_hadamards @qml.qnode(dev) def circuit(): qml.T(0) qml.Hadamard(0) qml.Hadamard(0) qml.T(1) qml.Hadamard(1) qml.CNOT([1, 2]) qml.Hadamard(1) qml.Hadamard(2) return qml.state()
>>> print(qml.draw(circuit)()) 0: ──T────┤ State 1: ──T─╭X─┤ State 2: ──H─╰●─┤ State