# 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, . In Circuit Composer, this is the blue gate labeled .

The simple score to make a superposition is given below. It starts with placing the gate on one of the qubits (which starts in the 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;
creg c;

// 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 gates in succession. If we consider the 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;
creg c;

// 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 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 gate, we make a uniform superposition of the ground and excited state, , 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 state or the state with an equal probability. In the second case, we can think of the second 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 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 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;
creg c;

// 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 gate (putting it in a superposition), and then measuring in the x-basis (another 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 state. By definition, this state has to be . That is, the gate transforms the computational basis into a new basis, the superposition basis, defined by the set .

Negative superposition state X-basis

OpenQasm Input

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

// Register declarations
qreg q;
creg c;

// 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 gate is

Applying this gate to the gives

and applying it to the gives

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.