liveBook · Manning

Quantum gate

As explained in Building Quantum Software with Python

A single-qubit gate is a quantum gate whose transformation acts on one qubit.

A quantum gate is an instruction that changes a quantum state by recombining amplitudes. An elementary gate acts on a pair of amplitudes according to a specific formula, changing outcome probabilities, amplitude directions, or both. Gate operations preserve the combined probability of each affected pair. section 2.2.2 section 3.2

For one qubit, the state has two amplitudes: the 0 and 1 outcomes. A single-qubit gate is a two-by-two linear transformation of those values. The X gate swaps them; Z reverses the direction of the 1 amplitude without changing its probability; a phase gate rotates that amplitude by a supplied angle. Hadamard and related gates recombine both amplitudes, allowing probability to move between outcomes. section 3.2.2 section 3.2.3

Figure 2.7 An elementary quantum instruction (gate) recombines pairs of amplitudes. The two inputs, a and b, are recombined according to a formula to compute two outputs, creating a shape that resembles butterfly wings.
figure

A butterfly diagram visualizes a gate as two input amplitudes recombined into two outputs. This pairwise view scales to larger states: the target qubit determines which outcome indices form each pair, and all selected pairs update simultaneously. section 2.2.2 section 1.4.3

Represent a single-qubit gate as a nested two-by-two list and apply it to a two-element state:

  • Store the gate as [[a, b], [c, d]], where each row supplies coefficients for one output amplitude. section 3.3.2
  • Compute new output 0 as a·z0 + b·z1 and output 1 as c·z0 + d·z1; retain the old amplitudes until both outputs are calculated. section 3.3.2
  • Reuse the same transformation function for X, Z, phase, Hadamard, RZ, Y, RX, and RY gates by changing only the gate matrix. section 3.3.2

Compose gates into a circuit

A single-qubit circuit is an ordered sequence of gates. Starting from an initialized state, apply RY(2π/3), X, P(π/3), and H in that order. Circuit notation writes the resulting sequence as HP(π/3)XRY(2π/3), with the written order reversed from application order; a circuit diagram instead shows applications left to right. section 3.3.3 section 3.3.3

In multi-qubit systems, a single-qubit gate still uses its two-by-two formula, but it recombines every amplitude pair that differs only at the target-qubit position. Controlled transformations add control qubits and reduce the pairs that are recombined. Sequences of these elementary operations form quantum computations and can increase the probability of desired outcomes. section 12.3 section 2.5

How Building Quantum Software with Python covers it

How deep it goes
Develops gate effects visually, as two-by-two linear transformations, and as Python simulations; defers multi-qubit pair selection.
Examples
Uses X, Z, phase, Hadamard, RZ, Y, RX, and RY transformations, plus a four-gate single-qubit circuit.
What it assumes
Introduces gates from state vectors and complex-number lists without requiring advanced linear algebra.
What you can do after
Build it from scratch: simulates basic single-qubit gates and composes them into circuits with a shared transform function.
How it connects
Connects quantum gates with amplitudes, state vectors, quantum circuits, amplitude amplification, unitary matrices, and the FFT butterfly pattern.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Quantum Software with Python. The section links point to the parts of the book it draws on.