The Bloch Sphere

The Bloch sphere is perhaps the most intuitive way in which to understand basic single qubit gates, as we can interpret them as rotations between different states. In this short blog, we will use it to build an intuition for the single qubit gates x, y, z, h, s, rx, ry, rz, and how statevectors and bases works.

bloch-sphere

 

The shots variable determines the amount of samples we use to negate some of the random noise that is simulated. Setting this lower may lead to more prevalent noise, while higher values will require more computing time.

The three variables below define three different basis. For now, we will leave them as they are and return to them a bit later in this notebook.

With our bases in place, we can now define our function for simulating a circuit and returning a statevector.

You don't need to be able to replicate the code above, but know that it samples measurements from each basis by running the circuit several times (to get reliable results, upwards of 1000 to 10000 shots are not uncommon).

Now it is time to feed the function some circuits and see how the gates transforms the statevector of the qubit!

First, here are some gates to play around with:

MethodDescription
.x(0)Flips state around x-axis
.y(0)Flips state around y-axis
.z(0)Flips state around z-axis
.h(0)Switches z and x values by flipping
around axis between |0 and x
.s(0)Switches x and y values
.rx(θ,0)Rotate θ radians around the x-axis.
.ry(θ,0)Rotate θ radians around the y-axis.
.rz(θ,0)Rotate θ radians around the z-axis.

Note that the 0's just specifies which qubit to apply the gate to. This will be useful for later multiqubit circuits!

 

png

 

Task 1: Apply each gate individually and see what it does. (Hint: If nothing happens, the gate rotates around an axis with which you are currently parallel to. Use another gate to no longer be parallel.)

Question 1: Is .ry(pi/2, 0) equivalent to the Hadamard gate,.h(0)? Why, why not?
Question 2: Does the order of the gates matter to the final position of the statevector? Question 3: Identify the axis around which the phase gate, .s(0), rotates.

Challenge 1: Construct a circuit that ends at negative x (opposite of where a single Hadamard would leave you).
Challenge 2: Construct a circuit which goes through all the poles of the x, y, and z, axes.
Challenge 3: Construct a circuit that gives equal probability of measuring 0 and 1, and x and -x if you measured a single time.
Challenge 4: Construct a circuit which gives 75% chance of measuring 1 and 25% of measuring 0 in the z basis.

Choosing a Basis

Remember how we skipped over how we measure the different bases? Let's look at it again. Unless otherwise specified, qubits are always initialized to |0, which means the qubit has a 100% chance (disregarding noise) to be measured as a 0 in the Z basis, something often called the computational basis. One can think of a basis as simply seeing how far along one of the axes the statevector is. When we measure in Qiskit, we measure the computational basis. However, this gives us no information about the x and y components of the statevector.

Challenge: Can you figure out how the bases that we've copied from above gives us information about the x and y components?

Hint: See them as quantum circuits, and send them to our simulator.

Final notes about bases: Unlike normal bits that can be either 0 or 1, the different superpositions between amplitude and phase that are intrinsic to qubits leaves us with a lot of freedom when it comes to measuring their value. While we've only mentioned the x, y, and z basis, one could imagine an infinite amount of axes within the sphere, all of which are valid bases. However, as the quantum state of qubits collaps once we measure them, we must choose our basis with care, since we only get one measurement for every time we run the circuit. That is why we set shots to such a large number above, so that we can average over many measurements, and the reason we ran a for-loop which meant we ran these many repetition for each basis. This is what allowed us to obtain all components of our statevector above.

Entanglement

Quantum entanglement is a physical phenomenon that occurs when pairs or groups of particles are generated or interact in ways such that the quantum state of each particle cannot be described independently instead, a quantum state must be described for the system as a whole. This means for an entangled system, the quantum state of composite system cannot be factored as a product of states of its local constituents.

Therefore, it can only be expressed as a sum, or superposition, of products of states of local constituents with more than one term, i.e., a state |ψ is said to be entangled if |ψ|a|b for any two subsystem states |a and |b.

Preparing Entangled States

We will try to prepare some of the most important (and popular) entangled quantum states, and also the their applications:

  1. Bell states
  2. Greenberger-Horne-Zeilinger state i.e. (GHZ state)
  3. W state

Bell States

The Bell states (or EPR states) are specific quantum states of two qubits that represent the simplest (and maximal) examples of quantum entanglement.

 

|Φ±=|00±|112 |Ψ±=|01±|102

Preparing Bell States

In quantum circuit language, the way to create a Bell pair between two qubits is to first transfer one of them to the Bell basis (|+ and |) by using a Hadamard gate, and then to apply a CNOT gate onto the other qubit controlled by the one in the Bell basis.

Implementation

 

png

 

 

 

png

 

 

png

 

 

 

png

 

Quantum Teleportation

The concept

Alice wants to send quantum information to Bob. Specifically, suppose she wants to send the state |ψ=α|0+β|1 to Bob. This entails passing on information about α and β to Bob.

There exists a theorem in quantum mechanics which states that you cannot simply make an exact copy of an unknown quantum state. This is known as the no-cloning theorem. As a result of this we can see that Alice can't simply generate a copy of |ψ and give the copy to Bob. Copying a state is only possible with a classical computation.

However, by taking advantage of two classical bits and entanglement, Alice can transfer the state |ψ to Bob. We call this teleportation as at the end Bob will have |ψ and Alice won't anymore. Let's see how this works in some detail.

How does quantum teleportation work?

Step 1: Alice and Bob create an entangled pair of qubits and each one of them holds on to one of the two qubits in the pair. The pair they create is a special pair called a Bell pair that we have discussed above.

Let's say Alice owns q1 and Bob owns q2 after they part ways.

Step 2: Alice applies a CNOT gate on q1, controlled by |ψ (the qubit she is trying to send Bob).

Step 3: Next, Alice applies a Hadamard gate to |ψ, and applies a measurement to both qubits that she owns - q1 and |ψ.

Step 4: Then, it's time for a phone call to Bob. She tells Bob the outcome of her two qubit measurement. Depending on what she says, Bob applies some gates to his qubit, q2. The gates to be applied, based on what Alice says, are as follows :

00 Do nothing

01 Apply X gate

10 Apply Z gate

11 Apply ZX gate

Note that this transfer of information is classical.

And voila! At the end of this protocol, Alice's qubit has now teleported to Bob.

Implementation

In this notebook, we will give Alice a secret state |ψ. This state will be generated by applying a series of unitary gates on a qubit that is initialized to the ground state, |0. Go ahead and fill in the secret unitary that will be applied to |0 before passing on the qubit to Alice.

If the quantum teleportation circuit works, then at the output of the protocol discussed above will be the same state passed on to Alice. Then, we can undo the applied secret_unitary (by applying its conjugate transpose), to yield the |0 that we started with.

We will then do repeated measurements of Bob's qubit to see how many times it gives 0 and how many times it gives 1.

What do we expect?

In the ideal case, and assuming our teleportation protocol works, we will always measure 0 from Bob's qubit because we started off with |0.

In a real quantum computer, errors in the gates will cause a small fraction of the results to be 1. We'll see how it looks.

1. Simulating the teleportation protocol

 

 

It's always a good idea to draw the circuit that we have generated in code. Let's draw it below.

 

png

 

 

 

png

 

Note that the results on the x-axis in the histogram above are ordered as c2c1c0. We can see that only results where c2=0 appear, indicating that the teleporation protocol has worked.

Greenberger-Horne-Zeilinger state i.e. (GHZ state)

The Greenberger-Horne-Zeilinger state is a certain type of entangled quantum state that involves at least three subsystems (qubits). For a N qubit system it is defined as: |GHZ=|0N+|1N2

Simply put, it is a quantum superposition of all subsystems being in state 0 with all of them being in state 1 (states 0 and 1 of a single subsystem are fully distinguishable). The GHZ state is a maximally entangled quantum state.

Here, we will try to prepare the simplest one, i.e. the 3-qubit GHZ state: |GHZ=|000+|1112

Preparing 3-qubit GHZ state

In quantum circuit language, the way to create a 3-qubit GHZ states is to first transfer the first qubit to the Hadamard basis (|+ and |) by using a Hadamard gate, and then to applying two CNOT gates in pairwise fashion: (CNOT(0,1), CNOT(1,2)).

Implementation

 

png

 

 

 

png

 

[#1] Challenge

Devise an algorithm to prepare the following generalized GHZN state: |GHZN=|0N+|1N2

W state

The W state is an entangled quantum state of three qubits which has the following shape: W=|001+|010+|1003

 

Preparing W state

We saw that construction of both Bell states and GHZ state was quite straight forward. However, preparing W state is quite tricky as its (one of the simplest) preparation make use of a custom gate G(p) and anti-controlled gates.

G(p)=[1ppp1p]

This can be implemented as a U3(θ,ϕ,λ) gate with ϕ=λ=0, which amounts to a standard SU(2) representation of a rotation of angle θ around the y-axis.

U3(θ,ϕ,λ)=[cosθ2eιλsinθ2eιϕsinθ2eι(λ+ϕ)cosθ2]

Therefore, in our case for p=1/3, we have θ=2×cos11p. Moreover, the anti-controlled gates can be implemented ACU=XCUX, i.e. sandwiching controlled gate bebtween two X gates.

Implementation

 

png

 

 

 

png

 

[#2] Challenge

Devise an algorithm to prepare the following generalized WN state: |WN=|0001++|0100+|1000N

Entanglement Swapping

Entanglement Swapping is a technique to implement quantum correlation in a system. This is done via measurements on one particle of the each of the two pairs of entangled particles, leaving the unmeasured particles correlated. This messes up with the normal expectation of correlations as two particles who never had shared a common past now are correlated, and affect measurements per-formed on each other.

Description:

Alice has one particle, Bob two, and Carol one. Alice's particle and Bob's first particle are entangled, and so are Bob's second and Carol's particle. Now, if Bob does a projective measurement on his two particles in the Bell state basis and communicates the results to Carol, as per the teleportation scheme described above, the state of Bob's first particle can be teleported to Carol's. Although Alice and Carol never interacted with each other, their particles are now entangled.

Implementation

 

png

 

 

 

png

 

The really important thing to realize is that, after that Bell basis measurement, Alice and Carol could be in one of many possible entangled states. Their qubits might be entangled to agree along the X axis, or to disagree. They also might agree or disagree along the Z axis. Concretely speaking, they could be in the state |00+|11, or in the state |01+|10, or in the state |00|11, or in the state |01|10.

But then there's still Bob's measurement results. They reveal which entangled case Alice and Carol ended up in. Bob knows their state's X-parity and its Z-parity. All Bob has to do is tell Alice and Carol "Hey, the Z-parity came out 'disagree' so one of you flip your qubit 180 degrees around the X axis to fix that". Do the same for the X-parity, and the problem is solved: Alice and Carorl will definitely end up in the state |00+|11 after the corrections. Therefore, although Alice and Carol never interacted with each other, their particles are now entangled.