2 Single
2 Single
In our Apple gedanken, the qubit is person while inside rooms and corridors. It could have all
kinds of thoughts about apples while in there, but once we observe from which door it exited, it
collapses to either a yes or a no person, i.e. the qubit becomes a bit.
A qubit can be realized using any two-state quantum system. Examples include: a photon (with
transmitted versus reflected states); a photon (with horizontal versus vertical polarization); an
electron or a nucleus (with spin up versus down); and a superconducting loop with Josephson
junctions (with clockwise versus counterclockwise current).
2. The State
The state of a qubit (its information content) before a measurement is a superposition of the
two possible outcomes of that measurement. There are a number of mathematical structures
capable of representing such a two-entity superposition (a point in a plane, a vector, a column
vector, an ordered pair, etc.) and we will go with a vector. And as noted in the Apple Gedanken
experiment, this vector must have a norm (length) associated with it (so we can normalize it)
and must be scalable by a complex number (so we can represent speakers). Finally, in order to
accommodate superposition, we need to be able to add these vectors.
The vector that represents a qubit in state s can be written as s (in bold), or as s with an arrow
on top, or using Dirac's bra-ket notation, which we will adopt throughout. In this notation, the
vector is written as a ket |s>.
A set of elements (vectors) that have an addition operation + (defined with the typical commu-
tative group properties), a multiplication * by a scalar field (complex numbers), and a distribu-
tive behaviour of * over + is known as a vector space. And if we augment this space with a dot
product that allows us to define a distance metric (and thus norm) in a complete way, we end
up with what is known as a Hilbert space.
where ⍺ and β are complex numbers known as the components (or projections) of the state
along the two basis vectors. In this basis, we can also represent |s> using the column vector:
"
! $
#
If we take the adjoint of |s> (transpose and complex conjugate), we get the row vector:
(" ∗ #∗ )
which is denoted using the bra-ket notation with the bra: <s|.
It should be noted that our vector space has infinitely many bases. Any two unit-length vectors
that are not multiples of each other can be used to form a basis.
Dot Product
Given two vectors, |s> (with components s1 and s2) and |t> (with components t1 and t2), their
inner product (aka dot product) denoted by <s|t> (or s ⋅ t) is defined as the complex number:
The first property allows us to define the norm (or length) of a vector as:
And as noted earlier, there are infinitely many bases in the vector space and all of which are
orthonormal. Let |x>, |y> be the vectors of a non-standard base, and note the followings:
• By Orthonormality
<x|x> = <y|y> = 1 and <x|y> = <y|x> = 0
• Change of Basis
If |s> = ⍺|0> + β|1> then we can also express it in the (x,y) basis as: |s> = ⍺'|x> + β'|y>,
where ⍺', β' are the components (or projections) of |s> on |x> and |y>. To compute
them, multiply both sides of the first expression by the bra <x| and again by <y|:
|s> = ⍺|0> + β|1> => <x|s> = ⍺<x|0> + β<x|1> => ⍺' = ⍺<x|0> + β<x|1>
|s> = ⍺|0> + β|1> => <y|s> = ⍺<y|0> + β<y|1> => β' = ⍺<y|0> + β<y|1>
Hence:
Global Phase
A vector |s> = ⍺|0> + β|1> that represents a qubit must be normalized. Hence:
The global phase g has no physical meaning (it has no implication) and can be dropped. In other
words, all state vectors that have the same θ and ' are considered equivalent regardless of the
Bloch Sphere
Since the qubit state can expressed as a linear combination of |0> and |1>, one is tempted to
visualize it as a 2D vector with |0> being the unit vector of the horizontal x-axis and |1> the unit
vector on the vertical y-axis. This picture would be valid if both components are real but is very
deceptive otherwise. We will therefore employ a different
geometric view, the Bloch sphere, as shown. The sphere has
a radius of 1, and its surface represents all the possible qubit
states. The qubit state vector (from the centre to a point on
the surface) is normalized and makes the two angles, θ and
3, as shown. Notice how |0> and |1> are not perpendicu-
lar in this view—they are along the +z and -z axis.
3. Transformations
Devices that modify the qubit state without learning anything about its current state (no leak of
information) are transformations that take one vector to another within the Hilbert space. In
the Apple Gedanken experiment, the rooms are such devices. In physical realizations, beam
splitters, glass plates, magnetic fields, or microwave pulse (depending on how the qubit is rea-
lized) are used to modify the state of the qubit, e.g. take it from |0> to |1> or from one super-
position to another. The time evolution of a closed system is also a state transformation.
Mathematically, transformations appear as operators in the state space, and once a basis is
chosen, these operators can be represented by matrices.
Linearity
All transformations in the quantum world are linear, i.e. given a transformation T,
T (⍺|0> + β|1>) = ⍺T|0> + β T|1>
Linearity is very useful in quantum computing because it tells us how a device will act on a qubit
in a superposition state if we know how it acts on classical bits (the basis vectors). Linearity also
justifies using matrices to represent transformations.
Unitarity
All transformations in the quantum world preserve the normalization of the state, and this is
achieved by requiring unitarity. A transformation matrix T is unitary if:
T Unitary ⇔ T†T = T T† = I
where T† is the adjoint (complex conjugate of the transpose) of T. And from the above equality,
we see that T† is no other than T-1, the inverse of T.
Reversibility
All transformations in the quantum world are reversible. Mathematically, this is a consequence
of unitarity because the inverse of a unitary matrix exists, so we can apply it to the output of
the device to reproduce its input. For computing, this is quite a contrast to classical gates (the
building blocks of computers), such as OR and AND, which are non-reversible.
4. Measurement
Unlike a transforming device, a measuring device seeks to glean information about the state of
the system, and it does so in an odd way. Specifically:
• Each measuring device has its own basis for the vector space. Let |e1> and |e2> denote the
two basis vectors of that basis.
• Given a vector |s> to be measured, the device computes its components ⍺ and β along the
|e1> and |e2>.
• The system is forced to collapse to (i.e. become) either |e1> or |e2>. The choice is random
but not uniformly so. It chooses |e1> with probability |⍺|2 and |e2> with probability |β|2.
The following key points must be kept in mind vis-à-vis measurement and collapse:
A. Once a measurement is made, the collapsed state of the system does not change (assuming
the system does not interact with anything). In other words, no matter how many times the
measurement is repeated, the outcome will stay the same.
B. Randomness is intrinsic in Nature. Unless the state vector happened to be along one of the
basis vectors of the measuring device (in which case the outcome is certain to be the state),
the outcome is truly random and has a distribution derived from the components of the
state vector along the vectors of the measurement basis. This is in stark contrast with our
classical world in which randomness is a convenience that covers our inability to know the
initial condition exactly or to cope with complexity.
C. We cannot determine the state of a given qubit exactly. In fact, we cannot even determine
it probabilistically because once we measure, the state collapses. The only way out would
be to make many copies of that state (an ensemble) and then measure all the copies to
obtain stats about the various outcomes. Alas, it is not possible to copy a state as shown by
the following theorem:
The post-measurement collapse and the inability to copy states sounds ominous for
quantum computing. For even if we benefited from the rich information content and the
rich parallelism of the quantum world, the results of any computation we do there is
seemingly inaccessible to us. We will see later that clever transformations in the quantum
world before we measure, can put the result state in a form that is useful to us even after it
collapses.
D. We cannot always distinguish two given states exactly. Even if we know exactly the states
of two qubits, and we just want to know which is which, we cannot perform a measurement
to tell them apart in all cases. If the two vectors are identical, then there is nothing to do. If
they are orthogonal, then we measure using them as basis, and in that case, the outcomes
would be 0 for one of them, 1 for the other. In all other cases (i.e. vectors neither parallel
not perpendicular), the outcomes are probabilistic and cannot distinguish the two exactly.
E. A measuring device is designed to measure some observable, e.g. the spin of an electron.
Mathematically, that observable is represented by a Hermitian matrix (one that is equal to
its adjoint). The eigenvectors of that matrix define the device's basis. The act of forcing the
state to become one of the basis vectors is thus by a projection operator (or a matrix). The
outcome of the measurement is the eigenvalue of the chosen eigenvector. For example, to
force the state to be along |0>, we use the projector |0><0| or the matrix [ 1,0], [0,0] ].
• A qubit in state (2|0> + |1>)/√5 is measured in the standard basis. Show that the outcome of
the measurement will be the bit 0 80% of the time. But if we measure in the Hadamard basis
then the state will collapse to |+> 90% of the time.
• What is wrong with this argument: "A qubit in pure state |0> is measured in the +/− basis.
Given the 1/√2 amplitude, the measurement outcome is certain to be ½"?
5. Gates
When transformations are performed as part of a computation (an algorithm), we call them
gates and use circuit-derived terminology such as input and output. Hence, gates are always
linear, unitary, and reversible, and are represented by operators or matrices.
To specify the function or purpose of a gate, we often specify how the gate acts on a classical
bit and then invoke linearity to determine how it acts on a qubit. To obtain the matrix of the
gate, we can do so by inspection, given the gate's function, or use projection operators (outer
products). Here is an example:
Two other gates, Hadamard and Phase, are used frequently in quantum algorithms. The first is
denoted by H and it turns the standard 0/1 basis to the Hadamard +/− basis. Based on this, we
can see that its operator and matrix are:
1 1
2 = |+>< 0| + |−>< 1| ⇒ 2 = 1/√2 D E
1 −1
The phase gate applies a phase to either or both components of a qubit. We can always pull out
and drop a global phase and leave only the phase on the second component. Hence:
1 0
;ℎ=>? = D E
0 ? $'
If θ = π/2 (the phase is i) then this gate is often denoted by S or P, and if θ = π/4 then this gate is
often denoted by T.
• What does the Z matrix do? Express it as the sum of two outer products.
• The Hadamard matrix turns |0> to |+> and |1> to |–>. Create its matrix via outer products.
• Compute X@Y (@ is matrix multiplication) and express it in terms of a Pauli matrix.
• Show that the Hadamard gate takes |x> to [ |0> + (−1)x |1> ] / √2, where x is either 0 or 1.
• Why is 1/√2 x [ [exp(ipi/4), exp(−ipi/4], [exp(−ipi/4), exp(ipi/4] ] known as the square root of
the X gate. It takes 0 not to 1 but halfway to 45 degrees …
• Prove that X = HZH.
6. Gates by Code
Rather than doing matrix operations by hand, we can use a programming language to do it for
us. Python is a light-weight programming language that has a library called NumPy intended for
scientific computations, including linear algebra. For example, to build the X gate from the sum
of two outer products |0><1| + |1><0|, we start by importing the library module and giving it
an abbreviated name np:
import numpy as np
In this module, vectors and matrices are called arrays. So to define the ket |0>, which is a
column vector with 1 on top and 0 below, we write:
ket0 = np.array([[1],[0]])
To define the corresponding bra <0|, which is the adjoint of |0>, we transpose the above ket
and complex conjugate the elements to obtain the row vector:
bra0 = np.conjugate(ket0.T)
Similarly for |1> and <1|:
ket1 = np.array([[0],[1]])
bra1 = np.conjugate(ket1.T)
Finally, we compute the two outer products (aka Kronecker product) and add them:
x = np.kron(ket0, bra1) + np.kron(ket1, bra0)
You can insert print statements throughout to see what is being computed, e.g.
print("ket0: \n", ket0)
print("x: \n", x)
2. Indicate the number of classical bits needed for the computation. All quantum algorithms
end up in some measurement and in qiskit, the outcome of any measurement is stored in a
classical bit. These bits are also collectively known as the classical register, and you create it
using a statement like this:
c = ClassicalRegister(1,'c')
The left-hand-side variable c holds this register; the "1" parameter means only one qubit is
needed, and the final 'c' is an arbitrary label that we attach to this register, and it appears in
the circuit diagram. It can be any label you like.
4. Initialize the input, i.e. specify the initial state of the qubits in the quantum register:
qc.initialize([1,0], q)
This function takes an array to indicate the initial state and the name of the quantum regis-
ter. In our example, the register holds only 1 qubit so the array has only two elements.
import numpy as np
from qiskit import *
backend = Aer.get_backend('qasm_simulator')
q = QuantumRegister(1,'q')
c = ClassicalRegister(1,'c')
qc = QuantumCircuit(q,c)
qc.initialize([1,0], q)
qc.x(q[0])
qc.h(q[0])
qc.measure(q,c)
print(qc.draw(output='text'))
job = execute(qc, backend, shots=1000)
result = job.result()
counts = result.get_counts()
print(counts)
Finally, we show three Qiskit features that I find very instructive: the ability to track the state
vector ket along the circuit; the ability to see the state vector on the Bloch sphere; and the
ability to use a custom gate:
qc.initialize([1,0], q)
qc.save_statevector(label='v0')
qc.x(q[0])
qc.save_statevector(label='v1')
qc.h(q[0])
qc.save_statevector(label='v2')
qc.measure(q,c)
for i in range(0,3):
print("At barrier "+str(i)+":")
print(np.asarray(result.data(0)['v'+str(i)]))