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.
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
