# Introducing Qubit Phase¶

In the last two sections we covered the bit-flip and the Hadamard gate. These allow us to to make the single-qubit quantum states $$\{|0\rangle, |1\rangle, |+\rangle, |-\rangle\}$$, and have introduced us to quantum superpositions. However, a general single-qubit quantum state has even richer qualities. As we have already mentioned, a single-qubit quantum state can be written as $$|\psi\rangle=\alpha |0\rangle + \beta |1\rangle$$, where $$\alpha$$ and $$\beta$$ are complex numbers with the probability constraint $$|\alpha|^2+|\beta|^2=1$$. Furthermore, the global phase of a quantum state is not detectable; therefore, $$|\psi\rangle$$ is the same as $$e^{i\gamma}|\psi\rangle$$.

An alternative representation of a single-qubit state that incorporates both of these constraints can be written as

$~~~~~~~~|\psi\rangle = \sqrt{p}|0\rangle + e^{i\phi} \sqrt{1-p} |1\rangle,$

where $$0 \leq p \leq 1$$ is the probability of the bit being in the 0 state, and $$0\leq \phi < 2\pi$$ is the quantum phase. The set of quantum gates, generated by $$\{H,T\}$$, makes it possible to reach all different values of $$p$$ and $$\phi$$. In the later sections we will show how this can be done in principle, and introduce the advanced gates in the IBM Q Experience to give finer control. First, however, we would like to develop an intuition for quantum phase by examining the $$T$$ gate. The $$T$$ gate applies a phase of $$\pi/4$$, and has a matrix representation of

$\begin{split}~~~~~~~~T =\begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}.\end{split}$

If we start with a system initially in the $$|+\rangle$$ (which is done using the Hadamard), then apply multiples of the $$T$$ gate and measure in the x-basis, we can map out this phase. These experiments are defined by the following eight scores:

OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 //Quantum Phase exp 0 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; // None barrier q; h q; measure q -> c; 
OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 //Quantum Phase exp 1 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; t q; barrier q; h q; sdg q; measure q -> c; 
OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 //Quantum Phase exp 2 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; t q; t q; barrier q; h q; measure q -> c; 
OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 //Quantum Phase exp 3 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; t q; t q; t q; barrier q; h q; measure q -> c; 
OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 //Quantum Phase exp 4 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; t q; t q; t q; t q; barrier q; h q; measure q -> c; 
OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 //Quantum Phase exp 5 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; t q; t q; t q; t q; t q; barrier q; h q; measure q -> c; 
OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 //Quantum Phase exp 6 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; t q; t q; t q; t q; t q; t q; barrier q; h q; measure q -> c; 
OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 //Quantum Phase exp 7 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; t q; t q; t q; t q; t q; t q; t q; barrier q; h q; measure q -> c; 
QISKit example
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 # quantum_phase.py import numpy as np from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer # Define the Quantum and Classical Registers q = QuantumRegister(1) c = ClassicalRegister(1) # Build the circuits circuits = [] pre = QuantumCircuit(q, c) pre.h(q) pre.barrier() middle = QuantumCircuit(q, c) meas_x = QuantumCircuit(q, c) meas_x.barrier() meas_x.h(q) meas_x.measure(q, c) exp_vector = range(0,8) for exp_index in exp_vector: circuits.append(pre + middle + meas_x) middle.t(q) # Execute the circuits shots = 1024 job = execute(circuits, backend = Aer.get_backend('qasm_simulator'), shots=shots, seed=8) result = job.result() # Print the result for exp_index in exp_vector: data = result.get_counts(circuits[exp_index]) try: p0 = data['0']/shots except KeyError: p0 = 0 try: p1 = data['1']/shots except KeyError: p1 = 0 print('exp {}: [{}, {}] X length = {}'.format(exp_index, p0, p1, p0-p1)) 

Here, QISKit gives us a nice advantage, as we can simply loop over the different circuits.

The results are summarized in the following table, where X length is the result of probability 0 minus probability 1. You can think of it as the length of the x measurement.

Experiment Phase angle Gates Prop 0 Prob 1 X length
0 0   1 0 1
1 $$\pi/4$$ $$T$$ 0.8535533 0.1464466 0.7071067
2 $$\pi/2$$ $$T^2$$ 0.5 0.5 0
3 $$3\pi/4$$ $$T^3$$ 0.1464466 0.8535533 -0.707106
4 $$\pi$$ $$T^4$$ 0 1 -1
5 $$5\pi/4$$ $$T^5$$ 0.8535533 0.1464466 0.7071067
6 $$3\pi/2$$ $$T^6$$ 0.5 0.5 0
7 $$7\pi/4$$ $$T^7$$ 0.1464466 0.8535533 -0.707106

Note: To get these values, you might need to set the number of shots to be much larger than 1024.

You have probably noticed that there are additional gates: $$\{Y,Z,S,S^\dagger,$$ $$T^\dagger\}$$, and a CNOT (that we will touch on later) available in the Composer. All of these gates can be built from the $$\{H,T,$$ and $$X\}$$.

$\begin{split}~~~~~~~~S =\begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} := T^2, ~~~~~~~~Z =\begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} := T^4, ~~~~~~~~S^\dagger =\begin{pmatrix} 1 & 0 \\ 0 & -i \end{pmatrix} := T^6, ~~~~~~~~T^\dagger =\begin{pmatrix} 1 & 0 \\ 0 & e^{-i\pi/4} \end{pmatrix} := T^7\end{split}$

and

$\begin{split}~~~~~~~~Y =\begin{pmatrix} 0 & -i \\ i & 0 \end{pmatrix} := XZ\end{split}$

The coloring denotes the group properties. All the green gates form a group known as the Pauli group, and can be made by $$\{X, Z\}$$. The blue set forms a group called the Clifford group, and can be made by $$\{H, S\}$$ (Note the Pauli group can be made using these). The red gates are the non-Clifford gates.

Now that we have a good understanding of the standard gates, we can define a third basis, the circular (or $$Y$$) basis: $$|\circlearrowright\rangle = \frac{1}{\sqrt{2}}(|0\rangle+i|1\rangle)$$$$|\circlearrowleft\rangle = \frac{1}{\sqrt{2}}(|0\rangle-i|1\rangle)$$. To make the $$|\circlearrowright\rangle$$ state from the $$|0 \rangle$$ state, use a $$H$$ gate followed by an $$S$$ gate. Try to figure out how to get the $$|\circlearrowleft\rangle$$ on your own.

To measure in this basis, we must rotate the computation basis ($$Z$$) to the circular basis ($$Y$$). To do this, use an $$S^\dagger$$ followed by $$H$$ before your measurement. See below for an example score (the other seven would be similar to before) and a QISKit example, to map out the quantum phase experiment above projected into the circular basis.

OpenQasm Input
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 //Quantum Phase exp 0 OPENQASM 2.0; include "qelib1.inc"; // Register declarations qreg q[1]; creg c[1]; // Quantum Circuit h q; barrier q; // None barrier q; sdg q; h q; measure q -> c; 
QISKit example
  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 # quantum_phase_meas_y.py import numpy as np from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer # Define the Quantum and Classical Registers q = QuantumRegister(1) c = ClassicalRegister(1) # Build the circuit circuits = [] pre = QuantumCircuit(q, c) pre.h(q) pre.barrier() middle = QuantumCircuit(q, c) meas_y = QuantumCircuit(q, c) meas_y.barrier() meas_y.s(q).inverse() meas_y.h(q) meas_y.measure(q, c) exp_vector = range(0,8) for exp_index in exp_vector: circuits.append(pre + middle + meas_y) middle.t(q) # Execute the circuits shots = 1024 job = execute(circuits, backend = Aer.get_backend('qasm_simulator'), shots=shots, seed=8) result = job.result() # Print the result for exp_index in exp_vector: data = result.get_counts(circuits[exp_index]) try: p0 = data['0']/shots except KeyError: p0 = 0 try: p1 = data['1']/shots except KeyError: p1 = 0 print('exp {}: [{}, {}] Y length = {}'.format(exp_index, p0, p1, p0-p1)) 
Experiment Phase angle Gates Prop 0 Prob 1 Y length
0 0   0.5 0.5 0
1 $$\pi/4$$ $$T$$ 0.8535533 0.1464466 0.7071067
2 $$\pi/2$$ $$T^2$$ 1.0 0 1
3 $$3\pi/4$$ $$T^3$$ 0.8535533 0.1464466 0.7071067
4 $$\pi$$ $$T^4$$ 0.5 0.5 0
5 $$5\pi/4$$ $$T^5$$ 0.1464466 0.8535533 -0.707107
6 $$3\pi/2$$ $$T^6$$ 0 1 -1
7 $$7\pi/4$$ $$T^7$$ 0.1464466 0.8535533 -0.707106