Entanglement
Two qubits are entangled when their joint state cannot be split into a state for each one. Measuring one then tells you about the other, however far apart they are.
Building a Bell state
Start with both qubits in and apply a Hadamard to qubit 0:
Qubit 0 is the right-hand digit, so it is now in superposition and qubit 1 is still 0. This is still a product state. Now a CNOT with qubit 0 as control flips qubit 1 only in the term where qubit 0 is 1:
That last state is a Bell state. In qsengine it is two lines:
import qsengine
qc = qsengine.QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
counts = qc.run(shots=1000, seed=1)
print(counts)Output
{'00': 513, '11': 487}Only 00 and 11 appear: the two qubits always agree.
Why it cannot be split
If the Bell state were a product of two single-qubit states, then by the tensor product rule
and we would need while . The second pair forces one of the four numbers to be zero, which breaks the first pair. No choice works, so the state is entangled.
Correlation, not communication
Each qubit on its own looks like a fair coin: 0 or 1, half the time each. Only the pair is special, because the two results always agree. Compare a Hadamard on both qubits, which gives four outcomes with no link between the qubits:
qc = qsengine.QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)
print(qc.probabilities()) # entangled
qc = qsengine.QuantumCircuit(2)
qc.h(0)
qc.h(1)
print(qc.probabilities()) # independentOutput
[0.5 0. 0. 0.5]
[0.25 0.25 0.25 0.25]Because each side alone is random, entanglement cannot send a message faster than light. It can still do useful work; teleportation and many algorithms are built on it.
More than two qubits
Chaining CNOTs spreads the entanglement to any number of qubits. Three gives the GHZ state:
The exact amplitudes example builds it and prints all eight amplitudes.