Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quantum-kittens
GitHub Repository: quantum-kittens/platypus
Path: blob/main/notebooks/intro/describing-quantum-computers.ipynb
3855 views
Kernel: Python 3

Describing quantum computers

This chapter will introduce the different mathematical objects and notations that we’re going to be using to describe quantum computers. Symbols, equations and specialist vocabulary allow us to communicate and work with maths in a very concise way, they’re incredibly powerful tools, but they also come at a cost; they are difficult to understand if you don’t know what all the symbols mean, and this can alienate people. To counter this, in this textbook, equations are interactive. You can move your mouse over symbols to see what they mean. We will also slowly sprinkle in some esoteric words so you can start speaking the language of mathematics and quantum computing, and you can see explanations of these words by moving your mouse over these words too.

Amplitudes

A classical probability is often represented by a real number between 0 and 1, but amplitudes also have a direction. A natural candidate to represent an amplitude is a complex number, as a complex number can also be completely described by both a magnitude and a direction, but in this course we will only work with amplitudes that can point in two directions (e.g. left and right) and we won’t worry about anything else.

Image comparing amplitudes and probabilities

This makes the maths a lot simpler, as we can now describe any amplitude as a number between -1 and +1; if the number is positive, the amplitude is facing forward, and if it's negative, it's facing backwards. It turns out that this is still enough to do interesting things!

Quick quiz

Which of these is a valid amplitude but not a valid probability?

  1. 1-1

  1. 1/31/3

  1. 1.011.01

  1. 2\sqrt{-2}

State vectors

We saw in the last page that we can predict the behaviour of a quantum system by keeping track of the probability amplitudes for each outcome at each point in our computation. We also saw that, for n qubits, there are 2n2^n possible outcomes, and we can store these amplitudes in lists of length 2n2^n which we call vectors. Since these vectors describe the state of our qubits, we call them “state vectors”.

Here is an example of a state vector for a quantum computer with two qubits:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{x-ket}{|x\rang…

Spend some time reading the tooltips on the equation above, then answer the questions below.

Quick quiz

In the state vector above, what is the amplitude of the outcome ‘01’?

  1. 11

  1. 12\sqrt{\tfrac{1}{2}}

  1. 1/21/2

  1. 00


If the state vector above described the state of some qubits, what would be the probability of measuring ‘00’?

  1. 11

  1. 12\sqrt{\tfrac{1}{2}}

  1. 1/21/2

  1. 00

Adding and multiplying vectors

If you study other areas of mathematics, you’ll find that lots of things can be considered vectors. We’ve introduced vectors as ‘lists of numbers’, because this is how we will consider them both in this textbook and in Qiskit. But what separates a vector from any old list of numbers is that mathematicians decided on some well defined rules for adding two vectors, and for multiplying vectors by scalars.

Multiplying vectors by scalars

For example, here is a vector multiplied by a scalar:

ParseError: KaTeX parse error: Undefined control sequence: \cssId at position 1: \̲c̲s̲s̲I̲d̲{_number-three}…

We can see that each element of the vector has been multiplied by 3. The more general rule for a vector with NN elements is:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{scalar}{s} \be…

So we could have written the state vector x|x\rangle we defined above more neatly like this:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{x-ket}{|x\rang…

Adding two vectors

The second rule is for adding two vectors together. This is only defined when the two vectors have the same number of elements, and gives a new vector with the same number of elements. Here is the general rule:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 17: …begin{bmatrix} \̲c̲l̲a̲s̲s̲{_vec-el-0}{a_0…

This means we can add and subtract vectors to make new vectors. For example, if we define the the vectors 00|00\rangle and 01|01\rangle like so:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{def-00}{|00\ra…

We can write ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{x-ket}{|x\rang… in the form:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{x-ket}{|x\rang…

We call adding quantum states like this “superposing” them, so we can say “x|x\rangle is a superposition of the states 00|00\rangle and 01|01\rangle.” In fact, it’s convention in quantum computing to define the computational basis states like so:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{def-00}{|00\ra…

And we can write any quantum state as a superposition of these state vectors, if we multiply each vector by the correct number and add them together:

ParseError: KaTeX parse error: Undefined control sequence: \cssId at position 1: \̲c̲s̲s̲I̲d̲{_psi-ket}{|\ps…

Since we can write any vector as a combination of these four vectors, we say these four vectors form a basis, which we will call the computational basis. The computational basis is not the only basis. For single qubits, a popular basis is formed by the vectors ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{plus-ket}{|{+}… and ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{minus-ket}{|{-…:

image showing both the |0>, |1> basis and the |+>, |-> basis on the same plane

ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{plus-ket}{|{+}…ParseError: KaTeX parse error: Undefined control sequence: \class at position 1: \̲c̲l̲a̲s̲s̲{minus-ket}{|{-…

Try it

Find values for α\alpha, β\beta, γ\gamma and δ\delta such that these equations are true:

  • α++β=0\alpha|{+}\rangle + \beta|{-}\rangle = |0\rangle

  • γ++δ=1\gamma|{+}\rangle + \delta|{-}\rangle = |1\rangle

How many different state vectors are there?

We know that we can represent any quantum state using vectors, but is any vector a valid quantum state? In our case, no; since we square our amplitudes to find the probability of outcomes occurring, we need these squares to add to one, otherwise it doesn't make sense.

ParseError: KaTeX parse error: Undefined control sequence: \cssId at position 1: \̲c̲s̲s̲I̲d̲{sum}{\sum^{N-1…

Quick quiz

Which of these is a valid quantum state? (Try adding up the squared amplitudes.)

  1. 13[1110]\sqrt{\tfrac{1}{3}}\begin{bmatrix} 1 \\\\ -1 \\\\ 1 \\\\ 0 \end{bmatrix}

  1. 12[1111]\sqrt{\tfrac{1}{2}}\begin{bmatrix} 1 \\\\ -1 \\\\ -1 \\\\ 1 \end{bmatrix}

  1. 12[11]\tfrac{1}{2}\begin{bmatrix} 1 \\\\ 1 \end{bmatrix}

Another factor is something we call "global phases" of state vector. Since we only know phase exists because of the interference effects it produces, we can only ever measure phase differences. If we rotated all the amplitudes in a state vector by the same amount, we'd still see the exact same behaviour.

image showing interference effects with different starting phases

image showing interference effects with different starting phases

For example, there is no experiment we could perform that would be able to distinguish between these two states:

a=12[1001]|a\rangle = \sqrt{\tfrac{1}{2}}\begin{bmatrix} 1 \\ 0 \\ 0 \\ 1 \end{bmatrix}
a=12[1001]-|a\rangle = \sqrt{\tfrac{1}{2}}\begin{bmatrix} -1 \\ 0 \\ 0 \\ -1 \end{bmatrix}

Because the differences between each of the amplitudes is the same. You could say these two vectors are different mathematically, but the same physically.

Quantum operations

So now we know all about the different states our qubits can be in, it’s time to look at how we represent the operations that transform one state to another.

In the same way there is a transition probability that a certain action will transform a coin from heads to tails, there is a transition amplitude for each starting state and end state of our qubits. We can describe any quantum operations through these transition amplitudes.

Image showing two state vectors before and after an operation

So, what possible transformations are there? Say we have a starting state a|a\rangle that’s transformed to a new state b|b\rangle. If we want our representation to cover every possible transformation, then each amplitude in a|a\rangle must have a transition amplitude to each amplitude in b|b\rangle.

Quick quiz

An nn-qubit state vector can contain up to 2n2^n amplitudes. What’s the largest number of transition amplitudes we’d need to represent any quantum operation on nn qubits?

  1. 22n2\cdot 2^n

  1. (2n)2(2^n)^2

  1. 2n2n

  1. 22n2^{2^n}

Drawing lines like this is a bit of a messy way of doing it, so instead we can put all these numbers into a matrix:

ParseError: KaTeX parse error: Undefined control sequence: \cssId at position 1: \̲c̲s̲s̲I̲d̲{u-gate}{U} = …

For example, here is the matrix that represents the CNOT operation we saw in the atoms of computation:

ParseError: KaTeX parse error: Undefined control sequence: \cssId at position 1: \̲c̲s̲s̲I̲d̲{_cnot-gate}{\t…

Quick quiz

What is the transition amplitude of the CNOT operation (as shown above) transforming the state 10|10\rangle to 01|01\rangle?

  1. 11

  1. 00

  1. [1000]\begin{bmatrix} 1 & 0 & 0 & 0\end{bmatrix}

  1. [0010]\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\\\ 0\end{bmatrix}

And here is the matrix for the H-gate we saw in the previous page:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 41: …begin{bmatrix} \̲c̲l̲a̲s̲s̲{_t_amp_0_0}{1}…

(we use the same rule for multiplying a matrix by a scalar as we do with vectors). And when we want to see what effect an operation will have on some qubits, we multiply each transition amplitude by the amplitude of each state in our input state vector, and then add up the amplitudes for each state to get our output state vector. This is exactly the same as multiplying along each branch in a probability (or amplitude) tree and adding up the total probabilities (or amplitudes) at the end.

For any mathematicians in the audience, this is just standard matrix multiplication.

ParseError: KaTeX parse error: Undefined control sequence: \class at position 50: …begin{bmatrix} \̲c̲l̲a̲s̲s̲{_t_amp_0_0}{1}…

image showing how the H-gate transforms the state |0> into the state |+>

Rules of quantum operations

In the same way that not every vector is a valid state vector, not every matrix is a valid quantum operation. If a matrix is to make sense as a real operation, it needs to keep the total probability of the output states equal to 1. So for example, this couldn’t be a real operation:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 17: …begin{bmatrix} \̲c̲l̲a̲s̲s̲{_t_amp_0_0}{1}…

Because if it acts on the state 0|0\rangle we get:

ParseError: KaTeX parse error: Undefined control sequence: \class at position 17: …begin{bmatrix} \̲c̲l̲a̲s̲s̲{_t_amp_0_0}{1}…

and the total probabilities add to two, which doesn't make any sense. Alternatively, if it acted on the state 1|1\rangle, then the total probabilities would add up to zero, which also doesn't make sense. To preserve the total probability in all cases, our operations need to be reversible. This means we can perform our quantum gates backwards to 'undo' them (remembering to reverse any rotations) and be left with the state we started with. We say matrices with this property are unitary. You will often see quantum gates referred to as 'unitaries' or 'unitary gates'.