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

qpe_gates(unitaries, *[, global_phase])

Generate the full textbook QPE gate sequence without simulating it.

qpe_circuit(initial_circ, unitaries, *[, ...])

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 qubit k (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 when global_phase is 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 in qpe_gates.

  • with_iqft (bool, default True) – If True, apply the inverse QFT on the phase register after the controlled unitaries. If False, 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_circ with the QPE circuit applied. When with_iqft is True, phase probabilities can be obtained with circ.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.psi is that network; the contraction strategy is deferred to post-processing, e.g. circ.compute_marginal(..., optimize=..., rehearse=...) or handing circ.psi to a contraction-path optimizer.

  • With a CircuitMPS, each gate is applied eagerly to the MPS with SVD truncation (controlled by the CircuitMPS max_bond / cutoff), i.e. the circuit is simulated as it is built.

In both cases the per-stage bond_dims trace is read from circ.psi.max_bond(), which is cheap and does not force a contraction.