qpe_toolbox.estimation.qpe_circuit¶
Generic construction of Quantum Phase Estimation circuits from arbitrary unitaries.
The functions in this module are agnostic to how the controlled unitaries are
obtained. The unitaries input is a sequence of length n_phase_bits, where
unitaries[k] is an iterable of uncontrolled Gate objects
implementing the unitary controlled by phase qubit k (in textbook QPE,
\(U^{2^k}\)), acting on data-register-local qubit indices [0, n_data).
Entries may be lists or one-shot generators, enabling lazy circuit construction.
Each power can be supplied as an independent gate decomposition, so
non-squaring implementations (e.g. modular exponentiation in Shor’s algorithm)
are supported.
Functions¶
|
Generate the full textbook QPE gate sequence without simulating it. |
|
Apply the textbook QPE circuit to an initial circuit. |
Module Contents¶
- qpe_toolbox.estimation.qpe_circuit.qpe_gates(unitaries, *, global_phase=0)[source]¶
Generate the full textbook QPE gate sequence without simulating it.
The sequence is the QPE first stage (Hadamard wall and controlled unitaries) followed by the inverse QFT on the phase register. Suitable for resource analysis and serialization.
- Parameters:
unitaries (sequence of iterable of Gate) –
unitaries[k]is the gate decomposition of the unitary controlled by phase qubitk(in textbook QPE, \(U^{2^k}\)), acting on data-register-local qubit indices[0, n_data)without controls. Entries may be one-shot generators; each is consumed exactly once.global_phase (float, default
0) – Global phase \(\phi\) of the unitary \(U\). The phase correction applied before the k-th controlled unitary is \(\phi \, 2^k\) (the global phase of \(U^{2^k}\)), and the whole correction is omitted whenglobal_phaseis zero.
- Returns:
Lazy gate sequence of the full QPE circuit.
- Return type:
generator of Gate
- qpe_toolbox.estimation.qpe_circuit.qpe_circuit(initial_circ, unitaries, *, global_phase=0, with_iqft=True, verbosity=0)[source]¶
Apply the textbook QPE circuit to an initial circuit.
The circuit is built from a Hadamard wall on the phase register and the controlled unitaries (in textbook QPE, \(U^{2^k}\) controlled by phase qubit
k), optionally followed by the inverse QFT on the phase register.- Parameters:
initial_circ (Circuit or CircuitMPS) – Circuit preparing the trial state. The phase register occupies qubits
[0, len(unitaries)), the data register the remaining qubits.unitaries (sequence of iterable of Gate) – Same convention as in
qpe_gates.global_phase (float, default
0) – Same convention as inqpe_gates.with_iqft (bool, default
True) – IfTrue, apply the inverse QFT on the phase register after the controlled unitaries. IfFalse, stop after the controlled unitaries (the QPE first stage), leaving the phase register in the Fourier basis.verbosity (int, default
0) – Verbosity level. If >= 1, print progress and bond dimension information.
- Returns:
traces (dict) – Contains per-stage computation times and bond dimensions.
circ (Circuit or CircuitMPS) – Copy of
initial_circwith the QPE circuit applied. Whenwith_iqftisTrue, phase probabilities can be obtained withcirc.compute_marginal(where=range(len(unitaries))).
Notes
Whether the circuit is contracted lazily or eagerly is governed by the class of
initial_circ, not by any argument here:With a Circuit, gates accumulate lazily into an uncontracted tensor network (no truncation). The returned
circ.psiis that network; the contraction strategy is deferred to post-processing, e.g.circ.compute_marginal(..., optimize=..., rehearse=...)or handingcirc.psito a contraction-path optimizer.With a CircuitMPS, each gate is applied eagerly to the MPS with SVD truncation (controlled by the
CircuitMPSmax_bond/cutoff), i.e. the circuit is simulated as it is built.
In both cases the per-stage
bond_dimstrace is read fromcirc.psi.max_bond(), which is cheap and does not force a contraction.