Prepares arbitrary superpositions and probability distributions over computational basis states with exact amplitudes.
State preparation initializes a register from |0...0⟩ into a specified quantum state or probability distribution. It supports single target states with biased probabilities, multi-state probability distributions, presets ("bell", "ghz", "superposition"), and custom wire assignments.
Under the hood, sparse state synthesis uses single-qubit RY rotations and controlled rotations (or CX gates) to construct the exact target probability distribution with optimal O(k · n) gate count for k specified states.
How it works
-
1
Base distribution
RY rotations establish initial probability weights on root qubits.
-
2
Controlled branching
Controlled RY and CX gates branch into the target computational basis states.
-
3
Target basis state
Basis bit flips (X gates) align the amplitudes with the requested target bitstrings.
StatePreparation(0b101, 0.4)
Function form: StatePreparation(0b101, 0.4)
This example expands from a standard-library function. Open it in the simulator to see every gate.
State. 40% on |101⟩, 60%/7 ≈ 8.57% on each of the other 7 states
P(101) = 0.40. All other 3-qubit basis states have probability ≈ 0.0857.
| Basis | Amplitude | Probability |
|---|---|---|
|101⟩ |
√0.4 ≈ 0.632 |
|
other 7 |
√(0.6/7) ≈ 0.293 |
Notes
- Single target: StatePreparation(0b101, 0.4) or StatePreparation(0b101, 40%) gives |101⟩ 40% probability and splits the remaining 60% equally among the other 7 basis states.
- Multi-state distribution: StatePreparation((0b101..0b111), (20%, 30%, 40%)) sets |101⟩ to 20%, |110⟩ to 30%, |111⟩ to 40%, and the remaining 10% equally among others.
- Presets: StatePreparation("bell"), StatePreparation("ghz"), StatePreparation("superposition").
- Optional wire range: StatePreparation(0b101, 50%, 1..3) applies the preparation to qubits 1, 2, and 3.
Change parameters
The write-up above is for the default circuit. Use this control to generate other variants and load them in the simulator.