The Measured Qubit
Learn how we can implement and draw the measured qubit.
We'll cover the following...
Let’s have a look at this gate in practice. We use IBM’s quantum computing SDK Qiskit.
The measured qubit implementation
from qiskit import execute, Aer, QuantumCircuitfrom qiskit.visualization import plot_histogram# Create a quantum circuit with one qubitqc = QuantumCircuit(1)# Define initial_stateqc.initialize(psi, 0)# Apply the X-gateqc.x(0)# Tell Qiskit how to simulate our circuitbackend = Aer.get_backend('statevector_simulator')# Do the simulation, returning the resultresult = 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 chance of observing the value 0
and a chance of observing the value ...