CZ gate

The controlled-Z gate: matrix, effect on the basis states, the cz() call in Python and JS, and what it becomes on IonQ hardware.

The CZ gate flips the sign of the 11\vert 11 \rangle amplitude and leaves the other three basis states alone. It acts on two qubits and takes no parameters. Control and target are interchangeable: cz(0, 1) and cz(1, 0) are the same gate. The Circuit panel draws a dot on the control wire joined to a Z box on the target wire. On its own it changes nothing a measurement can see; the sign shows once the qubits are 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.cz(control, target)
JScircuit.cz(control, target)
Qiskit classCZGate

Matrix

The matrix uses the basis order 00,01,10,11\vert 00 \rangle, \vert 01 \rangle, \vert 10 \rangle, \vert 11 \rangle.

CZ=(1000010000100001)CZ = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}

The matrix is diagonal and symmetric in the two qubits, which is why the roles of control and target do not matter. CZ is the special case cp(π) of the CP gate.

Effect on basis states

InputOutput
00\vert 00 \rangle00\vert 00 \rangle
01\vert 01 \rangle01\vert 01 \rangle
10\vert 10 \rangle10\vert 10 \rangle
11\vert 11 \rangle11-\vert 11 \rangle

A measurement straight after CZ shows no change on any basis state. The sign flip shows once the qubits are in superposition: an H gate on the target before and after a CZ turns it into a CX.

Inverse

CZ is its own inverse. Two CZ gates in a row on the same pair cancel.

Usage

from qiskit import QuantumCircuit

qc = QuantumCircuit(2, 2)
qc.h(0)
qc.h(1)
qc.cz(0, 1)
qc.h(1)
qc.measure([0, 1], [0, 1])
import { QuantumCircuit } from 'qiskit';

const circuit = QuantumCircuit(2, 2);
circuit.h(0);
circuit.h(1);
circuit.cz(0, 1);
circuit.h(1);
circuit.measure([0, 1], [0, 1]);

On a noiseless simulator every shot reads 00 or 11, in close to equal numbers: the H, CZ, H on the target is a CX, so this is the Bell pair.

On IonQ hardware

CZ is not a native gate, but it is close to one. On Forte it is a single ZZ gate with virtual Z rotations on both qubits, up to a global phase, and no single-qubit pulses at all; on Aria it is one MS gate with single-qubit pulses around it. Either way it is one entangling gate before IonQ's optimiser runs. 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.