Z gate
The Z gate: matrix, effect on |0⟩, |1⟩, |+⟩ and |−⟩, the z() call in Python and JS, and why it costs nothing on IonQ hardware.
The Z gate leaves alone and flips the sign of . It acts on one qubit and takes no parameters. The Circuit panel draws it as Z. On its own it changes nothing a measurement can see; the sign shows once the qubit is in superposition.
Kets such as name the basis states and rotations are described on the Bloch sphere; the qubits lesson introduces both.
Call
| Where | Call |
|---|---|
| Python | qc.z(qubit) |
| JS | circuit.z(qubit) |
| Qiskit class | ZGate |
| Controlled form | cz(control, target) |
Matrix
On the Bloch sphere this is a half-turn about the Z axis. Z is the special case p(π) of the P gate, and two S gates make one Z.
Effect on basis states
| Input | Output |
|---|---|
A measurement straight after Z shows no change on or . The sign flip shows once the qubit is in superposition: Z turns into , which an H gate then reads out as a 1.
Inverse
Z is its own inverse. Two Z gates in a row on the same qubit cancel.
Usage
from qiskit import QuantumCircuit
qc = QuantumCircuit(1, 1)
qc.h(0)
qc.z(0)
qc.h(0)
qc.measure(0, 0)
import { QuantumCircuit } from 'qiskit';
const circuit = QuantumCircuit(1, 1);
circuit.h(0);
circuit.z(0);
circuit.h(0);
circuit.measure(0, 0);
Every shot reads 1: the two H gates would cancel on their own, and the Z between them turns the pair into an X.
On IonQ hardware
Z is a virtual Z. The hardware has no physical Z gate; the compiler folds the half-turn into the phase of whatever pulse comes next, so Z costs no gate and no time on the machine. See How your circuit is compiled.
Related
Stay in the loop.
Get the latest tutorials, demos, and project showcases straight to your inbox. No noise, just the good stuff.
Gates