# Decoherence¶

Real quantum computers must deal with decoherence, or the loss of information due to environmental disturbances (noise). The Bloch vector formalism we introduced in the previous section is sufficient to describe the state of the system under decoherence processes. The pure states we have studied so far have a Bloch vector of length 1, touching the surface of the Bloch sphere, and can be represented in density matrix form as $$\rho=| \psi\rangle \langle \psi |$$. Decoherence causes a change in our quantum states from pure to mixed states, which have a density matrix $$\rho$$ that can be written as a sum over pure states

$$\rho = \sum_k p_k | \psi_k\rangle \langle \psi_k |$$

and a Bloch vector that sits inside the Bloch sphere

$$|\langle X\rangle|^2 + |\langle Y\rangle|^2 + | \langle Z\rangle|^2 < 1$$.

## Energy relaxation and $$T_1$$¶

One important decoherence process is called energy relaxation, where the excited $$|1\rangle$$ state decays toward the ground state $$|0\rangle$$. The time constant of this process, $$T_1$$, is an extremely important figure-of-merit for any implementation of quantum computing, and one in which IBM has made great progress in recent years, ultimately leading to the prototype quantum computer you are now using. Experiment with the circuits below to see how adding many repetitions of additional do-nothing Idle $$Id$$ gates (or Identity gates; these are gates that do nothing but wait) before measurement causes the state to gradually decay towards $$|0\rangle$$.

Below is a QISKit script for measuring $$T_1$$.

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 42 43 44 45 46 47 48 49 # t1.py import numpy as np import matplotlib.pyplot as plt from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, register import Qconfig register(Qconfig.APItoken, Qconfig.config['url']) # Define the Quantum and Classical Registers q = QuantumRegister(1) c = ClassicalRegister(1) # Build the circuits pre = QuantumCircuit(q, c) pre.x(q) pre.barrier() meas = QuantumCircuit(q, c) meas.measure(q, c) circuits = [] exp_vector = range(1,51) for exp_index in exp_vector: middle = QuantumCircuit(q, c) for i in range(45*exp_index): middle.iden(q) circuits.append(pre + middle + meas) # Execute the circuits shots = 1024 job = execute(circuits, 'ibmqx4', shots=shots, max_credits=10) result = job.result() # Plot the result exp_data = [] exp_error = [] for exp_index in exp_vector: data = result.get_counts(circuits[exp_index-1]) try: p0 = data['0']/shots except KeyError: p0 = 0 exp_data.append(p0) exp_error.append(np.sqrt(p0*(1-p0)/shots)) plt.errorbar(exp_vector, exp_data, exp_error) plt.xlabel('time [45*gate time]') plt.ylabel('Pr(0)') plt.grid(True) plt.show() 

## Dephasing and $$T_2$$¶

Dephasing is another decoherence process, and unlike energy relaxation, it affects only superposition states. It can be understood solely in a quantum setting as it has no classical analog. The time constant $$T_2$$ includes the effect of dephasing as well as energy relaxation, and is another crucial figure-of-merit. Again, IBM has some of the world’s best qubits by this metric. Practice with the scripts below to investigate the Ramsey and echo experiments. A Ramsey experiment measures $$T_2^*$$, which can be affected by slow noise, and the echo experiment removes some of this noise.

Below is a QISKit script for measuring $$T_2^*$$ (Ramsey) and $$T_2$$ (echo).

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 42 43 44 45 46 47 48 49 50 51 52 53 54 # t2_ramsey.py import numpy as np import matplotlib.pyplot as plt from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, register import Qconfig register(Qconfig.APItoken, Qconfig.config['url']) # Define the Quantum and Classical Registers q = QuantumRegister(1) c = ClassicalRegister(1) # Build the circuits pre = QuantumCircuit(q, c) pre.h(q) pre.barrier() meas_x = QuantumCircuit(q, c) meas_x.barrier() meas_x.h(q) meas_x.measure(q, c) circuits = [] exp_vector = range(1,51) phase = 0.0 for exp_index in exp_vector: middle = QuantumCircuit(q, c) phase = phase + 6*np.pi/len(exp_vector) middle.u1(phase,q) for i in range(5*exp_index): middle.iden(q) circuits.append(pre + middle + meas_x) # Execute the circuits shots = 1024 job = execute(circuits, 'ibmqx4', shots=shots, max_credits=10) result = job.result() # Plot the result exp_data = [] exp_error = [] for exp_index in exp_vector: data = result.get_counts(circuits[exp_index-1]) try: p0 = data['0']/shots except KeyError: p0 = 0 exp_data.append(p0) exp_error.append(np.sqrt(p0*(1-p0)/shots)) plt.errorbar(exp_vector, exp_data, exp_error) plt.xlabel('time [5*gate time]') plt.ylabel('Pr(+)') plt.grid(True) plt.show() 
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 # t2_echo.py import numpy as np import matplotlib.pyplot as plt from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, register import Qconfig register(Qconfig.APItoken, Qconfig.config['url']) # Define the Quantum and Classical Registers q = QuantumRegister(1) c = ClassicalRegister(1) # Build the circuits pre = QuantumCircuit(q, c) pre.h(q) pre.barrier() meas_x = QuantumCircuit(q, c) meas_x.barrier() meas_x.h(q) meas_x.measure(q, c) circuits = [] exp_vector = range(1,51) for exp_index in exp_vector: middle = QuantumCircuit(q, c) for i in range(15*exp_index): middle.iden(q) middle.x(q) for i in range(15*exp_index): middle.iden(q) circuits.append(pre + middle + meas_x) # Execute the circuits shots = 1024 job = execute(circuits, 'ibmqx4', shots=shots, max_credits=10) result = job.result() # Plot the result exp_data = [] exp_error = [] for exp_index in exp_vector: data = result.get_counts(circuits[exp_index-1]) try: p0 = data['0']/shots except KeyError: p0 = 0 exp_data.append(p0) exp_error.append(np.sqrt(p0*(1-p0)/shots)) plt.errorbar(exp_vector, exp_data, exp_error) plt.xlabel('time [31*gate time]') plt.ylabel('Pr(+)') plt.grid(True) plt.show() 

## Progress in decoherence with superconducting qubits¶

Because $$T_2$$ is such an important quantity, it is interesting to chart how far the community of superconducting qubits has come over the years. Here is a graph depicting $$T_2$$ versus time.