# How does a quantum computer do basic math at the hardware level?

On reading this Reddit thread I realized that even after a couple months of learning about quantum computing I've absolutely no clue about how a quantum computer actually works.

To make the question more precise, let's say we have a superconducting qubit based 5-qubit quantum computer (like the 5-qubit IBM Quantum Computer). I type in $2+3$ using a keyboard onto a monitor (say in a basic calculator app the quantum computer might have). After that it should return me $5$. But is going on at the hardware level? Are some sort of electrical signals corresponding to the inputs $2$,$3$ and $+$ going to the processing unit of the computer? Does that somehow "initialize" the Cooper pair electrons? What happens to the Cooper pair electron qubits after that (guess they'd be worked on by some quantum-gates, which are in turn again black boxes)? How does it finally return me the output $5$ ?

I am surprised as to how little I could come up with about the basic working of a quantum computer by searching on the net.

• Hmm, perhaps useful to know is that it might not even be needed to have such primitives for current quantum algorithms. It might even be the case that the 'classical component' does all the work. – Discrete lizard Mar 24 '18 at 8:08
• What makes this different from the question "How are quantum gates realised, in terms of the dynamic?"? Are you asking about initialisation and readout as well? Or are you asking about the specific gates required to perform the operation '2+3'? – Mithrandir24601 Mar 24 '18 at 13:09
• @Mithrandir24601 Even before application of gates, it is not clear how the qubits are initialized. And how exactly the addition operation is performed with the gates. What happens to the Cooper pair electrons. – Blue Mar 24 '18 at 13:12
• @Rob I specifically mentioned that if there are many ways I'd be happy with the discussion of just one. That is how say a superconducting quantum computer like the IBM 5 quit one, works at the hardware level. – Blue Mar 24 '18 at 16:43

Firstly, a classical computer does basic maths at the hardware level in the arithmetic and logic unit (ALU). The logic gates take low and high input voltages and uses CMOS to implement logic gates allowing for individual gates to be performed and built up to perform larger, more complicated operations. In this sense, typing on a keyboard is sending electrical signals, which eventually ends up in a command (in the form of more electrical signals) being sent to the ALU, the correct operations being performed and more signals sent back, which gets converted to display pixels in the shape of a number on your screen.

## What about a quantum computer?

There are two possible ways that quantum processors get used: by themselves, or in conjunction with a classical processor. However, most (including your example of superconducting) quantum processors don't actually use electrical signals, although this is still how your mouse, keyboard and monitor etc. transmit and receive information. So, there needs to be a way to convert the electric signal to whatever signal the quantum processor uses (which I'll get on to later), as well as some way of telling the processor what you want to do. Both these issues can be solved at once by classical pre- and post- processing, such as in IBM's QISKit. Microsoft is taking a bit more of a top-down approach in Q#, where programs for a quantum processor is written more like a 'classical' program, as opposed to a script, then compiled and potentially optimised for the hardware. That is, if you've got a function, it can perform classical operations, as well as make calls to the quantum processor to perform any required quantum operations. This leads me to the first point:

If you're going to ask a computer with access to a quantum processor to calculate something such as $2+3$, one very valid solution would be to just compute it on the classical processor as per usual.

OK, let's say that you're forcing the classical processor to use the quantum processor, which in this case is one of IBM's superconducting chips, using transmon qubits, let's say, the IBM QX4. This is too small to have error correction, so let's ignore that. There are three parts to using a circuit model processor: initialisation, unitary evolution and measurement, which are explained in more detail below. Before that,

## What is a transmon?

Take a superconducting loop to allow for Cooper pairs and add one or two Josephson junctions to give a Cooper pair box island in the region between the two Josephson junctions with Josephson coupling energy $E_J = I_c\Phi_0/2\pi$, where the magnetic flux quantum $\Phi_0 = h/2e$ and $I_c$ is the critical current of the junction. Applying a voltage $V_g$ to this box gives a 'gate capacitance' $C_g$ and makes this a charge qubit. For the Coulomb energy of a single Cooper pair $E_C = \left(2e\right)^2/2C$, where $C$ is the sum of the total capacitance of the island. The Hamiltonian of such a system is given by $$H = E_C\left(n - n_g\right)^2 - E_J\cos\phi,$$ where $n$ is the number of Cooper pairs, $\phi$ is the phase change across the junction and $n_g = C_gV_g/2e$. When performing unitary operations, only the two lowest states of the system are considered, $\left|n\right\rangle = \left|0\right\rangle$ and $\left|n\right\rangle = \left|1\right\rangle$ with respective energies $E_0 =\hbar\omega_0$ and $E_1 = \hbar\omega_1$ and qubit frequency $\omega = \omega_1-\omega_0$, describing the computational basis of a qubit. A typical charge qubit could have $E_C = 5E_J$. Adding a large shunting capacitance and increasing the gate capacitance switches this ratio, so that $E_J\gg E_C$ and we have a transmon. This has the advantage of longer coherence times, at a cost of reduced anharmonicity (where energy levels beyond the first two are closer together, potentially causing leakage).

Finally, we get to the main question:

## How do we initialise, evolve and measure a transmon?

• Single qubit unitary evolution: Applying a microwave pulse $\mathcal E\left(t\right) = \mathcal E_x\left(t\right)\cos\left(\omega_dt\right) + \mathcal E_y\left(t\right)\sin\left(\omega_dt\right)$ for $0<t<t_g$ of frequency $\omega_d$ and making the rotating wave approximation gives the Hamiltonian of the qubit states (in the ideal case) as $$H =\hbar \begin{pmatrix}\omega_1-\omega_d && \frac 12\mathcal E_x\left(t\right) - \frac i2\mathcal E_y\left(t\right)\\ \frac 12\mathcal E_x\left(t\right) + \frac i2\mathcal E_y\left(t\right) && \omega_2-2\omega_d\end{pmatrix}$$ However, due to lower anharmonicity, the microwave pulses have to be shaped to reduce leakage to higher energy levels in a process known as Derivative Removal by Adiabatic Gate (DRAG). By varying the pulse, different Hamiltonians can be achieved, which, depending on the time of the pulse can be used to implement different unitary operations on a single qubit.
• Measurement/readout: A microwave resonator, with resonance frequency $\omega_r$, can be coupled to the transmon using a capacitor. This interaction causes (decaying) Rabi oscillations to occur in the transmon-resonator system. When the coupling strength of cavity and qubit, $g \ll \omega-\omega_r$, this is known as the dispersive regime. In this regime, the transmittance spectrum of the cavity is shifted by $\pm g^2/\left(\omega-\omega_r\right)$ depending on the state of the qubit, so applying a microwave pulse and analysing the transmittance and reflectance (by computer) can then be used to measure the qubit.
• Multiple qubit unitary evolution: This idea of coupling a qubit to a microwave resonator can be extended by coupling the resonator to another qubit. As in the single qubit gate case, timings of the coupling as well as microwave pulses can be used allow the first qubit to couple to the cavity, which is then coupled to the second qubit and perform certain 2-qubit gates. Higher energy levels can also be used to make certain gates easier to implement due to interactions between higher levels caused by the cavity. One such example is shown here, where the cavity causes an interaction between the states of $\left|2\right>\left|0\right>$ and $\left|1\right>\left|1\right>$. An avoided crossing between these states means that a 2-qubit phase gate can be implemented, although in general 2-qubit gates are implemented less well (have a lower fidelity) than single qubit ones.
• Initialisation: Readout, potentially followed by a single qubit Pauli $X$ gate (on each qubit measured to be in state $\left|1\right\rangle$) to ensure that all qubits start in state $\left|0\right\rangle$.

Adding 2 and 3 is now a 'simple' matter of initialising the qubits, performing the gates equivalent to a classical reversible adder and measuring the result, all implemented automatically. The measurement result is then returned by a classical computer as per usual.

As a bonus, it seems a little pointless to go through all that in order to implement gates that could be done on a classical computer anyway, so it turns out that it's possible to approximately implement a quantum adder, which adds two quantum (as opposed to classical) states, with some error, on one of IBM's processors.

• Its not pointless, since for example, if you wanted to perform Grover search on a function, you can't compute the function classically – sunny-lan Jun 29 '18 at 22:18
• Though I fully understand the question the answer seems like a different language to me. Cooper pairs, Josephson junctions, box island, magnetic flux, critical current. It looks like I never studied physics at all. – keiv.fly Oct 6 '18 at 13:28

Here is my process for doing arithmetic on a quantum computer.

Step 1: Find a classical circuit that does the thing you're interested in.

In this example, a full adder.

Step 2: Convert each classical gate into a reversible gate.

Have your output bits present from the start, and initialize them with CNOTs, CCNOTs, etc.

Step 3: Use temporary outputs.

If you were doing this addition to e.g. control whether a Grover oracle phases by -1 or not, now is the time to apply a Z gate to your output qubit.

Step 4: Get rid of intermediate values by doing exactly the opposite of what you did to compute them.

This may or may not include getting rid of the output bits, depending on how the circuit fits into your overall algorithm.

Step 5: (Sometimes) for each output bit you keep, get rid of an input bit.

And I don't mean "drop them on the floor", I mean apply operations that cause them to become 0 for sure.

When you compute c+=a, leaving behind a copy of the original value of c tends to be bad. It destroys coherence. So you must look at your adder circuit (or whatever), and think hard about if there's a way to use your output bits to get rid of your input bits. For example, after computing c+a you could do a temporary out-of-place subtraction into a register r, xor r into the register storing the unwanted copy of c, then revert the temporary subtraction.

(A notable exception to "if you keep your output, don't keep so much of your input" is Shor's algorithm. Shor's algorithm decoheres its input on purpose, but in a very particular way that helps with period finding.)

Step 6: Be efficient

In step 5 I said you could uncompute the input of an inplace addition by doing an out of place addition followed by a temporary out-of-place subtraction. This is a bit silly. The overall adding process is going to span 4n qubits (n to hold a, n to hold c, n to hold c+a, n to hold (c+a)-a). If you are more clever, you can fit everything into 2n qubits or (slightly easier) into 2n+1 qubits: