6 min read
Single-Qubit Gates: X, H, and Z
Apply the Pauli-X, Hadamard, and Pauli-Z gates and watch the state vector move on the Bloch sphere.
Suggested before this lesson
So far you've built circuits the short way: QuantumCircuit(1) and go. Qiskit gives you a couple of other ways to do the same thing, and they're worth knowing before things get busier in later lessons.
Give it a name. Circuits (and the registers they're built from) can carry a name. It doesn't change what the circuit does; it just shows up wherever the circuit is drawn or inspected, which is handy once you're juggling more than one.
Build it from a register. Instead of just handing QuantumCircuit a number of qubits, you can first create a named QuantumRegister and pass that in instead. A register is just a named, sized group of qubits: right now that group has one qubit in it, but this is the pattern you'll use once circuits need more.
Both snippets above produce an equivalent one-qubit circuit; try either style in the exercises below and the checker will accept it. The live circuit preview under each exercise will pick up the name and register label if you use them, so you can see the effect immediately.
The gate is the quantum analogue of a classical NOT gate: it flips . On the Bloch sphere it is a 180-degree rotation about the axis.
There's a second way to write that last line. qc.x(0) is really just a shortcut for appending a gate object to the circuit, and that's a pattern that works for every gate Qiskit has:
.append(gate, qubits) is the general mechanism; .x(), .h(), .cx() and friends are just convenience methods built on top of it. You'll see both styles used in the wild; use whichever reads better to you.
qc.x(0) or qc.append(XGate(), [0]) works.Live preview of the circuit detected in your code
The Hadamard gate () creates an equal superposition:
On the Bloch sphere, rotates the state from the pole to the equator.
Live preview of the circuit detected in your code
Applying after rotates to . Watch the Bloch vector swing across the equator.
Circuit
h
z
Step through the circuit: after gate 2 of 2
3 / 3
State Amplitudes
Bloch Sphere
Python
Python
Python
Python
Python
Python