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])], []) 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])], [])](/static/e152901ddc338b4e1bb4bcf9ee0e46f1/f058b/original_circuit.png)
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"]) Expanded circuit from (tape_expanded,) , _ = qml.compile(tape, basis_set=["T", "S", "Hadamard", "CNOT"])](/static/e70278a8e5c90e6fdb51dac22cfeb3d0/f058b/expanded_circuit.png)
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.
