This lesson introduces the basic framework of quantum information, including the description of quantum states as vectors with complex number entries, measurements that allow classical information to be extracted from quantum states, and operations on quantum states that are described by unitary matrices. We will restrict our attention in this lesson to the comparatively simple setting in which a single system is considered in isolation. In the next lesson, we will expand our view to multiple systems, which can interact with one another and be correlated, for instance.
There are, in fact, two common mathematical descriptions of quantum information. The one introduced in this lesson is the simpler of the two. This description is sufficient for understanding many (or perhaps most) quantum algorithms, and is a natural place to start from a pedagogical viewpoint.
A more general, and ultimately more powerful description of quantum information, in which quantum states are represented by density matrices, will be introduced in a later lesson. The density matrix description is essential for the study of quantum information for reasons that will be explained as they arise. As an example, the density matrix description is used to model the effects of noise on quantum computations, and more generally it serves as a mathematical basis for quantum information theory and quantum cryptography. It is also quite beautiful from a mathematical perspective. For these reasons, we encourage you to learn more about it when the time is right, but for now our focus will be on the simpler description of quantum information.
To describe quantum information and how it works, we will begin with classical information. Some readers may wonder why we have chosen to devote so much attention to classical information in this lesson (as well as the next lesson), but there are good reasons.
For one, although quantum and classical information are different in some pretty spectacular ways, their mathematical descriptions are actually quite similar.
Classical information also serves as a familiar point of reference when studying quantum information, as well as a source of analogy that goes a surprisingly long way. It is common that people ask questions about quantum information that have natural classical analogs — often with simple answers that can provide both clarity and insight into the original questions about quantum information. Indeed, it is not at all unreasonable to claim that one cannot truly understand quantum information without understanding classical information.
Some readers may already be familiar with the material to be discussed in this section, while others may not — but the discussion is meant for both audiences. In addition to highlighting the aspects of classical information that are most relevant to an introduction to quantum information, this section introduces the Dirac notation, which is often used to describe vectors and matrices in quantum information and computation. As it turns out, the Dirac notation is not specific to quantum information: it can equally well be used in the context of classical information, as well as for many other settings in which vectors and matrices arise.
Suppose that we have a system that stores information. More specifically, we will assume that this system can be in one of a finite number of classical states at each instant. Here, the term classical state should be understood in intuitive terms, as a configuration that can be recognized and described unambiguously.
The archetypal example, which we will come back to repeatedly, is that of a bit, which is a system whose classical states are 0 and 1. Other examples include a standard six-sided die, whose classical states are 1, 2, 3, 4, 5, and 6; a nucleobase in a strand of DNA, whose classical states are A, C, G, and T; and a switch on an electric fan, whose classical states are (commonly) high, medium, low, and off. In mathematical terms, the specification of the classical states of a system are, in fact, the starting point: we define a bit to be a system that has classical states 0 and 1, and likewise for systems having different classical state sets.
For the sake of this discussion, let us give the name $\mathsf{X}$ to the system being considered, and let us use the symbol $\class{_sigma}{\Sigma}$ to refer to the set of classical states of $\mathsf{X}$. As well as the assumption that $\Sigma$ is finite, as mentioned earlier, we naturally assume that $\Sigma$ is nonempty: it is nonsensical for a physical system to have no states at all that it can be in. Although it does make sense to consider physical systems having infinitely many classical states, we will ignore this possibility for now. For the sake of convenience and brevity, we will hereafter use the term classical state set to mean any finite and nonempty set.
For example, if $\mathsf{X}$ is a bit, then $\Sigma = \{0,1\}$ (which is often called the binary alphabet); if $\mathsf{X}$ is a six-sided die, then $\Sigma = \{1,2,3,4,5,6\}$; and if $\mathsf{X}$ is an electric fan switch, then $\Sigma = \{\mathrm{high}, \mathrm{medium}, \mathrm{low}, \mathrm{off}\}$.
When thinking about $\mathsf{X}$ as a carrier of information, where the different classical states of $\mathsf{X}$ could have different interpretations or lead to different outcomes or consequences, it may be sufficient to describe $\mathsf{X}$ as simply being in one of its possible classical states. For instance, if $\mathsf{X}$ is a fan switch, we might happen to know with certainty that it is set to high. Often in information processing, however, our knowledge of $\mathsf{X}$ is uncertain, and we represent our knowledge of the classical state of $\mathsf{X}$ by assigning probabilities to each classical state, resulting in a probabilistic state.
For example, suppose $\mathsf{X}$ is a bit. Based on what we know or expect about what has happened to $\mathsf{X}$ in the past, perhaps we believe that $\mathsf{X}$ is in the classical state $0$ with probability $3/4$ and in the state $1$ with probability $1/4.$ We may represent such a belief by writing this:
$$ \class{probability}{\operatorname{Pr}}(\mathsf{X}=0) = \frac{3}{4} \quad\text{and}\quad \class{probability}{\operatorname{Pr}}(\mathsf{X}=1) = \frac{1}{4}. $$A more succinct way to represent this probabilistic state is by a column vector:
$$ \begin{pmatrix} \frac{3}{4}\\[1mm] \frac{1}{4} \end{pmatrix}. $$The probability of the bit being $0$ is placed at the top of the vector and the probability of the bit being $1$ is placed at the bottom simply because this is the conventional way to order the set $\{0,1\}$, with $0$ first and $1$ second.
In general, we can represent a probabilistic state of a system having any classical state set in the same way, as a vector of probabilities. The probabilities can be ordered in any way we choose — which is typically determined by some natural or default way to order the classical state set we're working with.
To be precise, we can represent any probabilistic state through a column vector satisfying two properties:
Conversely, any column vector that satisfies these two properties can be taken as a representation of a probabilistic state. Hereafter, we will refer to vectors of this form as probability vectors.
Alongside the succinctness of this notation, identifying probabilistic states as column vectors has the advantage that operations on probabilistic states are represented through matrix–vector multiplication, as will be discussed in greater detail shortly.
Which one of these is a valid probability vector?
Now let us briefly consider what happens if we measure a system when it is in a probabilistic state. By measuring a system, we mean that we look at the system and unambiguously recognize whatever classical state it is in.
Measurement changes our knowledge of the system, and therefore changes the probabilistic state that we associate with that system: if we recognize that $\mathsf{X}$ is in the classical state $a\in\Sigma$, then the new probability vector representing our knowledge of $\mathsf{X}$ becomes a vector having a $1$ in the entry corresponding to $a$ and $0$ for all other entries. This vector indicates that $\mathsf{X}$ is in the classical state $a$ with certainty, which we know having just recognized it.
We denote the vector just described, meaning the vector having a $1$ in the entry corresponding to $a$ and $0$ for all other entries, by $\vert a\rangle.$ This vector is read as "ket $a$" for a reason that will be explained later. Vectors of this sort are also called standard basis vectors.
For example, assuming that the system we have in mind is a bit, whose classical state set is therefore $\{0,1\}$, we denote
$$ \vert 0\rangle = \begin{pmatrix}1\\0\end{pmatrix} \quad\text{and}\quad \vert 1\rangle = \begin{pmatrix}0\\1\end{pmatrix}. $$Notice that any two-dimensional column vector can be expressed as a linear combination of these two vectors. For example, we have
$$ \begin{pmatrix} \frac{3}{4}\\[2mm] \frac{1}{4} \end{pmatrix} = \frac{3}{4}\,\vert 0\rangle + \frac{1}{4}\,\vert 1\rangle. $$The fact that any column vector can be written as a linear combination of standard basis vectors naturally generalizes to any classical state set. Expressing vectors as linear combinations of standard basis vectors will be very typical going forward.
Returning to the change of a probabilistic state upon being measured, we may note the following connection to our everyday experiences. Suppose we flip a fair coin, but cover up the coin before looking at it. We would then say that its probabilistic state is
$$ \begin{pmatrix} \frac{1}{2}\\[2mm] \frac{1}{2} \end{pmatrix} = \frac{1}{2}\,\vert\text{heads}\rangle + \frac{1}{2}\,\vert\text{tails}\rangle. $$Here, the classical state set of our coin is $\{\text{heads},\text{tails}\}$, and even though it doesn't matter for this particular vector, we'll order these two states as heads first, tails second:
$$ \vert\text{heads}\rangle = \begin{pmatrix}1\\0\end{pmatrix} \quad\text{and}\quad \vert\text{tails}\rangle = \begin{pmatrix}0\\1\end{pmatrix}. $$If we were to uncover the coin and look at it, we would see one of the two classical states: heads or tails. Supposing that the result were tails, we would naturally update our description of the probabilistic state of the coin so that it becomes $|\text{tails}\rangle$. Of course, if we were then to cover up the coin, and then uncover it and look at it again, the classical state would still be tails, which is consistent with the probabilistic state being described by the vector $|\text{tails}\rangle$. This may seem trivial, and in some sense it is — but in recognizing this triviality, the analogous behavior for quantum information might seem less unusual.
One final remark concerning measurements of probabilistic states is that probabilistic states describe knowledge or belief, and not necessarily something actual. The state of our coin after we flip it, but before we look, is either heads or tails and we simply do not know which until we look — and doing so does not actually change the state of the coin, but only our knowledge of it. Upon seeing that the classical state of the coin is tails, say, we naturally update our knowledge by assigning the probabilistic state $|\text{tails}\rangle$ to the coin — but to someone else who did not see the coin when it was uncovered, the probabilistic state of the coin would remain unchanged and would be described by the probability vector specified previously. This is not a cause for concern: different individuals may have different knowledge or beliefs about of a particular system, and hence describe that system by different probability vectors.
In the last part of this brief summary of classical information, we will consider the sorts of operations one might perform on a classical system.
First, there are deterministic operations, where each classical state $a\in\Sigma$ is transformed into $f(a)$ for some function $f$ of the form $f:\Sigma\rightarrow\Sigma$.
For example, if $\Sigma = \{0,1\}$, there are four functions of this form, $f_1$, $f_2$, $f_3$, and $f_4$, which can be represented by tables of values as follows:
$$ \rule[-10mm]{0mm}{15mm} \begin{array}{c|c} a & f_1(a)\\ \hline 0 & 0\\ 1 & 0 \end{array} \qquad \begin{array}{c|c} a & f_2(a)\\ \hline 0 & 0\\ 1 & 1 \end{array} \qquad \begin{array}{c|c} a & f_3(a)\\ \hline 0 & 1\\ 1 & 0 \end{array} \qquad \begin{array}{c|c} a & f_4(a)\\ \hline 0 & 1\\ 1 & 1 \end{array} $$The first and last of these functions are constant: $f_1(a) = 0$ and $f_4(a) = 1$ for each $a\in\Sigma$. The middle two are not constant, they are balanced in the sense that the two possible output values occur the same number of times as we range over the possible inputs. The function $f_2$ is the identity function: $f_2(a) = a$ for each $a\in\Sigma$. And $f_3$ is the function $f_3(0) = 1$ and $f_3(1) = 0$, which is better-known as the NOT function.
The actions of deterministic operations on probabilistic states can be represented by matrix-vector multiplication. Specifically, the matrix $M$ that represents a given function $f:\Sigma\rightarrow\Sigma$ is the one that satisfies
$$ M \vert a \rangle = \vert f(a)\rangle $$for every $a\in\Sigma$. Such a matrix always exists and is unique.
For example, the matrices $M_1,\ldots,M_4$ corresponding to the functions $f_1,\ldots,f_4$ above are as follows:
$$ \rule[-6mm]{0mm}{14.5mm} M_1 = \begin{pmatrix} \class{_m00}{1} & \class{_m10}{1}\\ \class{_m01}{0} & \class{_m11}{0} \end{pmatrix}, \hspace{4mm} M_2 = \begin{pmatrix} \class{_m00}{1} & \class{_m10}{0}\\ \class{_m01}{0} & \class{_m11}{1} \end{pmatrix}, \hspace{4mm} M_3 = \begin{pmatrix} \class{_m00}{0} & \class{_m10}{1}\\ \class{_m01}{1} & \class{_m11}{0} \end{pmatrix}, \hspace{4mm} \text{and} \hspace{4mm} M_4 = \begin{pmatrix} \class{_m00}{0} & \class{_m10}{0}\\ \class{_m01}{1} & \class{_m11}{1} \end{pmatrix}. $$Matrices that represent deterministic operations always have exactly one $1$ in each column, and $0$ for all other entries.
A convenient way to represent matrices of these and other forms makes use of an analogous notation for row vectors to the one for column vectors discussed previously: we denote by $\langle a \vert$ the row vector having a $1$ in the entry corresponding to $a$ and zero for all other entries, for each $a\in\Sigma.$ This vector is read as "bra $a$."
For example, if $\Sigma = \{0,1\}$, then
$$ \langle 0 \vert = \begin{pmatrix} 1 & 0 \end{pmatrix} \quad\text{and}\quad \langle 1 \vert = \begin{pmatrix} 0 & 1 \end{pmatrix}. $$For an arbitrary choice of a classical state set $\Sigma$, viewing row vectors and column vectors as matrices having a single row or column, respectively, and performing the matrix multiplication $\vert b\rangle \langle a\vert$, one obtains a square matrix having a $1$ in the entry corresponding to the pair $(b,a)$, meaning that the row of the entry corresponds to $b$ and the column corresponds to $a$, and $0$ for all other entries.
Using this notation, for any function $f:\Sigma\rightarrow\Sigma$, we may express the matrix $M$ corresponding to the function $f$ as
$$ M = \sum_{a\in\Sigma} \vert f(a) \rangle \langle a \vert. $$Now, if we again think about vectors as matrices, but this time consider the multiplication $\langle a \vert \vert b \rangle$, then we obtain a $1\times 1$ matrix, which we can think about as a scalar. For the sake of tidiness we write this product as $\langle a \vert b\rangle$ rather than $\langle a \vert \vert b \rangle.$ This product satisfies the following simple formula:
$$ \langle a \vert b \rangle = \begin{cases} 1 & a = b\\ 0 & a \not= b. \end{cases} $$Using this observation, together with the fact that matrix multiplication is associative and linear, we obtain
$$ M \vert b \rangle = \Biggl( \sum_{a\in\Sigma} \vert f(a) \rangle \langle a \vert \Biggr) \vert b\rangle = \sum_{a\in\Sigma} \vert f(a) \rangle \langle a \vert b \rangle = \vert f(b)\rangle, $$for each $b\in\Sigma$, which is what we require of $M$.
As we will discuss in greater detail in Lesson 3, $\langle a \vert b \rangle$ may also be seen as an inner product between the vectors $\vert a\rangle$ and $\vert b\rangle$. Inner products are critically important in quantum information, but we will delay a discussion of them until they are needed.
At this point the names "bra" and "ket" may be evident: putting a "bra" $\langle a\vert$ together with a "ket" $\vert b\rangle$ yields a "bracket" $\langle a \vert b\rangle$. This notation and terminology is due to Paul Dirac, and for this reason is known as the Dirac notation.
In addition to deterministic operations, we have probabilistic operations.
For example, consider an operation on a bit where, if the classical state of the bit is $0,$ it is left alone; and if the classical state of the bit is $1,$ it is flipped to $0$ with probability $1/2.$ This operation is represented by the matrix
$$ \begin{pmatrix} 1 & \frac{1}{2}\\[1mm] 0 & \frac{1}{2} \end{pmatrix}, $$meaning that the action of this operation on a given probabilistic state is obtained by multiplying this matrix to the probability vector associated with the given probabilistic state.
For an arbitrary choice of a classical state set, we can describe the set of all probabilistic operations in mathematical terms as those that are represented by stochastic matrices, which are matrices satisfying these two properties:
Equivalently, stochastic matrices are matrices whose columns all form probability vectors.
We can think about probabilistic operations at an intuitive level as ones where randomness might somehow be used or introduced during the operation, just like in the example above. With respect to the stochastic matrix description of a probabilistic operation, each column can be viewed as a vector representation of the probabilistic state that is generated given whatever classical state input corresponds to that column.
We can also think about stochastic matrices as being exactly those matrices that always map probability vectors to probability vectors. That is, stochastic matrices always map probability vectors to probability vectors, and any matrix that always maps probability vectors to probability vectors must be a stochastic matrix.
Finally, another way to think about probabilistic operations is that they are random choices of deterministic operations. For instance, we can think about the operation in the example above as applying either the identity function or the constant 0 function, each with probability $1/2$. This is consistent with the equation
$$ \begin{pmatrix} 1 & \frac{1}{2}\\[1mm] 0 & \frac{1}{2} \end{pmatrix} = \frac{1}{2} \begin{pmatrix} 1 & 0\\[1mm] 0 & 1 \end{pmatrix} + \frac{1}{2} \begin{pmatrix} 1 & 1\\[1mm] 0 & 0 \end{pmatrix}. $$Such an expression is always possible, for an arbitrary choice of a classical state set and any stochastic matrix with rows and columns identified with that classical state set.
Suppose that $\mathsf{X}$ is a system having classical state set $\Sigma$, and $M_1,\ldots,M_n$ are stochastic matrices representing probabilistic operations on the system $\mathsf{X}$.
If the first operation $M_1$ is applied to the probabilistic state represented by a probability vector $u$, the resulting probabilistic state is represented by the vector $M_1 u.$ If we then apply the second probabilistic operation $M_2$ to this new probability vector, we obtain the probability vector
$$ M_2 (M_1 u) = (M_2 M_1) u. $$The equality follows from the fact that matrix multiplication (which includes matrix-vector multiplication as a special case) is an associative operation. Thus, the probabilistic operation obtained by composing the first and second probabilistic operations, where we first apply $M_1$ and then apply $M_2$, is represented by the matrix $M_2 M_1$, which is necessarily stochastic.
More generally, composing the probabilistic operations represented by the matrices $M_1,\ldots,M_n$ in that order, meaning that $M_1$ is applied first, $M_2$ is applied second, and so on, with $M_n$ applied last, is represented by the matrix
$$ M_n \,\cdots\, M_1. $$Note that the ordering is important here: although matrix multiplication is associative, it is not a commutative operation in general.
For example, if we have
$$ M_1 = \begin{pmatrix} 1 & 1\\[1mm] 0 & 0 \end{pmatrix} \quad\text{and}\quad M_2 = \begin{pmatrix} 0 & 1\\[1mm] 1 & 0 \end{pmatrix}, $$then
$$ M_2 M_1 = \begin{pmatrix} 0 & 0 \\[1mm] 1 & 1 \end{pmatrix} \quad\text{and}\quad M_1 M_2 = \begin{pmatrix} 1 & 1\\[1mm] 0 & 0 \end{pmatrix}. $$That is, the order in which probabilistic operations are composed matters: changing the order in which operations are applied in a composition can change the resulting operation.
Now we move on to quantum information, where we make a different choice for the type of vector that represents a state — in this case a quantum state — of the system being considered. As in the previous section, we'll be concerned with systems having finite and nonempty sets of classical states, and we will make use of much of the notation that was introduced in that section.
A quantum state of a system is represented by a column vector in a similar way to the representation of probabilistic states by vectors, including the assumption that the indices of the vector are placed in correspondence with the classical state set of the system being considered. Vectors representing quantum states are characterized by these two properties:
Thus, in contrast to the probabilistic case, vectors representing quantum states need not have nonnegative real number entries, and it is the sum of the absolute values squared of the entries (as opposed to the sum of the entries) that must equal $1.$
The Euclidean norm of a column vector
$$ v = \begin{pmatrix} \alpha_1\\ \vdots\\ \alpha_n \end{pmatrix} $$is denoted and defined as follows:
$$ \| v \| = \sqrt{\sum_{k=1}^n |\alpha_k|^2}. $$The condition that the sum of the absolute values squared of a quantum state vector equals $1$ is therefore equivalent to that vector having Euclidean norm equal to $1.$ That is, quantum state vectors are unit vectors with respect to the Euclidean norm.
The term qubit refers to a system whose classical state set is $\{0,1\}$ and that can be in a quantum state. That is, a qubit is really just a bit — but by using this name we explicitly recognize that this bit can be in a quantum state.
These are examples of quantum states of a qubit:
$$ \begin{pmatrix} 1\\[2mm] 0 \end{pmatrix} = \vert 0\rangle \quad\text{and}\quad \begin{pmatrix} 0\\[2mm] 1 \end{pmatrix} = \vert 1\rangle, $$$$ \begin{pmatrix} \frac{1}{\sqrt{2}}\\[2mm] \frac{1}{\sqrt{2}} \end{pmatrix} = \frac{1}{\sqrt{2}}\,\vert 0\rangle + \frac{1}{\sqrt{2}}\,\vert 1\rangle, \tag{1} $$and $$ \begin{pmatrix} \frac{1+2i}{3}\\[2mm] -\frac{2}{3} \end{pmatrix} = \frac{1+2i}{3}\,\vert 0\rangle - \frac{2}{3}\,\vert 1\rangle. $$
The first two examples, $\vert 0\rangle$ and $\vert 1\rangle$, illustrate that standard basis elements are valid quantum state vectors: their entries are complex numbers (where the imaginary part of these numbers happens to be $0$) and computing the sum of the absolute values squared of the entries yields
$$ \vert 1\vert^2 + \vert 0\vert^2 = 1 \quad\text{and}\quad \vert 0\vert^2 + \vert 1\vert^2 = 1, $$as required. Similar to the classical setting, we associate the quantum state vectors $\vert 0\rangle$ and $\vert 1\rangle$ with a qubit being in the classical state $0$ or $1$, respectively, with certainty.
For the other two examples, we again have complex number entries, and computing the sum of the absolute value squared of the entries yields
$$ \biggl\vert\frac{1}{\sqrt{2}}\biggr\vert^2 + \biggl\vert\frac{1}{\sqrt{2}}\biggr\vert^2 = \frac{1}{2} + \frac{1}{2} = 1 $$and
$$ \biggl\vert \frac{1+2i}{3} \biggr\vert^2 + \biggl\vert -\frac{2}{3} \biggr\vert^2 = \frac{5}{9} + \frac{4}{9} = 1. $$These are therefore valid quantum state vectors.
The example $(1)$ of a qubit state vector above is very commonly encountered — it is called the plus state and is denoted as follows:
$$ \vert + \rangle = \frac{1}{\sqrt{2}} \vert 0\rangle + \frac{1}{\sqrt{2}} \vert 1\rangle. $$We also use the notation
$$ \vert - \rangle = \frac{1}{\sqrt{2}} \vert 0\rangle - \frac{1}{\sqrt{2}} \vert 1\rangle $$to refer to a related quantum state vector where the second entry is negative rather than positive, and we call this state the minus state. This sort of notation, where some symbol other than one referring to a classical state appears inside of a ket, is common — we can use whatever name we wish inside of a ket to name a vector.
Indeed, it is quite common to use a notation such as $\vert\psi\rangle$, or other names in place of $\psi$, to refer to arbitrary vectors that may not necessarily be a standard basis vector: $\psi$ is simply a name for the vector, but it is put inside a ket, which stresses that it is a vector.
Notice that if we have a vector $\vert \psi \rangle$ whose indices correspond to some classical state set $\Sigma$, and if $a\in\Sigma$ is an element of this classical state set, then the (matrix) product $\langle a\vert \vert \psi\rangle$ is equal to the entry of the vector $\vert \psi \rangle$ whose index corresponds to $a$. As we did when $\vert \psi \rangle$ is a standard basis vector, we write $\langle a \vert \psi \rangle$ rather than $\langle a\vert \vert \psi\rangle$ for the sake of readability.
For example, if $\Sigma = \{0,1\}$ and
$$ \vert \psi \rangle = \frac{1+2i}{3} \vert 0\rangle - \frac{2}{3} \vert 1\rangle = \begin{pmatrix} \frac{1+2i}{3}\\[2mm] -\frac{2}{3} \end{pmatrix}, \tag{2} $$then
$$ \langle 0 \vert \psi \rangle = \frac{1+2i}{3} \quad\text{and}\quad \langle 1 \vert \psi \rangle = -\frac{2}{3}. $$It must be understood when using this notation that $\langle \psi \vert$ refers to the row vector obtained by taking the conjugate-transpose of the column vector $\vert\psi\rangle$, where (in addition to transposing the vector from a column vector to a row vector) each entry is replaced by its complex conjugate.
For example, if $\vert\psi\rangle$ is the vector defined in $(2)$, then
$$ \langle\psi\vert = \frac{1-2i}{3} \langle 0\vert - \frac{2}{3} \langle 1\vert = \begin{pmatrix} \frac{1-2i}{3} & -\frac{2}{3} \end{pmatrix}. $$We can consider quantum states of systems having arbitrary classical state sets.
For example, here is a quantum state vector for an electrical fan switch:
$$ \begin{pmatrix} \frac{1}{2}\\[1mm] 0 \\[1mm] -\frac{i}{2}\\[1mm] \frac{1}{\sqrt{2}} \end{pmatrix} = \frac{1}{2} \vert\mathrm{high}\rangle - \frac{i}{2} \vert\mathrm{low}\rangle + \frac{1}{\sqrt{2}} \vert\mathrm{off}\rangle. $$The assumption here is that the classical states are ordered as high, medium, low, off. There may be no particular reason why one would want to consider a quantum state of an electrical fan switch, but it is possible in principle.
Here is another example, this time of a quantum decimal digit whose classical states are $0, 1, \ldots, 9$:
$$ \frac{1}{\sqrt{385}} \begin{pmatrix} 1\\ 2\\ 3\\ 4\\ 5\\ 6\\ 7\\ 8\\ 9\\ 10 \end{pmatrix} = \frac{1}{\sqrt{385}}\sum_{k = 0}^9 (k+1) \vert k \rangle. $$This example illustrates the convenience of writing quantum state vectors using the Dirac notation. For this particular example, the column vector representation is merely cumbersome — but if there were significantly more classical states it would become unusable. The Dirac notation, however, supports precise descriptions of large and complicated vectors in a compact form.
The Dirac notation also allows for the expression of vectors where different aspects of the vectors are indeterminate (meaning unknown or not yet established). For example, for an arbitrary classical state set $\Sigma$, we can consider the quantum state vector
$$ \frac{1}{\sqrt{|\Sigma|}} \sum_{a\in\Sigma} \vert a \rangle, $$which is a uniform quantum state over the classical states in $\Sigma$. (Here, the notation $\vert\Sigma\vert$ refers to the number of elements in $\Sigma$.)
We'll encounter much more complicated expressions of quantum state vectors in later lessons, where an expression of the quantum state vector as a column vector would be impractical or impossible. In fact, we'll mostly abandon the column vector representation of quantum state vectors, except for vectors having a small number of entries (often in the context of examples) where it is helpful to display and examine explicit vectors for some reason.
There is one more reason why expressing quantum state vectors using the Dirac notation is generally more convenient than writing column vector descriptions, and that is that it alleviates the need to explicitly specify an ordering of the classical states (or, equivalently, the correspondence between classical states and vector indices). For example, a quantum state vector for a system having classical state set $\{\clubsuit,\diamondsuit,\heartsuit,\spadesuit\}$, such as
$$ \frac{1}{2} \vert\clubsuit\rangle + \frac{i}{2} \vert\diamondsuit\rangle - \frac{1}{2} \vert\heartsuit\rangle - \frac{i}{2} \vert\spadesuit\rangle, $$is unambiguously described by this expression, and there really is no need to choose or specify an ordering of this classical state set in order to make sense of the expression. In this case, it is not difficult to simply specify an ordering of the standard card suits — for instance, we could order them as follows: $\clubsuit$, $\diamondsuit$, $\heartsuit$, $\spadesuit$. If we choose this particular ordering, the quantum state vector above is represented by the column vector
$$ \begin{pmatrix} \frac{1}{2}\\[2mm] \frac{i}{2}\\[2mm] -\frac{1}{2}\\[2mm] -\frac{i}{2} \end{pmatrix}. $$In general, however, it is convenient to simply ignore the question of how classical state sets are ordered, and to view that quantum state vectors are directly indexed by classical states. That is, conceptually speaking, there is generally no difficulty in defining or specifying an ordering of any given classical state set, but if there is no need then we need not go through the trouble.
Next let us consider what happens when a quantum state is measured, focusing on a simple type of measurement known as a standard basis measurement. (There are more general notions of measurement that will be discussed later on.)
Similar to the probabilistic setting, when a system in a quantum state is measured, the observer performing the measurement won't see a quantum state vector, but rather the result will be a classical state. In this sense, measurements act as the interface between quantum and classical information, through which classical information is extracted from quantum states.
The rule is simple: if a quantum state is measured, each classical state of the system results with probability equal to the absolute value squared of the entry in the quantum state vector corresponding to that classical state. (This is known as the Born rule in quantum mechanics.) Notice that this rule is consistent with the requirement that the absolute values squared of the entries in a quantum state vector sum to 1, as it implies that the probabilities of different classical state measurement outcomes sum to $1.$
For example, measuring the quantum state
$$ \vert + \rangle = \frac{1}{\sqrt{2}} \vert 0 \rangle + \frac{1}{\sqrt{2}} \vert 1 \rangle $$results in the two possible outcomes, $0$ and $1,$ with probabilities as follows:
$$ \operatorname{Pr}(\text{outcome is 0}) = \bigl\vert \langle 0 \vert + \rangle \bigr\vert^2 = \biggl\vert \frac{1}{\sqrt{2}} \biggr\vert^2 = \frac{1}{2}, $$$$ \operatorname{Pr}(\text{outcome is 1}) = \bigl\vert \langle 1 \vert + \rangle \bigr\vert^2 = \biggl\vert \frac{1}{\sqrt{2}} \biggr\vert^2 = \frac{1}{2}. $$Measuring the quantum state
$$ \vert - \rangle = \frac{1}{\sqrt{2}} \vert 0 \rangle - \frac{1}{\sqrt{2}} \vert 1 \rangle $$results in exactly the same probabilities for the two outcomes:
$$ \operatorname{Pr}(\text{outcome is 0}) = \bigl\vert \langle 0 \vert - \rangle \bigr\vert^2 = \biggl\vert \frac{1}{\sqrt{2}} \biggr\vert^2 = \frac{1}{2}, $$$$ \operatorname{Pr}(\text{outcome is 1}) = \bigl\vert \langle 1 \vert - \rangle \bigr\vert^2 = \biggl\vert -\frac{1}{\sqrt{2}} \biggr\vert^2 = \frac{1}{2}. $$Measuring the quantum state
$$ \vert \psi \rangle = \frac{1+2i}{3} \vert 0\rangle - \frac{2}{3} \vert 1\rangle $$produces results as follows:
$$ \operatorname{Pr}(\text{outcome is 0}) = \bigl\vert \langle 0 \vert \psi \rangle \bigr\vert^2 = \biggl\vert \frac{1+2i}{3} \biggr\vert^2 = \frac{5}{9}, $$$$ \operatorname{Pr}(\text{outcome is 1}) = \bigl\vert \langle 1 \vert \psi \rangle \bigr\vert^2 = \biggl\vert -\frac{2}{3} \biggr\vert^2 = \frac{4}{9}. $$Of course, measuring the quantum state $\vert 0\rangle$ results in the classical state $0$ with certainty, and likewise measuring the quantum state $\vert 1\rangle$ results in the classical state $1$ with certainty. This is consistent with the identification of these quantum states with the system being in the corresponding classical state, as was suggested previously.
Thus far it may not be evident why quantum information is fundamentally different from classical information. That is, when a quantum state is measured, the probability to obtain each classical state is given by the absolute value squared of the corresponding vector entry — so why not simply record these probabilities in a probability vector?
The answer, at least in part, is that the set of allowable operations that can be performed on a quantum state is different than it is for classical information. Similar to the probabilistic setting, operations on quantum states are linear mappings — but rather than being represented by stochastic matrices as in the classical case, operations on quantum state vectors are represented by unitary matrices.
A square matrix $U$ having complex number entries is unitary if it satisfies the equalities
$$ U^{\class{conjugate-transpose}{\dagger}} U = \class{identity-matrix}{\mathbb{1}} = U U^{\dagger}. $$Here, $U^{\dagger}$ is the conjugate transpose of $U$, meaning the matrix obtained by transposing $U$ and taking the complex conjugate of each entry, and $\mathbb{1}$ is the identity matrix. If either of the equalities in the equation above is true, then the other must also be true; both equalities are equivalent to $U^{\dagger}$ being the inverse of $U$:
$$ U^{-1} = U^{\dagger}. $$(Warning: if $M$ is not a square matrix, then it could be that $M^{\dagger} M = \mathbb{1}$ and $M M^{\dagger} \not= \mathbb{1}$, for instance. The equivalence of the two equalities in the first equation above is only true for square matrices.)
The condition that $U$ is unitary is equivalent to the condition that multiplication by $U$ does not change the Euclidean norm of any vector. That is, an $n\times n$ matrix $U$ is unitary if and only if $\\| U \vert \psi \rangle \\| = \\|\vert \psi \rangle \\|$ for every $n$-dimensional column vector $\vert \psi \rangle$ with complex number entries. Thus, because the set of all quantum state vectors is the same as the set of vectors having Euclidean norm equal to $1,$ we find that multiplying a unitary matrix to a quantum state vector results in another quantum state vector.
Indeed, for any choice of a system, the set of all linear mappings that always transform quantum state vectors into quantum state vectors is precisely represented by the set of unitary matrices. That is to say, the assumption that operations correspond to linear maps on state vectors, together with the decision to represent quantum states by complex unit vectors of a given dimension, leads naturally to the association of operations on quantum states with the unitary matrices of that dimension. Notice here a resemblance to the classical probabilistic case, where operations are associated with stochastic matrices, which are the ones that always transform probability vectors into probability vectors.
Which one of these is matrices is unitary?
The following list describes some important unitary operations on qubits.
Pauli operations. The four Pauli matrices are as follows:
$$
\mathbb{1} =
\begin{pmatrix}
1 & 0\\
0 & 1
\end{pmatrix},
\quad
\sigma_x =
\begin{pmatrix}
0 & 1\\
1 & 0
\end{pmatrix},
\quad
\sigma_y =
\begin{pmatrix}
0 & -i\\
i & 0
\end{pmatrix},
\quad
\sigma_z =
\begin{pmatrix}
1 & 0\\
0 & -1
\end{pmatrix}.
$$
A common notation, which we will often use, is $X = \sigma_x$, $Y = \sigma_y$, and $Z = \sigma_z$ — but be aware
that the letters $X$, $Y$, and $Z$ are also commonly used for other purposes.
The $\sigma_x$ (or $X$) operation is also called a bit flip or a NOT operation because it induces this action
on bits:
$$
\sigma_x \vert 0\rangle = \vert 1\rangle
\quad \text{and} \quad
\sigma_x \vert 1\rangle = \vert 0\rangle.
$$
The $\sigma_z$ (or $Z$) operation is also called a phase flip because it has this action:
$$
\sigma_z \vert 0\rangle = \vert 0\rangle
\quad \text{and} \quad
\sigma_z \vert 1\rangle = - \vert 1\rangle.
$$
Hadamard operation. The Hadamard operation is described by this matrix:
$$ H = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix}. $$Phase operations. A phase operation is one described by the matrix
$$
P_{\theta} =
\begin{pmatrix}
1 & 0\\
0 & e^{i\theta}
\end{pmatrix}
$$
for any choice of a real number $\theta$. The operations
$$
S = P_{\pi/2} =
\begin{pmatrix}
1 & 0\\
0 & i
\end{pmatrix}
\quad\text{and}\quad
T
= P_{\pi/4}
=
\begin{pmatrix}
1 & 0\\
0 & \frac{1 + i}{\sqrt{2}}
\end{pmatrix}
$$
are particularly important examples.
Other examples include $\mathbb{1} = P_0$ and $\sigma_z = P_{\pi}$.
All of the matrices just defined are unitary, and therefore represent quantum operations on a single qubit.
For example, here is a calculation that verifies that $H$ is unitary:
$$ \begin{aligned} \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix}^{\dagger} \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} & = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix}\\[2mm] & = \begin{pmatrix} \frac{1}{2} + \frac{1}{2} & \frac{1}{2} - \frac{1}{2}\\[2mm] \frac{1}{2} - \frac{1}{2} & \frac{1}{2} + \frac{1}{2} \end{pmatrix}\\[2mm] & = \begin{pmatrix} 1 & 0\\ 0 & 1 \end{pmatrix}. \end{aligned} $$Here is the action of the Hadamard operation on a few qubit state vectors:
$$ \begin{aligned} H \vert 0 \rangle & = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} 1\\[2mm] 0 \end{pmatrix} = \begin{pmatrix} \frac{1}{\sqrt{2}}\\[2mm] \frac{1}{\sqrt{2}} \end{pmatrix} = \vert + \rangle,\\[2mm] H \vert 1 \rangle & = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} 0\\[2mm] 1 \end{pmatrix} = \begin{pmatrix} \frac{1}{\sqrt{2}}\\[2mm] -\frac{1}{\sqrt{2}} \end{pmatrix} = \vert - \rangle,\\[2mm] H \vert + \rangle & = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} \frac{1}{\sqrt{2}}\\[2mm] \frac{1}{\sqrt{2}} \end{pmatrix} = \begin{pmatrix} 1\\[2mm] 0 \end{pmatrix} = \vert 0 \rangle,\\[2mm] H \vert - \rangle & = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} \frac{1}{\sqrt{2}}\\[2mm] -\frac{1}{\sqrt{2}} \end{pmatrix} = \begin{pmatrix} 0\\[2mm] 1 \end{pmatrix} = \vert 1 \rangle, \end{aligned} $$and
$$ \begin{aligned} H \biggl(\frac{1+2i}{3} \vert 0\rangle - \frac{2}{3} \vert 1\rangle\biggr) & = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} \frac{1+2i}{3}\\[2mm] -\frac{2}{3} \end{pmatrix}\\[2mm] & = \begin{pmatrix} \frac{-1+2i}{3\sqrt{2}}\\[2mm] \frac{3+2i}{3\sqrt{2}} \end{pmatrix}\\[2mm] & = \frac{-1+2i}{3\sqrt{2}} | 0 \rangle + \frac{3+2i}{3\sqrt{2}} | 1 \rangle. \end{aligned} $$The last of these examples is not important, but the others are well-worth summarizing more succinctly:
$$ \begin{aligned} H \vert 0 \rangle & = \vert + \rangle,\\[2mm] H \vert 1 \rangle & = \vert - \rangle,\\[2mm] H \vert + \rangle & = \vert 0 \rangle,\\[2mm] H \vert - \rangle & = \vert 1 \rangle. \end{aligned} $$It is worth pausing to consider the fact that $H\vert +\rangle = \vert 0\rangle$ and $H\vert -\rangle = \vert 1\rangle$. Consider a situation in which a qubit is prepared in one of the two quantum states $\vert +\rangle$ and $\vert -\rangle$, but where it is not known to us which one it is. Measuring either state produces the same output distribution as the other: $0$ and $1$ both appear with equal probability $1/2.$ So, doing this provides no information about which of the two states $\vert +\rangle$ and $\vert -\rangle$ was originally prepared. However, if we apply a Hadamard operation and then measure, we obtain the outcome $0$ with certainty if the original state was $\vert +\rangle$ and we obtain the outcome $1,$ again with certainty, if the original state was $\vert -\rangle$. Thus, the quantum states $\vert +\rangle$ and $\vert -\rangle$ can be discriminated perfectly. This reveals that sign changes, or more generally changes to the phases (which are also traditionally called arguments) of the complex number entries of a quantum state vector, can significantly change that state.
Here is another example, this time of the action of a $T$ operation on a plus state:
$$ T \vert +\rangle = T \biggl(\frac{1}{\sqrt{2}} \vert 0\rangle + \frac{1}{\sqrt{2}} \vert 1\rangle\biggr) = \frac{1}{\sqrt{2}} T\vert 0\rangle + \frac{1}{\sqrt{2}} T\vert 1\rangle = \frac{1}{\sqrt{2}} \vert 0\rangle + \frac{1+i}{2} \vert 1\rangle. $$Notice here that we did not bother to convert to the equivalent matrix/vector forms, and instead used the linearity of matrix multiplication together with the formulas
$$ T \vert 0\rangle = \vert 0\rangle \quad\text{and}\quad T \vert 1\rangle = \frac{1 + i}{\sqrt{2}} \vert 1\rangle. $$Along similar lines, we may compute the result of applying a Hadamard operation to the quantum state vector just obtained:
$$ \begin{aligned} H\, \biggl(\frac{1}{\sqrt{2}} \vert 0\rangle + \frac{1+i}{2} \vert 1\rangle\biggr) & = \frac{1}{\sqrt{2}} H \vert 0\rangle + \frac{1+i}{2} H \vert 1\rangle\\ & = \frac{1}{\sqrt{2}} \vert +\rangle + \frac{1+i}{2} \vert -\rangle \\ & = \biggl(\frac{1}{2} \vert 0\rangle + \frac{1}{2} \vert 1\rangle\biggr) + \biggl(\frac{1+i}{2\sqrt{2}} \vert 0\rangle - \frac{1+i}{2\sqrt{2}} \vert 1\rangle\biggr)\\ & = \biggl(\frac{1}{2} + \frac{1+i}{2\sqrt{2}}\biggr) \vert 0\rangle + \biggl(\frac{1}{2} - \frac{1+i}{2\sqrt{2}}\biggr) \vert 1\rangle. \end{aligned} $$The two approaches — one where we explicitly convert to matrix representations and the other where we use linearity and plug in the actions of an operation on standard basis states — are equivalent. We can use whichever one is more convenient in the case at hand.
Compositions of unitary operations are represented by matrix multiplication, just like we had in the probabilistic setting. For example, if we first apply a Hadamard operation, followed by the $S$ operation, followed by another Hadamard operation, the resulting operation (which we'll name $R$) is as follows:
$$ R = H S H = \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} \begin{pmatrix} 1 & 0\\ 0 & i \end{pmatrix} \begin{pmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\[2mm] \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \end{pmatrix} = \begin{pmatrix} \frac{1+i}{2} & \frac{1-i}{2} \\[2mm] \frac{1-i}{2} & \frac{1+i}{2} \end{pmatrix}. $$This unitary operation $R$ is an interesting example. By applying this operation twice, which is equivalent to squaring its matrix representation, we obtain a NOT operation:
$$ R^2 = \begin{pmatrix} \frac{1+i}{2} & \frac{1-i}{2} \\[2mm] \frac{1-i}{2} & \frac{1+i}{2} \end{pmatrix}^2 = \begin{pmatrix} 0 & 1 \\[2mm] 1 & 0 \end{pmatrix}. $$That is, $R$ is a square root of NOT operation. Such a behavior, where the same operation is applied twice to yield a NOT operation, is not possible for a classical operation on a single bit.
You can use the interactive component below to compose a sequence of qubit unitary operations. It shows you both the matrix representation of the resulting unitary operation as well as its action on the state $\vert 0\rangle$, which we take to be the default, initialized state of a qubit. To specify the sequence, drag the operations you'd like to perform on the qubit down onto the line: the leftmost operation is applied first, and the rightmost applied last. Diagrams like this represent quantum circuits, which are discussed in greater detail and generality in Lesson 3.
q-circuit-sandbox-widget(goal="single-systems-circuit-sandbox")
.availableGates X Y Z H S T
.instructions Drag the operations down onto the circuit to see how they transform the qubit.
.explanation The <strong>matrix</strong> display shows the unitary matrix of the circuit (i.e., of all the operations composed together). The <strong>state vector</strong> display shows the state of the qubit after the operations act on it.
In later lessons we will see many examples of unitary operations on systems having more than two classical states. An example of a unitary operation on a system having three classical states is given by the following matrix:
$$ A = \begin{pmatrix} \class{_u00}{0} & \class{_u10}{0} & \class{_u20}{1} \\ \class{_u01}{1} & \class{_u11}{0} & \class{_u21}{0} \\ \class{_u02}{0} & \class{_u12}{1} & \class{_u22}{0} \end{pmatrix}. $$Assuming that the classical states of the system are $0,$ $1,$ and $2,$ we can describe this operation as addition modulo $3:$
$$ A \vert 0\rangle = \vert 1\rangle, \quad A \vert 1\rangle = \vert 2\rangle, \quad\text{and}\quad A \vert 2\rangle = \vert 0\rangle. $$The matrix $A$ is an example of a permutation matrix, which is a matrix in which every row has exactly one $1,$ every column has exactly one $1,$ and every other entry is $0.$ Every permutation matrix, in any positive integer dimension, is unitary. These are the only examples of matrices that represent both classical and quantum operations: a matrix is both stochastic and unitary if and only if it is a permutation matrix.
Another example of a unitary matrix, this time being a $4\times 4$ matrix, is this one:
$$ U = \frac{1}{2} \begin{pmatrix} 1 & 1 & 1 & 1 \\ 1 & i & -1 & -i \\ 1 & -1 & 1 & -1 \\ 1 & -i & -1 & i \end{pmatrix}. $$This matrix describes an operation known as the quantum Fourier transform, specifically in the $4\times 4$ case. The quantum Fourier transform can be defined more generally, for any positive integer dimension $n$, and will play a key role in Unit 2 on quantum algorithms.
In this section we present some examples of Qiskit implementations of the concepts introduced in this lesson.
Qiskit uses the Python programming language, so before discussing Qiskit specifically it may be helpful to very briefly discuss matrix and vector computations in Python.
In Python, matrix and vector computations can be performed using the array
class from the NumPy
library (which includes many additional components for numerical computation).
Here is an example of a code cell that defines two vectors, ket0
and ket1
, corresponding to the qubit state vectors $\vert 0\rangle$ and $\vert 1\rangle$, and displays their average.
from numpy import array
ket0 = array([1, 0])
ket1 = array([0, 1])
display(ket0/2 + ket1/2)
It is not actually necessary to explicitly use the display
command to see the result of this computation.
We may instead simply write the expression of interest as the last line of the code cell, and it will be returned as its output:
ket0/2 + ket1/2
This code cell also illustrates that running code cells sequentially on a given page of this textbook has a cumulative effect, so it is not necessary to reload the array
class or define ket0
and ket1
again.
Reloading the page or switching to another page will, however, reset everything to its initial state.
As a general guideline, code cells within each numbered subsection of this course are intended to be run sequentially. So, if running a code cell generates an error, be sure to first run all previous code cells within the subsection in which that code cell appears.
We can also use array
to create matrices that represent operations.
M1 = array([[1, 1], [0, 0]])
M2 = array([[1, 1], [1, 0]])
M1/2 + M2/2
Matrix multiplication (including matrix-vector multiplication as a special case) can be performed using the matmul
function from NumPy
:
from numpy import matmul
display(matmul(M1,ket1))
display(matmul(M1,M2))
display(matmul(M2,M1))
Qiskit includes several classes that allow for states, measurements, and operations to be easily created and manipulated — so starting from scratch and programming everything that is needed to simulate quantum states, measurements, and operations in Python is not required. Some examples to get started are included below.
Qiskit's Statevector
class provides functionality for defining and manipulating quantum state vectors.
The following code cell imports the Statevector
class and defines a few vectors using it:
from qiskit.quantum_info import Statevector
from numpy import sqrt
u = Statevector([1/sqrt(2), 1/sqrt(2)])
v = Statevector([(1+2.j)/3, -2/3])
w = Statevector([1/3, 2/3])
print("State vectors u, v, and w have been defined.")
(Note that we need the sqrt
function from the NumPy
library to compute the square roots for the vector u
.)
The Statevector
class provides a draw
method for displaying state vectors, including latex
and text
options for different visualizations, as this code cell demonstrates:
display(u.draw('latex'))
display(v.draw('text'))
The Statevector
class also includes the is_valid
method, which checks to see if a given vector is a valid quantum state vector (i.e., that it has Euclidean norm equal to 1):
display(u.is_valid())
display(v.is_valid())
display(w.is_valid())
Statevector
¶Next we will see one way that measurements of quantum states can be simulated in Qiskit, using the measure
method from the Statevector
class.
First, we create a qubit state vector v
and then display it.
v = Statevector([(1+2.j)/3, -2/3])
v.draw('latex')
(Note that code cells can be modified, so go ahead and change the specification of the vector if you wish. Alternatively, you can use the scratchpad to the right for experimenting with code cells.)
Next, running the measure
method simulates a standard basis measurement.
It returns the result of that measurement, plus the new quantum state of our system after that measurement.
v.measure()
Measurement outcomes are probabilistic, so the same method can return different results. Try running the cell a few times to see this.
For the particular example of the vector v
defined above, the measure
method defines the quantum state vector after the measurement takes place to be
(rather than $\vert 0\rangle$)} or
$$ - \vert 1\rangle $$(rather than $\vert 1\rangle$), depending on the measurement outcome. In both cases the alternatives are, in fact, equivalent — they are said to differ by a global phase because one is equal to the other multiplied by a complex number on the unit circle. This issue is discussed in greater detail in Lesson 3, and can safely be ignored for now.
As an aside, Statevector
will throw an error if the measure
method is applied to an invalid quantum state vector.
Go ahead and try if you are so inclined!
Statevector
also comes with a sample_counts
method that allows for the simulation of any number of measurements on the system.
For example, the following cell shows the outcome of measuring the vector v
$1000$ times, which (with high probability) results in the outcome $0$ approximately $5$ out of every $9$ times (or about $556$ of the $1000$ trials) and the outcome $1$ approximately $4$ out of every $9$ times (or about $444$ out of the $1000$ trials).
The cell also demonstrates the plot_histogram
function for visualizing the results.
from qiskit.visualization import plot_histogram
statistics = v.sample_counts(1000)
display(statistics)
plot_histogram(statistics)
Trying different numbers of samples in place of $1000$ may be helpful for developing some intuition for how the number of trials influences the estimated probabilities.
Operator
and Statevector
¶Unitary operations can be defined and performed on state vectors in Qiskit using the Operator
class, as in the example that follows.
from qiskit.quantum_info import Operator
X = Operator([[0,1],[1,0]])
Y = Operator([[0,-1.j],[1.j,0]])
Z = Operator([[1,0],[0,-1]])
H = Operator([[1/sqrt(2),1/sqrt(2)],[1/sqrt(2),-1/sqrt(2)]])
S = Operator([[1,0],[0,1.j]])
T = Operator([[1,0],[0,(1+1.j)/sqrt(2)]])
v = Statevector([1,0])
v = v.evolve(H)
v = v.evolve(T)
v = v.evolve(H)
v = v.evolve(T)
v = v.evolve(Z)
v.draw('latex')
Quantum circuits won't be formally introduced until Lesson 3, but we can nevertheless experiment with composing qubit unitary operations using Qiskit's QuantumCircuit
class.
In particular, we may define a quantum circuit (which in this case will simply be a sequence of unitary operations performed on a single qubit) as follows.
from qiskit import QuantumCircuit
circuit = QuantumCircuit(1)
circuit.h(0)
circuit.t(0)
circuit.h(0)
circuit.t(0)
circuit.z(0)
circuit.draw()
The operations are applied sequentially, starting on the left and ending on the right in the figure. Let us first initialize a starting quantum state vector and then evolve that state according to the sequence of operations.
ket0 = Statevector([1,0])
v = ket0.evolve(circuit)
v.draw('latex')
Finally, let's simulate the result of running this experiment (i.e., preparing the state $\vert 0\rangle$, applying the sequence of operations represented by the circuit, and measuring) 4000 times.
statistics = v.sample_counts(4000)
plot_histogram(statistics)