What is Quantum Compilation?

What is Quantum Compilation?

Quantum compilation is the process of transforming quantum programs. The main goal is to translate a higher-level program description to a set of low-level instructions that a quantum device can execute. This shall be done in such a way that quantum resources like circuit depth or the number of certain types of gates are optimized.

Example

Consider the following quantum circuit containing T, Hadamard, CNOT and Toffoli gates.

Quantum tape constructed from tape = qml.tape.QuantumScript([qml.Hadamard(0), qml.Hadamard(1), qml.Hadamard(2), qml.CNOT((0, 1)), qml.CNOT((1, 2)), qml.T(0), qml.T(1), qml.T(2), qml.Toffoli([0, 1, 2])], [])

We may compile this circuit to a different basis gate set to the Clifford + T gate set, i.e. containing only S, T, Hadamard and CNOT.

Expanded circuit from (tape_expanded,) , _ = qml.compile(tape, basis_set=["T", "S", "Hadamard", "CNOT"])

There are some optimizations we can perform by hand, e.g. T gates commute through the control wires of CNOT gates, and $T^2 = S$. We could thereby remove two T gates, which are often considered expensive in fault tolerant settings (see e.g. this blog post on T gate optimization). There are more elaborate passes yielding, for example, the following circuit with significantly lower T-gate count.

Optimized circuit with very different structure