What are magic states?

What are magic states?

In quantum error correction codes like the surface code, Clifford gates like qml.CNOT, qml.Hadamard or qml.S are readily available. Non-Clifford gates, and, in particular, qml.T gates are not directly available, and instead need to be realized via magic state injection. This involves preparing a noisy magic state on an auxiliary qubit, which is refined using magic state distillation, and then injected into the circuit via teleportation. This makes non-Clifford operations typically the most expensive resource in fault tolerant quantum computing settings.

What are magic states?

There are different flavours of magic states, but in the context of fault tolerant quantum computing we typically encounter

$$ |H\rangle = \frac{1}{\sqrt{2}} \left(|0 \rangle + e^{i \frac{\pi}{4}} |1\rangle\right) = T |+\rangle. $$

This is exactly the state one would obtain from applying qml.T to the equal superposition state $|+\rangle = H |0\rangle = \frac{1}{\sqrt{2}} \left(|0 \rangle + |1\rangle\right)$. More generally, magic states are maximal non-stabilizer states of the Clifford group and provide the necessary resources to perform universal quantum computing in combination with Clifford operators (see, e.g., Fig. 3 of arXiv:1807.10296). Good resources for further reading on magic states are given by the original work by Bravyi and Kitaev in arXiv:quant-ph/0403025 and Reichardt arXiv:quant-ph/0608085.

What is magic state distillation?

Magic states such as $|H\rangle$ are typically used to implement the qml.T gate in quantum error correction codes. While it is not possible to apply qml.T gate in a fault tolerant way, we typically can prepare a noisy version $|H⚡\rangle$ of $|H\rangle$. This state can then be refined to be arbitrarily close to $|H\rangle$ using magic state distillation. This process is akin to amplitude amplification.

What is magic state injection?

Distilled magic states can be prepared on auxiliary qubits and used as a resource to execute a qml.T gate using magic state injection, which is similar to quantum teleportation. The protocol is relatively simple and given by the following circuit:

Magic state distillation protocol: main qubit initialized in some arbitrary state $|\psi\rangle$ and a resource magic state $|H\rangle$, prepared on an auxiliary qubit. The two qubit are entangled via a CNOT gate. To retrieve the correct state on the main wire, a S gate is applied depending on the measurement outcome on the auxiliary wire.

We have a qubit in an arbitrary state $|\psi\rangle = \alpha |0\rangle + \beta |1\rangle$ and an auxiliary qubit in a distilled magic state $|H\rangle = \frac{1}{\sqrt{2}} \left(|0 \rangle + e^{i \frac{\pi}{4}} |1\rangle\right)$. The joint initial state then reads

$$ \frac{1}{\sqrt{2}} \left(\alpha |00\rangle + \alpha e^{i \frac{\pi}{4}} |01\rangle + \beta |10\rangle + \beta e^{i \frac{\pi}{4}} |11\rangle \right). $$

We can entangle both qubits via a qml.CNOT(("main", "aux")) gate and obtain

$$ \frac{1}{\sqrt{2}} \left(\alpha |00\rangle + \alpha e^{i \frac{\pi}{4}} |01\rangle + \beta |11\rangle + \beta e^{i \frac{\pi}{4}} |10\rangle \right).$$

Note that qml.CNOT is a Clifford gate and, as such, can be typically performed in a fault-tolerant way. With some rearranging by sorting for the state on the "aux" qubit, we obtain

$$ \frac{1}{\sqrt{2}} \left(\alpha |0\rangle + \beta e^{i \frac{\pi}{4}} |1\rangle \right) |0\rangle + \frac{1}{\sqrt{2}} \left(\alpha e^{i \frac{\pi}{4}} |0\rangle + \beta |1\rangle \right) |1\rangle. $$

We then measure the auxiliary qubit. If we measure $|0\rangle$, we obtain $T|\psi\rangle |0\rangle,$ as desired. If we measure $|1\rangle$ on the auxiliary qubit, we obtain $\frac{1}{\sqrt{2}} \left(\alpha e^{i \frac{\pi}{4}} |0\rangle + \beta |1\rangle \right)$ on our main qubit. We can correct the relative phase by a factor of $\frac{\pi}{2}$ to retrieve the desired $T|\psi\rangle$ state. This can be achieved via a classically controlled qml.S on the outcome $1$. In this case, we obtain

$$ \left( \alpha e^{i \frac{\pi}{4}} |0\rangle + \beta e^{i \frac{\pi}{2}} |1\rangle \right) |1\rangle = e^{i \frac{\pi}{4}} T|\psi\rangle |1\rangle. $$

We can ignore the GlobalPhase of $e^{i \frac{\pi}{4}}.$ We see that, indeed, this protocol achieves the desired outcome of applying qml.T on the main qubit state $|\psi\rangle$.