The Measured Qubit

Learn how we can implement and draw the measured qubit.

Let’s have a look at this gate in practice. We use IBM’s quantum computing SDK Qiskit.

The measured qubit implementation

Press + to interact
from qiskit import execute, Aer, QuantumCircuit
from qiskit.visualization import plot_histogram
# Create a quantum circuit with one qubit
qc = QuantumCircuit(1)
# Define initial_state
qc.initialize(psi, 0)
# Apply the X-gate
qc.x(0)
# Tell Qiskit how to simulate our circuit
backend = Aer.get_backend('statevector_simulator')
# Do the simulation, returning the result
result = execute(qc,backend).result()
counts = result.get_counts()
plot_histogram(counts)

The fundamental unit of Qiskit is the quantum circuit. A quantum circuit is a model for quantum computation. Our circuit consists of a single qubit in line 5.

We initialize our qubit with the state psi in line 8, and apply the X-gate in line 11.

Qiskit provides the Aer package that we import at line 1. In addition, it offers different backends for simulating quantum circuits. The most common backend is the statevector_simulator in line 14.

The execute function that we imported at line 1 runs our quantum circuit (qc) at the specified backend. In line 17, it returns a job object that has a useful method job.result(). This returns the result object once our program completes it.

Qiskit uses Matplotlib to provide insightful visualizations. A simple histogram will do. The result object provides the get_counts method to obtain the histogram data of an executed circuit in line 18.

The method plot_histogram returns a Matplotlib figure that Jupyter draws automatically in line 19.

We see we have a 75%75\% chance of observing the value 0 and a 25%25\% chance of observing the value ...