liveBook · Manning

State preparation

As explained in Quantum Programming in Depth

A state preparation algorithm is a computational procedure that transforms an initial quantum state into a specified target quantum state.

State preparation transforms freshly initialized qubits, typically \(\ket{0}\), into a target superposition described by amplitudes. It is the opening step of many quantum algorithms: the prepared distribution determines which outcomes can later be amplified or sampled with high probability. section 2.0 section 2.8

For real amplitudes, a single qubit can be prepared as \(\alpha\ket{0}+\beta\ket{1}\) with \(\alpha^2+\beta^2=1\) by applying \(Ry(\theta)\), where \(\theta=2\operatorname{atan2}(\beta,\alpha)\). Using \(\operatorname{atan2}\) preserves both amplitude signs; simpler inverse-trigonometric choices can prepare the wrong relative phase or even an orthogonal state. section 2.1 section 2.1.1

Arbitrary multiqubit preparation follows a recursive decomposition. Split the amplitude array into entries for even and odd basis-state indices, prepare the least significant qubit from the norms of those groups, then conditionally prepare the remaining qubits for each branch. This uses controlled versions of the same preparation routine and follows little-endian amplitude ordering. section 2.3 section 2.5.1 section 2.8

Figure 2.5 To prepare an \(n\)-qubit state, we prepare the least significant qubit in a superposition state and then adjust the state of the remaining \(n-1\) qubits. Same as in the two-qubit case, controlled variants of the state preparation operation allow us to adjust the states of the most significant \(n-1\) qubits conditionally, with separate handling of the least significant qubit being in \(\ket{0}\) and \(\ket{1}\) states.
figure

The recursion diagram makes the branching structure explicit: prepare one qubit, then invoke controlled preparation on the remaining register for its \(\ket{0}\) and \(\ket{1}\) branches. section 2.5.1

A practical implementation and validation workflow is:

  • Compute one-qubit rotation angles with \(2\operatorname{atan2}(\beta,\alpha)\); its dependence on relative values also avoids renormalizing recursive subarrays. section 2.1.1 section 2.5.2
  • Package preparation routines as gates or operations, control them on the appropriate branch, and transpile custom controlled gates when targeting a simulator or device. section 2.3.3
  • Inspect the simulator statevector and compare its amplitudes with the requested vector using floating-point approximate equality. section 2.3.3 section 2.4.1
  • Test basis states, unequal and negative-amplitude superpositions, and random states; equal superpositions alone can hide sign, square-root, and endian bugs. section 2.4 section 2.5.2

Preparing a constrained search space

For an \(N\)-queens Grover search, each row can be represented by \(\lceil\log_2N\rceil\) qubits holding a column index. Preparing \(\ket{E_N}\), the equal superposition of indices from \(0\) through \(N-1\), independently for every row restricts the search space before the marking oracle checks column and diagonal conflicts. section 8.3.2 section 8.3.3

The recursive method is approachable rather than optimal. Structured states with few nonzero or patterned amplitudes may admit more efficient custom circuits. The presented routine handles real amplitudes; supporting general complex states requires gates beyond \(Ry\), such as \(Rx\) and \(Rz\). section 2.6 section 2.7

How Quantum Programming in Depth covers it

How deep it goes
Derives and implements real-amplitude preparation from one qubit through recursive multiqubit circuits, deferring efficient synthesis and complex amplitudes.
Examples
Uses single- and two-qubit target vectors, recursive basis and random states, and the N-queens search-space state.
What it assumes
Assumes quantum-state notation, gates, and basic programming while refreshing rotations, amplitudes, and endian-sensitive indexing.
What you can do after
Build it from scratch as tested Qiskit and Q# routines for arbitrary real-amplitude states.
How it connects
Connects controlled operations, Ry rotations, recursion, statevectors, quantum simulators, Grover’s algorithm, and marking oracles.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Quantum Programming in Depth. The section links point to the parts of the book it draws on.