Code
Step-by-step explanation
Gate definitions The circuit defines two gates from first principles using the universal single-qubit gateU(theta, phi, lambda):
h(Hadamard) is defined asU(pi/2, 0, pi), which maps |0⟩ → (|0⟩ + |1⟩)/√2 and |1⟩ → (|0⟩ − |1⟩)/√2.cx(CNOT) is defined using thectrl @modifier, which promotes a single-qubit gate to a controlled version. Here it appliesU(pi, 0, pi)(an X gate) on the target qubit whenever the control qubit is |1⟩.
qubit[2] q allocates a two-qubit register. reset q explicitly sets both qubits to |0⟩, giving the initial state |q[0]q[1]⟩ = |00⟩.
Hadamard on q[0]
h q[0] places q[0] into equal superposition:
cx q[0], q[1] flips q[1] only when q[0] is |1⟩:
Expected output
When you measure both qubits, the simulator collapses the entangled state to one of two outcomes with equal probability:
Outcomes
01 and 10 have zero probability. This perfect correlation — never a mismatched result — is the defining signature of entanglement.
Because no measurement instruction appears in this circuit, the OpenQASM Playground displays the statevector amplitude of each basis state rather than a histogram of shots. You will see amplitude 1/√2 ≈ 0.707 on both |00⟩ and |11⟩.