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 0\vert 0 \rangle alone and flips the sign of 1\vert 1 \rangle. 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 0\vert 0 \rangle name the basis states and rotations are described on the Bloch sphere; the qubits lesson introduces both.

Call

WhereCall
Pythonqc.z(qubit)
JScircuit.z(qubit)
Qiskit classZGate
Controlled formcz(control, target)

Matrix

Z=(1001)Z = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix}

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

InputOutput
0\vert 0 \rangle0\vert 0 \rangle
1\vert 1 \rangle1-\vert 1 \rangle
+\vert + \rangle\vert - \rangle
\vert - \rangle+\vert + \rangle

A measurement straight after Z shows no change on 0\vert 0 \rangle or 1\vert 1 \rangle. The sign flip shows once the qubit is in superposition: Z turns +\vert + \rangle into \vert - \rangle, 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.

Stay in the loop.

Get the latest tutorials, demos, and project showcases straight to your inbox. No noise, just the good stuff.