liveBook · Manning

Phase

As explained in Building Quantum Software with Python

Wave phase is the horizontal or angular offset that specifies the position of a periodic waveform within its cycle.

Phase is an angular position within a repeating pattern. For a sinusoid A cos(2πft + φ), φ is its horizontal shift at t = 0; frequency counts cycles, while amplitude sets peak height. Sine and cosine have the same shape but differ by a phase shift of π/2. section 7.1.1

In a quantum state, phase is the direction of a complex amplitude. An amplitude z = x + iy has a magnitude and direction; its squared magnitude gives an outcome probability, whereas its direction can carry information not visible in probabilities alone. Python's atan2(z.imag, z.real) returns that direction in radians. section 3.1.1 section 3.1.3

Treat phase as an angle on the complex plane. Multiplying an amplitude by cos(φ) + i sin(φ) preserves its magnitude and adds φ to its direction. This gives a direct implementation model for phase rotations: magnitudes multiply, directions add. section 3.2.1

Encode and recover a value in one amplitude's phase

To encode x = 273.5 from a 0–1000 range, set θ = πx/1000. Apply a Hadamard gate to an initial qubit, then a phase gate P(θ). Outcome 1 retains magnitude 1/√2 and receives phase θ; atan2 can recover x by converting θ/π back to the original scale. section 3.5.2

Phase can represent a periodic sequence across many amplitudes. A geometric sequence state assigns outcome k the phase kθ while keeping every amplitude at magnitude 1/√N. As k advances, the phases trace rotations around the unit circle; their repetition and total rotation describe the sequence frequency. section 7.1.2

Figure 7.8 Unit color wheel representation of the geometric sequence state for θ = π/3
figure

The unit color wheel makes the phase progression for θ = π/3 visible as successive angular steps and repeated directions. section 7.1.2

A phase-encoded state may have equal measurement probabilities, so direct sampling cannot reveal its angle. A final Hadamard gate can convert a single-qubit phase difference θ into magnitudes cos(θ/2) and sin(θ/2), producing probabilities from which the encoded angle can be inferred. This is the simplest phase-to-magnitude pattern of the quantum Fourier transform. section 7.2

For multi-qubit states, store one complex amplitude per outcome in a list of length 2ⁿ. Build a table with each outcome, its phase from atan2, magnitude, and squared magnitude; the phase-and-probability columns can also reconstruct the complex amplitudes, up to rounding. section 4.2.2

How Building Quantum Software with Python covers it

How deep it goes
Explains phase visually and computationally through complex amplitudes, rotations, geometric states, and a Hadamard conversion pattern.
Examples
Uses sine and cosine waves, a 273.5 single-qubit encoding, π/3 and π/6 geometric sequences, and an eight-amplitude state table.
What it assumes
Introduces direction from complex-number real and imaginary parts while deferring further complex-number details to an appendix.
What you can do after
Apply it via Python state and circuit helpers to encode angles, inspect amplitude directions, and convert phase information into measurement probabilities.
How it connects
Connects phase to complex numbers, amplitudes, magnitude, probability, Hadamard gates, phase gates, geometric sequences, frequency, and the quantum Fourier transform.

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.