qml.transforms.zx.optimize_t_count

optimize_t_count(tape)[source]

Reduce the number of T gates in a Clifford + T circuit by using basic commutation and cancellation rules, combined with a dedicated phase-polynomial optimization strategy based on the Third Order Duplicate and Destroy (TODD) algorithm.

This transform applies a sequence of passes for T-count optimization to the given Clifford + T circuit. First, some ZX-based commutation and cancellation rules are applied to simplify the circuit. Then, the circuit is cut into phase-polynomial blocks and the TODD algorithm is used to optimize each of these phase polynomials. For circuits with many qubits and T gates, this transform may exhibit long run-times.

Note

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

The implementation is based on the pyzx.full_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.optimize_t_count
@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: ──Z─╭●────╭●─┤  State
1: ────╰X──S─│──┤  State
2: ──────────╰X─┤  State