Creating superpositions

Up to this point, our system has behaved like a classical bit. To go beyond classical behavior, we must explore what it means to make a superposition. The operation for generating a superposition is the Hadamard gate, H . In Circuit Composer, this is the blue gate labeled H .

The simple score to make a superposition is given below. It starts with placing the H gate on one of the qubits (which starts in the |0\rangle state) and a standard measurement. Run the example below.

Superposition state

OpenQasm Input

//Superposition State
OPENQASM 2.0;
include "qelib1.inc";

// Register declarations
qreg q[1];
creg c[1];

// Quantum Circuit
h q;
measure q -> c;

Qiskit example

# superposition_state.py
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer

# Define the Quantum and Classical Registers
q = QuantumRegister(1)
c = ClassicalRegister(1)

# Build the circuit
superposition_state = QuantumCircuit(q, c)
superposition_state.h(q)
superposition_state.measure(q, c)

# Execute the circuit
job = execute(superposition_state, backend = Aer.get_backend('qasm_simulator'), shots=1024)
result = job.result()

# Print the result
print(result.get_counts(superposition_state))

Did you find that the results give a 0 half the time, and a 1 the rest of the time? Indeed, much like flipping a fair coin, the results are close to 50/50 (running on the real device will give less-than-ideal results, due to noise and errors).

However, quantum randomness is much different. Let’s see how. Run the experiment again, but this time with two H gates in succession. If we consider the H gate to be analog to a coin flip, here we would be flipping it twice. When you flip a coin twice in a row, you would still expect a 50/50 distribution. Below is a quantum score for this experiment; run the example.

Superposition state X-basis

OpenQasm Input

//Superposition State in X Basis
OPENQASM 2.0;
include "qelib1.inc";

// Register declarations
qreg q[1];
creg c[1];

// Quantum Circuit
h q;
barrier q;
h q;
measure q -> c;

Qiskit example

# superposition_state_xbasis.py
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer

# Define the Quantum and Classical Registers
q = QuantumRegister(1)
c = ClassicalRegister(1)

# Build the circuit
superposition_state_xbasis = QuantumCircuit(q, c)
superposition_state_xbasis.h(q)
superposition_state_xbasis.barrier()
superposition_state_xbasis.h(q)
superposition_state_xbasis.measure(q, c)

# Execute the circuit
job = execute(superposition_state_xbasis, backend = Aer.get_backend('qasm_simulator'), shots=1024)
result = job.result()

# Print the result
print(result.get_counts(superposition_state_xbasis))

This time, the results are surprising. Unlike the classical case, with high probability the outcome is not random, but in the |0\rangle state. Quantum randomness is not simply like a classical random coin flip. In both of the above experiments, the system (without noise) is in a definite state, but only in the first case does it behave randomly. This is because, in the first case, via the H gate, we make a uniform superposition of the ground and excited state, |+\rangle=(|0\rangle+|1\rangle)/\sqrt{2} , but then follow it with a measurement in the computational basis. The act of measurement in the computational basis forces the system to be in either the |0\rangle state or the |1\rangle state with an equal probability. In the second case, we can think of the second H gate as being part of the final measurement operation; it changes the measurement basis from the computational basis to a new basis - which we call the superposition basis, or x-basis. The experiment confirms this by giving the result 0, showing the system is in the |+\rangle superposition state.

Before we give the math to explain this, let’s consider two more experiments. The first puts the qubit in the excited state, then applies the H gate. The score for this is below; run it and you will see that we get the same 50/50 statistics as the first experiment.

Negative superposition state

OpenQasm Input

//Negative Superposition State
OPENQASM 2.0;
include "qelib1.inc";

// Register declarations
qreg q[1];
creg c[1];

// Quantum Circuit
x q;
h q;
measure q -> c;

Qiskit example

# negative_superposition_state.py
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer

# Define the Quantum and Classical Registers
q = QuantumRegister(1)
c = ClassicalRegister(1)

# Build the circuit
negative_superposition_state = QuantumCircuit(q, c)
negative_superposition_state.x(q)
negative_superposition_state.h(q)
negative_superposition_state.measure(q, c)

# Execute the circuit
job = execute(negative_superposition_state, backend = Aer.get_backend('qasm_simulator'), shots=1024)
result = job.result()

# Print the result
print(result.get_counts(negative_superposition_state))

The second experiment consists of first preparing the qubit in the excited state, applying the H gate (putting it in a superposition), and then measuring in the x-basis (another H gate followed by a measurement). Here we find with high probability that the system gives outcome 1. This tells us that the state just before the x-basis measurement was a superposition that was orthogonal to the |+\rangle state. By definition, this state has to be |-\rangle=(|0\rangle-|1\rangle)/\sqrt{2} . That is, the H gate transforms the computational basis into a new basis, the superposition basis, defined by the set \{|+\rangle, |-\rangle\} .

Negative superposition state X-basis

OpenQasm Input

//Negative Superposition State X Basis
OPENQASM 2.0;
include "qelib1.inc";

// Register declarations
qreg q[1];
creg c[1];

// Quantum Circuit
x q;
h q;
barrier q;
h q;
measure q -> c;

Qiskit example

# negative_superposition_state_xbasis.py
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister, execute, Aer

# Define the Quantum and Classical Registers
q = QuantumRegister(1)
c = ClassicalRegister(1)

# Build the circuit
negative_superposition_state_xbasis = QuantumCircuit(q, c)
negative_superposition_state_xbasis.x(q)
negative_superposition_state_xbasis.h(q)
negative_superposition_state_xbasis.barrier()
negative_superposition_state_xbasis.h(q)
negative_superposition_state_xbasis.measure(q, c)

# Execute the circuit
job = execute(negative_superposition_state_xbasis, backend = Aer.get_backend('qasm_simulator'), shots=1024)
result = job.result()

# Print the result
print(result.get_counts(negative_superposition_state_xbasis))

The matrix the represents the H gate is

\begin{split}H =\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} .\end{split}

Applying this gate to the |0\rangle gives

\begin{split}H|0\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\begin{pmatrix} 1 \\ 0 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ 1 \end{pmatrix}=|+\rangle,\end{split}

and applying it to the |1\rangle gives

\begin{split}H|1\rangle = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix}\begin{pmatrix} 0 \\ 1 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 \\ -1 \end{pmatrix}=|-\rangle.\end{split}

These matrices lead directly to the quantum randomness seen above. You have also learned about quantum superpositions, and that these superpositions can have a sign. The main message to take away from this this chapter is:

  • a physical system in a definite state can still behave randomly.

This is the first of the two principles from The quantum world section. This needs to become your new intuition, as it is what makes quantum systems different to classical systems.