Qubits and bra-ket notation
A classical bit is either 0 or 1. A qubit has two basic states too, but it can also be in a blend of both at once. This page shows how physicists write those states down, which is the notation the rest of these pages use.
Kets
A state is written inside a ket, the symbol . The two basic states of a qubit are
Under the notation, a state is just a column of numbers. and play the role of 0 and 1, and every qsengine circuit starts with all its qubits in .
Superposition
Any other state of one qubit is a combination of the two basic states:
and are amplitudes. They are complex numbers, and they must satisfy
because, as the measurement page explains, the squares are probabilities and must add up to 1. A state with both amplitudes non-zero is in superposition.
Making a superposition
The Hadamard gate turns into an equal superposition:
qsengine shows the two amplitudes directly. :
import qsengine
qc = qsengine.QuantumCircuit(1)
qc.h(0)
print(qc.statevector())
print(qc.run(shots=1000, seed=3))Output
[0.70710678+0.j 0.70710678+0.j]
{'0': 493, '1': 507}Equal amplitudes, so 0 and 1 each come up about half the time.
Gates are matrices
A gate on one qubit is a 2 by 2 matrix, and applying it multiplies the state by that matrix. The X gate swaps the two amplitudes, which is why it acts as a NOT:
Every gate in qsengine is a matrix like this. The gates page lists them all.
Bras
The mirror image of a ket is a bra, : the same numbers laid out as a row and complex-conjugated. Putting a bra against a ket gives a single number, the overlap of two states:
That is how you pick an amplitude out of a state, and it is the start of the measurement rule.