qml.transforms.zx.todd

todd(tape)[source]

Apply the Third Order Duplicate and Destroy (TODD) algorithm to reduce the number of T gates in the given Clifford + T circuit.

This transform optimizes a Clifford + T circuit by cutting it into phase-polynomial blocks, and using the TODD algorithm to optimize each of these phase polynomials. Depending on the number of qubits and T gates in the original circuit, it might take a long time to run.

Note

The transformed output circuit is equivalent to the input up to a global phase.

The implementation is based on the pyzx.phase_block_optimize 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 Clifford + T circuit.

Example:

import pennylane as qml
import pennylane.transforms.zx as zx

dev = qml.device("default.qubit")

@zx.todd
@qml.qnode(dev)
def circuit():
    qml.T(0)
    qml.CNOT([0, 1])
    qml.S(0)
    qml.T(0)
    qml.T(1)
    qml.CNOT([0, 2])
    qml.T(1)
    return qml.state()
>>> print(qml.draw(circuit)())
0: ──S†─╭Z─╭●─╭●─┤  State
1: ──S──╰●─│──╰X─┤  State
2: ────────╰X────┤  State