Writing a song “is an act of self-murder”: Nick Cave on ChatGPT

The best part of Nick Cave’s critique of ChatGPT is, IMHO, the following:

“Songs arise out of suffering, by which I mean they are predicated upon the complex, internal human struggle of creation and, well, as far as I know, algorithms don’t feel.”

A close second:

“Writing a good song is not mimicry, or replication, or pastiche, it is the opposite. It is an act of self-murder that destroys all one has strived to produce in the past.”

Visualising qubits on the Bloch sphere

This post brings together visualisations and sums that I found really helpful for getting to grips with the Bloch sphere representation of qubit states.

Recap

The state of a qubit is represented by the linear combination

\(\displaystyle \alpha |0\rangle + \beta |1\rangle\)

for complex amplitudes \(\alpha, \beta \in \mathbb{C}\). The amplitudes satisfy \(|\alpha|^2 + |\beta|^2 = 1\), where

\(\displaystyle |x  + yi| = \sqrt{x^2 + y^2}\),

the modulus of a complex number.

The probability of measuring (using the classical basis) a 0 is \(|\alpha|^2\) and of measuring a 1 is \(|\beta|^2\), by the Born rule.

Distinct states can imply the same measurement probabilities:

Example 1. The amplitudes in the following state are defined without any imaginary component:

\(\displaystyle \sqrt{\frac{1}{2}} |0\rangle + \sqrt{\frac{1}{2}} |1\rangle\).

Apply the Born rule and the probability of both measurement outcomes is \(\frac{1}{2}\).

Example 2. The following example has an imaginary component in both amplitudes:

\(\displaystyle \frac{1}{2}(1 + i) |0\rangle + \frac{1}{2}(1 + i) |1\rangle\).

The modulus of both amplitudes is \(\sqrt{(\frac{1}{2})^2 + (\frac{1}{2})^2} = \sqrt{\frac{1}{2}}\). So the probability of obtaining either a 0 or a 1 is again \(\frac{1}{2}\).

Bloch sphere

The state of a qubit can be represented as a point on the surface of sphere, known as the Bloch sphere. To make sense of this representation, let’s look at a couple of animations, GIFed from the QuVis visualisation project at the University of St Andrews.

Firstly, consider the following circle sliding down and up the sphere (you could think of this as travelling along the sphere’s latitudes):

The first thing to note is that the north (top) and south (bottom) pole of the sphere are where the pure \(|0\rangle\) and \(|1\rangle\) states live, respectively.

The location of the circle determines the probability of a particular measurement outcome. If the circle is at the north pole, then the probability of measuring a 0 is 1. If it’s at the south pole, then the probability of measuring a 1 is 1. At the equator, there’s a 50-50 chance of a 0 or a 1. All points on the circle at any given latitude represent states with the same measurement probabilities. Each latitude circle denotes what is called a magnitude.

Now let’s stop in the middle latitude. We can also rotate around the sphere (think of this as travelling along different longitudes):

These circles represent different relative phases of the state. Phases cannot be directly detected by measurement using the classical computational basis; however, there are methods to see what the phase is and phases are important in quantum algorithms.

Here’s a still of the sphere:

The angle \(\theta\) indexes the longitudes (moving north or south) and \(\phi\) indexes the longitudes (sweeping east or west).

The state of a qubit can be written in terms of these two parameters as follows:

\(\displaystyle \cos\frac{\theta}{2} |0\rangle + e^{i \phi} \sin\frac{\theta}{2} |1\rangle\).

Let’s fix \(\phi = 0\), so \(e^{i \phi} = 1\) and the equation above simplifies to:

\(\displaystyle \cos\frac{\theta}{2} |0\rangle + \sin\frac{\theta}{2} |1\rangle\).

The full sweep from north pole to south pole is \(180^{\circ}\) or \(\pi\) radians. Let’s try north pole (\(\theta = 0\)), equator (\(\theta = \frac{\pi}{2}\)), and south pole (\(\theta = \pi\)).

\(\theta\) \(\displaystyle \alpha = \cos\frac{\theta}{2}\) \(\displaystyle \beta = \sin\frac{\theta}{2}\) State
\(\displaystyle 0\) \(1\) \(0\) \(\displaystyle |0\rangle\)
\(\displaystyle \frac{\pi}{2}\) \(\displaystyle \sqrt{\frac{1}{2}}\) \(\displaystyle \sqrt{\frac{1}{2}}\) \(\displaystyle \frac{|0\rangle + |1\rangle}{\sqrt{2}}\)
\(\displaystyle \pi\) \(0\) \(1\) \(\displaystyle |1\rangle\)

Now what effect does the phase have? Fix \(\theta = \frac{\pi}{2}\), so the measurement probabilities are constant. A \(360^{\circ}\) turn is equal to \(2\pi\) radians. We shall try \(\phi = 0, \frac{\pi}{2}, \pi, \frac{3\pi}{2}\). This time I’m using Grokking the Bloch Sphere to visualise.

Bloch sphere \(\phi\) \(\displaystyle \alpha = \cos\frac{\theta}{2}\) \(\displaystyle \beta = e^{i \phi} \sin\frac{\theta}{2}\)
\(\displaystyle 0\) \(\displaystyle \frac{1}{\sqrt{2}}\) \(\displaystyle \frac{1}{\sqrt{2}}\)
 \(\displaystyle \frac{\pi}{2}\) \(\displaystyle \frac{1}{\sqrt{2}}\) \(\displaystyle \frac{i}{\sqrt{2}}\)
 \(\displaystyle \pi\) \(\displaystyle \frac{1}{\sqrt{2}}\) \(\displaystyle -\frac{1}{\sqrt{2}}\)
 \(\displaystyle \frac{3\pi}{2}\) \(\displaystyle \frac{1}{\sqrt{2}}\) \(\displaystyle –\frac{i}{\sqrt{2}}\)

Note how the \(\beta\) amplitudes come in pairs, one positive, one negative. The sign flips when spinning half a circle.

Simple examples of bras and kets

Animated interpretation of the Matrix’s digital rain, by Jahobr

Quantum computing involves lots of matrix multiplication. After seeing definitions, sometimes you just need a few simple examples.

Here’s a matrix:

\(\begin{pmatrix}
3 & 1 & 4\\
1 & 5 & 9\\
2 & 6 & 5
\end{pmatrix}\)

We can pull out the second row by multiplying as follows:

\(\begin{pmatrix}
0 & 1 & 0
\end{pmatrix}\begin{pmatrix}
3 & 1 & 4\\
1 & 5 & 9\\
2 & 6 & 5
\end{pmatrix} = \begin{pmatrix}
1 & 5 & 9
\end{pmatrix}\)

And the third row:

\(\begin{pmatrix}
0 & 0 & 1
\end{pmatrix}\begin{pmatrix}
3 & 1 & 4\\
1 & 5 & 9\\
2 & 6 & 5
\end{pmatrix} = \begin{pmatrix}
2 & 6 & 5
\end{pmatrix}\)

Or the second column:

\(\begin{pmatrix}
3 & 1 & 4\\
1 & 5 & 9\\
2 & 6 & 5
\end{pmatrix} \begin{pmatrix}
0 \\
1 \\
0
\end{pmatrix} = \begin{pmatrix}
1 \\
5 \\
6
\end{pmatrix}\)

Here’s the middle element:

\(\begin{pmatrix}
0 & 1 & 0
\end{pmatrix}\begin{pmatrix}
3 & 1 & 4\\
1 & 5 & 9\\
2 & 6 & 5
\end{pmatrix} \begin{pmatrix}
0 \\
1 \\
0
\end{pmatrix} = 5\)

And the top-left element:

\(\begin{pmatrix}
1 & 0 & 0
\end{pmatrix}\begin{pmatrix}
3 & 1 & 4\\
1 & 5 & 9\\
2 & 6 & 5
\end{pmatrix} \begin{pmatrix}
1 \\
0 \\
0
\end{pmatrix} = 3\)

Bra-kets

Again, this time using Dirac notation.

Let \(M= \begin{pmatrix}
3 & 1 & 4\\
1 & 5 & 9\\
2 & 6 & 5
\end{pmatrix}\)

And define the following kets:

\(|e_o\rangle = \begin{pmatrix}
1\\
0\\
0
\end{pmatrix}\)

\(|e_1\rangle = \begin{pmatrix}
0\\
1\\
0
\end{pmatrix}\)

\(|e_2\rangle = \begin{pmatrix}
0\\
0\\
1
\end{pmatrix}\)

This means we get the following bras (yes, they are really called that):

\(\langle e_o | = \begin{pmatrix}
1 &
0 &
0
\end{pmatrix}\)

\(\langle e_1 | = \begin{pmatrix}
0 &
1 &
0
\end{pmatrix}\)

\(\langle e_2 | = \begin{pmatrix}
0 &
0 &
1
\end{pmatrix}\)

We can pull out the second row of \(M\) like so:

\(\langle e_1 | M = \begin{pmatrix}1 & 5 & 9\end{pmatrix}\)

And the third row:

\(\langle e_2 | M = \begin{pmatrix}2 & 6 & 5\end{pmatrix}\)

Or the second column:

\(M |e_1\rangle = \begin{pmatrix}
1 \\
5 \\
6
\end{pmatrix}\)

Here’s the middle element:

\(\langle e_1 | M | e_1 \rangle = 5\)

And the top-left:

\(\langle e_0 | M | e_0 \rangle = 3\)

To get the \(6\), do:

\(\langle e_2 | M | e_1 \rangle = 6\)

 

Measurement in quantum computing

This post explores what happens when you measure one entangled qubit in a part-entangled three-qubit system. The sums turn out to be straightforward once you get over the weird Dirac notation.

It’s easy to think about measurement for a single qubit. Suppose the qubit is in the following superposition:

\(\displaystyle \alpha |0\rangle + \beta|1\rangle\).

If we measure it, then by the Born rule

\(\displaystyle P(|0\rangle) = |\alpha|^2\) and

\(\displaystyle P(|1\rangle) = |\beta|^2\),

where \(|z|\) is the modulus of \(z\).

For example, if

\(\displaystyle |\psi\rangle = \sqrt{0.2} |0\rangle + \sqrt{0.8}|1\rangle\),

then

\(\displaystyle P(|0\rangle) = |\sqrt{0.2}|^2 = 0.2\) and

\(\displaystyle P(|1\rangle) = |\sqrt{0.8}|^2 = 0.8\).

Following measurement, the qubit’s posterior state, \(|\psi’\rangle\), collapses to whatever the measurement outcome was, so \(|\psi’\rangle = |0\rangle\) or \(|\psi’\rangle = |1\rangle\).

We can measure one qubit in a system of two or more qubits, but now things are more complex. If the qubit we measure is entangled with others, then their superpositions collapse too. Any qubits that are unentangled with the one being measured should survive measurement unscathed.

Quantum mechanics gives us predictions for systems of any number of qubits and configurations (see Matuschak and Nielsen, 2020, postulate 3). Let’s see what happens when we apply it to the following three qubit system:

\(\displaystyle |\psi\rangle = \frac{|000\rangle + |011\rangle + |100\rangle + |111\rangle}{2}\)

Numbering the qubits right to left, the first two (call them \(q[0]\) and \(q[1]\)) are entangled, the third, \(q[2]\), is unentangled with the first two. We are going to measure \(q[0]\).

We need a set of measurement operators. For a single qubit in the classical measurement basis these are \(|0\rangle\langle 0|\) and \(|1\rangle\langle 1|\). To parse this Dirac notation, note that \(\langle \phi |^\dagger = |\phi \rangle\) and \(|\phi \rangle^\dagger = \langle \phi |\), where \(M^\dagger\) is the conjugate transpose of \(M\); i.e., transpose a row vector to a column vector, or vice versa, and take the complex conjugate of each element.

So

\(\displaystyle |0\rangle\langle 0| = \begin{pmatrix} 1\\ 0 \end{pmatrix} \begin{pmatrix} 1 & 0 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & 0 \end{pmatrix}\)

\(\displaystyle |1\rangle\langle 1| = \begin{pmatrix} 0\\ 1 \end{pmatrix} \begin{pmatrix} 0 & 1 \end{pmatrix} = \begin{pmatrix} 0 & 0 \\ 0 & 1 \end{pmatrix}\)

We have three qubits, so we need to pad out these measurement operators with the identity matrix to give

\(M_{q[0] = 0} = I \otimes I \otimes  |0\rangle\langle 0|\)

\(M_{q[0] = 1} = I \otimes I \otimes  |1\rangle\langle 1|\)

where

\(\displaystyle I = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\)

and \(\otimes\) is the tensor product. This is exactly what we did previously when applying one qubit gates to systems of more than one qubit.

The probability that the measurement outcome for the first qubit is \(1\) is

\(\displaystyle P(q[0] = 1)  =  \langle \psi | M_{q[0] = 1}^\dagger  M_{q[0] = 1} |\psi\rangle = \frac{1}{2}\).

Suppose \(q[0] = 1\) is indeed the measurement outcome. What’s left of the system state (the posterior state), call it \(|\psi’\rangle\)?

\(\displaystyle |\psi’\rangle= \frac{M_{q[0] = 1} | \psi \rangle}{\sqrt{P(q[0] = 1)}} = \frac{\frac{1}{2}(|011\rangle + |111\rangle)}{\sqrt{\frac{1}{2}}} = \frac{|011\rangle + |111\rangle}{\sqrt{2}}\)

So, the first two qubits have collapsed to the same state, \(|1\rangle\). The third is still in superposition (it would be \(|0\rangle\) or \(|1\rangle\) if we measured it). The arithmetic works!

Maybe it’s easier to see what’s going on if we write \(|\psi’\rangle\) as

\(\displaystyle \frac{|011\rangle + |111\rangle}{\sqrt{2}} = \sqrt{0.5}|0{\underline{11}}\rangle + \sqrt{0.5}|1{\underline{11}}\rangle\).

The previously entangled qubits are now underlined. There’s a 50-50 chance that measuring again would give \(q[2]  = 1\) and a 100% chance that \(q[0] = q[1]  = 1\).

Similarly, the probability that \(q[0] = 0\)  is

\(\displaystyle P(q[0] = 0)  =  \langle \psi | M_{q[0] = 0}^\dagger  M_{q[0] = 0} |\psi\rangle = \frac{1}{2}\).

If this is the actual measurement outcome, then the posterior state is

\(\displaystyle |\psi’\rangle= \frac{M_{q[0] = 0} | \psi \rangle}{\sqrt{P(q[0] = 0)}} = \frac{\frac{1}{2}(|000\rangle + |011\rangle)}{\sqrt{\frac{1}{2}}} = \frac{|000\rangle + |100\rangle}{\sqrt{2}}\)

Again, the first two qubits have collapsed to the same state, this time \(|0\rangle\). The third is still in superposition.

Praxis

That’s the sums. Let’s see what happens when we run this on one of IBM Quantum’s computers. The circuit that establishes the state above and measures \(q[0]\), \(q[1]\), and \(q[2]\) (in that order) is as follows:

The OpenQASM code (auto generated) is:

OPENQASM 2.0;
include "qelib1.inc"

qreg q[3];
creg c[3];

reset q[0];
reset q[1];
reset q[2];
h q[0];
h q[2];
cx q[0], q[1];
measure q[0] -> c[0];
measure q[1] -> c[1];
measure q[2] -> c[2];

Results following 1,000 runs on ibmq_lima (a Falcon r4T):

Outcomes matched predictions for entanglement (\(q[0] = q[1]\)) on 92.3% of runs. Of these, 48.3% were both 1s (versus both 0s), 95% CI = [45.0, 51.6], which is compatible with the 50-50 split we would expect. However, \(q[2] = 1\) on 42% of those entangled trials, which is statistically significantly lower than the predicted 50% (95% CI = [39.1, 45.5]).

Second time lucky, in case that was a fluke:

The bar chart looks a little more symmetrical. This time on correctly entangled runs, \(q[2] = 1\) across 47.5% of those runs. This wasn’t statistically significantly different to 50% (95% CI = [44.3, 50.8]) so it’s compatible with what we expect. But maybe this series of runs was a fluke…?

Another time, with 10,000 runs: \(q[2] = 1\) across 46.2% of correctly entangled runs (95% CI = [45.2, 47.3]). So it seems possible there is some bias on ibmq_lima.

I tried again on another computer: ibm_oslo (a Falcon r5.11H). Now with 20,000 runs – the maximum allowed in one booking. The outcomes for \(q[0]\) and \(q[1]\) were the same (i.e., as predicted) on 93.9% of runs. Of those, \(q[2] = 1\) on 50.1% of runs and this was not statistically significantly different to 50%, 95% CI = [49.4, 50.8].

Digression on quantum randomness

At this point I began to suspect that I’m not the first person to investigate bias. Tamura and Shikano (2021) ran a series of random number generator tests on measurements on a 20 qubit computer, IBM 20Q Poughkeepsie, obtaining 4,743,168 samples for each qubit. The circuit had a Hadmard gate, establishing the state

\(\displaystyle H|0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}}\).

The bias is already visible from their Figure 3, without examining the tests (though note the y-axis range – it’s not as bad as it first looks). The Born rule would predict results around 0.5:

So it looks like Poughkeepsie is an imperfect implementation.

I tried the same circuit on ibm_oslo with 10,000 runs on 7 qubits:

Here are the results:

0 1 % of 1s Lower CI Upper CI CI inc. 50%
c[0] 5078 4922 49.2 48.2 50.2 TRUE
c[1] 4852 5148 51.5 50.5 52.5 FALSE
c[2] 5065 4935 49.4 48.4 50.3 TRUE
c[3] 4963 5037 50.4 49.4 51.4 TRUE
c[4] 5092 4908 49.1 48.1 50.1 TRUE
c[5] 5025 4975 49.8 48.8 50.7 TRUE
c[6] 4797 5203 52.0 51.0 53.0 FALSE

Looking only at the marginal frequencies, that looks random enough… Two of the 95% CIs didn’t include 50%, perhaps due to a fluke. There are a dozen other properties we would want to check (see Tamura and Shikano, 2021) . But I’ll stop there.

This illustrates that imperfect implementations of quantum theory (and an imperfect universe, perhaps!) means we can’t assume that random sequences generated by a quantum process will be any more random than a pseudorandom generator – even if the theory says they will be. We need to check. This is another illustration of the role of implementation in trustworthiness that arose when exploring the BB84 quantum key distribution protocol. BB84 is perfectly secure in theory, but lots of extra work is needed to take account of imperfect implementation.

References

Matuschak, A., & Nielsen, M. A. (2020). Quantum Mechanics Distilled.

Tamura, K., & Shikano, Y. (2021). Quantum Random Numbers Generated by a Cloud Superconducting Quantum Computer. In T. Takagi, M. Wakayama, K. Tanaka, N. Kunihiro, K. Kimoto, & Y. Ikematsu (Eds.), International Symposium on Mathematics, Quantum Theory, and Cryptography (Vol. 33, pp. 17–37). Springer Singapore.

Teleporting a quantum state

This post explores the results of trying quantum teleportation on an actual quantum computer™.

Suppose Alice has a quantum state she would like to send to Bob,

\(|\mathit{Alice\ state}\rangle = \alpha|0\rangle + \beta|1\rangle\),

and they both hold entangled qubits, \(|\mathit{Alice\ tangle}\rangle\) and \(|\mathit{Bob\ tangle}\rangle\). It’s possible to teleport \(|\mathit{Alice\ state}\rangle\) to Bob via the entanglement, even if they are millions of miles apart! I’m going for teleportation within a computer so not quite so far.

One step of the process, after some operators are applied, is that Alice measures her qubits and tells Bob what the outcomes were. These measurements – one of \(|0\rangle|0\rangle\), \(|0\rangle|1\rangle\), \(|1\rangle|0\rangle\), or \(|1\rangle|1\rangle\) at random – don’t reveal the qubit state being teleported. In fact Alice doesn’t even need to know the state, so could be relaying a private message. The communication of these two measurement outcomes can’t happen faster than light speed, so the teleportation doesn’t break relativity.

Here’s a picture of the process, in lieu of a proper explanation (built and simulated using IBM Quantum Composer):

The pink bit over on the right hand size follows the rules below (lightly reordered from Flarend and Hilborn, 2022, p. 156) to recover the state depending on the outcomes of Alice’s measurements:

alice_tangle alice_state Gate to apply to bob_tangle
0 0 \(I\)
0 1 \(Z\)
1 0 \(X\)
1 1 \(Y\)

Here are the Pauli matrices referred to above:

\(X = \begin{pmatrix} 0&1\\ 1&0 \end{pmatrix}\)

\(Y = i\begin{pmatrix} 0&-1\\ 1&0 \end{pmatrix}\)

\(Z = \begin{pmatrix} 1&0\\ 0&-1 \end{pmatrix}\)

(\(i = \sqrt{-1}\).)

\(I\) is the \(2 \times 2\) identity matrix that does nothing, so there’s a chance that the correct state magics its way to Bob without him applying any transformation. Alice just needs to tell him when she measured her qubits.

It works in the simulator, but annoyingly doesn’t run on IBM’s quantum computers because of the way I encoded the conditionals (Error: Instruction bfunc is not supported [7001]). I’ve used a classical computing conditional to choose which of the four gates to apply, which requires a sort of dynamic quantum circuit that’s not supported.

But there’s another way! Since \(Y = iXZ\), we get the following:

alice_tangle alice_state Gate to apply to bob_tangle
0 0 \(I\)
0 1 \(Z\)
1 0 \(X\)
1 1 \(iXZ\)

It’s possible to control \(Z\) and \(X\) with a qubit – the latter is just a controlled NOT (CNOT). So it looks easy to get the combinations. Apart from the \(i\). Mermin (2007, p. 154) ignores it for reasons I don’t yet follow (is the \(Y\) really needed after all?). He also has the gates in the order

which seems to me back to front. I’ll ignore \(i\) too but order the gates to match the arithmetic. Here’s a circuit, second attempt:

The state circled in purple is what Alice is sending to Bob. Since we know the correct answer, I (or Bob) will make the quantum tomography easier by inverting the RX and RY gates Alice used to setup the state. This means we can look out for an easier basis state, \(|0\rangle\) (the states circled in green show where the \(|0\rangle\) came from and where it is measured).

If the teleportation worked, the 3rd classical bit (most significant bit, leftmost) will always be a 0. It is in the simulations:

Now let’s try on the quantum computer. Off it goes to ibm_nairobi. Let’s see what happens…

It was actually on the queue for 40 minutes in the end.

And here are the results – not quite as nice as the simulation:

Did it work? Well, given what I expected to happen, it did on 68.2% of the 1,000 runs (95% CI = [65.1%, 71.0%]). Here’s a table:

Measurement outcome Frequency
000 136
001 201
010 188
011 157
100 106
101 102
110 60
111 50

I was hoping for something a bit closer to 99%, but whatever happened it’s definitely not just a coin flip!

Let’s give it another go with a simpler circuit:

This will only work when Alice’s measurements are \(|0\rangle|0\rangle\), so for this setup they both keep trying with fresh entangled pairs until Alice gets the desired measurements. Again she needs to tell him when she has measured and what she got. I’ve undone the superposition again Bob’s side, so by “work” I mean Bob’s measurement is also \(|0\rangle\). Looks good in the simulator:

Fingers crossed. Here’s what happens when it’s run on the actual™  computer (ibmq_belem).

That looks a lot better (we’re just interested in the two bars pointed to above). Though it’s still a bit suspicious that Bob’s qubit is mostly \(|0\rangle\), irrespective of what Alice’s qubits are.

I think I’ve found the problem (emphasis original):

“The IBM quantum computers currently do not support instructions after measurements, meaning we cannot run the quantum teleportation in its current form on real hardware. Fortunately, this does not limit our ability to perform any computations due to the deferred measurement principle… The principle states that any measurement can be postponed until the end of the circuit, i.e. we can move all the measurements to the end, and we should see the same results…”

Third time lucky – this time only measuring as a final step:

This looks a little more convincing since Bob gets about the same number of \(|1\rangle\)s and \(|0\rangle\)s when Alice’s qubits are wrong. He still mostly gets \(|0\rangle\) when Alice’s qubits align (i.e., she measures \(|0\rangle|0\rangle\)).

References

Flarend, A., & Hilborn, B. (2022). Quantum computing: from Alice to Bob. Oxford University Press.

Mermin, N. D. (2007). Quantum computer science: an introduction. Cambridge University Press.

Quantum key distribution using BB84

Suppose Alice has a secret message she wants to send to Bob. They have two information channels: a quantum channel (e.g., Bob is able to detect polarised photons sent by Alice from a satellite) and a two-way unsecure classical channel (e.g., unencrypted email). Let’s assume that the message and key are both encoded using binary and the key is a one-time pad. They will eventually XOR message and key to encrypt and decrypt the message.

BB84 (Bennett & Brassard, 1984) is an approach to quantum key distribution that allows Alice to send an encryption key to Bob and for them to verify with a high level of confidence that the key hasn’t been intercepted. Once convinced that the key was sent securely, Alice can use it to encrypt the secret message and send it over the unsecure classical channel. Bob safely decrypts at the other side.

BB84 takes advantages of three related features of quantum mechanics.

  1. If a qubit is in superposition, e.g., \(\frac{|0\rangle + |1\rangle}{\sqrt{2}}\), then it’s impossible to infer its state from one observation. In particular, suppose an eavesdropper, Eve, measured the qubit and observed \(|1\rangle\). She couldn’t tell whether it had been in the state \(\frac{|0\rangle + |1\rangle}{\sqrt{2}}\) or \(|1\rangle\).
  2. Once you measure a qubit in superposition, it collapses to a basis state, so Eve couldn’t intercept the key and retransmit it onto Bob.
  3. You also can’t clone a qubit that is in an unknown state so, e.g., Eve couldn’t intercept a qubit from Alice, clone it, measure one of the pair and pass the other unmeasured qubit onto Bob.

Here’s how BB84 works.

Alice begins by generating a stream of random bits:

110110100110000101110…

Some of these bits will be used for the key.

Next, she generates a random stream of bases, classical basis (\(+\)) or the Hadamard basis (\(\times\)):

\(+\)\(\times\)\(+\)\(+\)\(\times\)\(+\)\(\times\)\(+\)\(\times\)\(\times\)\(+\)\(\times\)\(\times\)\(+\)\(\times\)\(+\)\(\times\)\(\times\)\(+\)\(\times\)\(+\)…

These will determine which basis Alice uses to send each bit of the key. The figure below (from Mayers, 2001) shows the bases in state space.

For a photon, the classical basis corresponds to vertical/horizontal polarisation and the Hadamard basis to the diagonal polarisations. Note in this case the state space corresponds nicely with the physical realisation of the qubit; that won’t always be the case, e.g., consider spin up and down states for electrons.

Here are the qubit states Alice sends:

\(\Psi(0, +) = |0\rangle\)

\(\Psi(1, +) = |1\rangle\)

\(\displaystyle \Psi(0, \times) = H|0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}}\)

\(\displaystyle \Psi(1, \times) = H|1\rangle = \frac{|0\rangle -|1\rangle}{\sqrt{2}}\)

Where \(\displaystyle H = \frac{1}{\sqrt2} \begin{bmatrix}1 & 1\\1 & -1\end{bmatrix}\), the Hadamard gate.

Alice sends the potential key bits using the randomly chosen bases.

Bob measures them, randomly deciding whether to assume a classical or Hadamard basis – for the latter applying the Hadamard gate before measuring. The possible outcomes in the absence of eavesdropping are as follows:

Alice sends Bob assumes classical Bob assumes Hadamard
\(\Psi(0, +) = |0\rangle\) \(P(|0\rangle) = 1\) \(P(|0\rangle) = \frac{1}{2}\)
\(\Psi(1, +) = |1\rangle\) \(P(|1\rangle) = 1\) \(P(|1\rangle) = \frac{1}{2}\)
\(\Psi(0, \times) = H|0\rangle\) \(P(|0\rangle) = \frac{1}{2}\) \(P(|0\rangle) = 1\)
\(\Psi(1, \times) = H|1\rangle\) \(P(|1\rangle) = \frac{1}{2}\) \(P(|1\rangle) = 1\)

So if Bob randomly chooses the correct basis, he gets the correct bit; if not, he gets a random bit, with a 50-50 chance of a 1 or 0.

Bob tells Alice via the unsecure channel the sequence of bases he used. At this point, doing so doesn’t help any eavesdroppers since the qubits have already been measured.

Alice tells Bob which bases were correct, again on the unsecure channel, so Bob can discard measurements for the rest. She also sacrifices a random sample of the key bits by sharing what the right answer is for those. If Eve the eavesdropper intercepted any, then they won’t all have made it to Bob: either they will be missing or Eve will have had to replace them with a random bit.

If Alice and Bob are satisfied that the test qubits made it across okay without being intercepted, then they use the remainder for the key, sending the encrypted message through the unsecure channel.

That’s the gist. The devil’s in the detail, e.g., working out how many bits to send to ensure enough remain after checking for intercepts; how many to sacrifice to check that Eve wasn’t eavesdropping; while taking account of errors in transmission that will mean bits don’t arrive intact but for innocent reasons other than eavesdropping.

The security of BB84 depends on the quality of the implementation. The field of quantum hacking explores a variety of ways to exploit imperfections, e.g., classical side channels that leak information about what was sent, which can be intercepted without interfering with the qubit. Researchers devise clever ways to defend against these attacks. See, e.g., Dixon et al. (2017).

References

Bennett, C. H. & Brassard, G. (1984). Quantum cryptography: Public key distribution and coin tossing. Proceedings of IEEE International Conference on Computers, Systems, and Signal Processing (pp. 175-179), India.

Dixon, A. R., Dynes, J. F., Lucamarini, M., Fröhlich, B., Sharpe, A. W., Plews, A., Tam, W., Yuan, Z. L., Tanizawa, Y., Sato, H., Kawamura, S., Fujiwara, M., Sasaki, M., & Shields, A. J. (2017). Quantum key distribution with hacking countermeasures and long term field trial. Scientific Reports, 7, 1978.

Mayers, D. (2001). Unconditional security in quantum cryptography. Journal of the ACM, 48, 351–406.

Quantum entanglement

This brief post shows how to establish an entangled state on IBM Quantum’s computers – here using ibmq_manila.

The circuit to establish \(\displaystyle \frac{|00\rangle + |11\rangle}{\sqrt{2}}\) is as follows:

A few clicks later, and the circuit is added to the queue…

The total wait to get onto ibmq_manila was about an hour and the circuit ran 1,000 times in 5 seconds.

Here are the results:

It worked across 93.9% of runs: both qubits had the same measurement outcome, roughly 50-50 split between \(|00\rangle\) and \(|11\rangle\).