qpe_toolbox.estimation.quantum_phase_estimation¶
Hamiltonian-driven Quantum Phase Estimation circuit construction.
Build the controlled unitaries \(U^{2^k} = e^{-i H t 2^k}\) from a
Hamiltonian and feed them to the generic QPE circuit builder in qpe_circuit.
The assembled circuit places two contiguous registers, phase first:
phase register – the
n_phase_bitsestimation qubits, at indices[0, n_phase_bits)(phase_reg). Hadamard wall, controls, inverse QFT.data register – the qubits the controlled unitary acts on, at indices
[n_phase_bits, initial_circ.N). For textbook QPE (and RPE) this is the physical register; the genericqpe_circuitlayer works in data-register local indices[0, n_data)and shifts them past the phase register.
The Hamiltonian methods get_exact_unitary / get_trotter_step build gates on
the physical register phys_reg – the n_qubits qubits the
Hamiltonian acts on. Here phys_reg coincides with the data register, so the
default phys_reg = range(n_qubits) is used. The distinction only matters
for block-encoded variants (e.g. LCU), where the data register additionally
contains ancilla qubits and data_reg = ancilla_reg + phys_reg.
Functions¶
|
Perform quantum phase estimation (QPE) to estimate the energy of a Hamiltonian. |
|
Apply quantum phase estimation to a given initial circuit and sample the output. |
|
Build the QPE gate list for a Hamiltonian evolution without simulating it. |
|
Perform the first stage of the quantum phase estimation algorithm. |
|
Build the exact evolution unitaries \(U(t \, 2^k)\) for the QPE sequence. |
|
Build the evolution unitaries \(U(t \, 2^k)\) for the QPE sequence. |
|
Set up the energy search window for phase estimation. |
Module Contents¶
- qpe_toolbox.estimation.quantum_phase_estimation.qpe_energy(hamiltonian, initial_circ, n_trotter_steps, E_target, size_interval, *, trotter_order=1, optimize='auto-hq', verbosity=0)[source]¶
Perform quantum phase estimation (QPE) to estimate the energy of a Hamiltonian.
The algorithm encodes the phase corresponding to the Hamiltonian evolution into a phase register and samples it to extract the energy eigenvalue.
- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the QPE-Toolbox
Hamiltonianclass.initial_circ (Circuit or CircuitMPS) – Initial circuit preparing the trial state in the data register.
n_trotter_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps for the
U(t)evolution, orEXACTfor exact evolution.E_target (float) – Central target energy for the search window, in physical energy units (i.e. including
hamiltonian.e_constif present).size_interval (float) – Width of the energy search interval.
trotter_order (int, default
1) – Order of the Trotter decomposition.optimize (str, default
"auto-hq") – Optimization strategy when computing marginals with tensor networks.verbosity (int, default
0) – Verbosity level. If >= 1, print timing and progress information and the result summary.
- Returns:
traces (dict) – Dictionary with computation information, including timing, bond dimensions, gate counts, and the phase values sorted by decreasing probability.
energy (float) – Estimated energy eigenvalue in physical units (Pauli eigenvalue plus
hamiltonian.e_constif present).
Notes
The phase register is automatically determined as
initial_circ.N - hamiltonian.n_qubits.The estimated energy is computed as
\[E = E_\mathrm{max} - \frac{2 \pi \theta}{t_\mathrm{evol}}\]where \(\theta\) is the phase of the most probable state and \(E_\mathrm{max} = E_\mathrm{target} + \Delta/2\) (see
set_search_window()).Supports both Trotterized and exact evolution.
- qpe_toolbox.estimation.quantum_phase_estimation.qpe_sample(hamiltonian, initial_circ, evolution_time, n_trotter_steps, global_phase, *, trotter_order=1, rehearse=False, optimize='auto-hq', verbosity=0)[source]¶
Apply quantum phase estimation to a given initial circuit and sample the output.
- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the QPE-Toolbox
Hamiltonianclass.initial_circ (Circuit or CircuitMPS) – Circuit preparing the trial state.
evolution_time (float) – Total evolution time for the controlled-U operations.
n_trotter_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps for the
U(t)evolution; ifEXACT, evolution is exact.global_phase (float) – Global phase added to the controlled-U operations.
trotter_order (int, default
1) – Order of Trotter decomposition for time evolution.rehearse (bool, default
False) – IfTrue, the finalcompute_marginalis not run: it returns the contraction rehearsal (tensor network, path, and cost estimates) instead of the phase probabilities.optimize (str, default
"auto-hq") – Optimization strategy for tensor network marginal computation.verbosity (int, default
0) – If> 0, prints timing and progress information.
- Returns:
traces (dict) – Dictionary containing bond dimensions, full QPE circuit, timing and gate counts.
probs (array or dict) – Probability tensor of the phase qubits, or the contraction rehearsal when
rehearse=True.
Notes
To obtain the gate list without simulating the circuit (resource analysis), use
qpe_gate_list.The QPE quantum circuit can be recovered as
traces["circuit"].traces["gates_count"]covers the whole circuit, including any gates carried byinitial_circ; circuits built bymake_circcarry none.Whether the circuit is contracted lazily or eagerly is set by the class of
initial_circ: a Circuit accumulates an uncontracted tensor network that the finalcompute_marginalcontracts exactly (steered byoptimize/rehearse), while a CircuitMPS is simulated eagerly with SVD truncation. Either way the marginal over the phase register is returned, unlessrehearseisTrue.With
rehearse=Trueno contraction is performed:compute_marginalreturns the contraction rehearsal instead of the probabilities. Combined with a Circuit, evaluation is then completely lazy.
- qpe_toolbox.estimation.quantum_phase_estimation.qpe_gate_list(hamiltonian, n_phase_bits, evolution_time, n_trotter_steps, global_phase, *, trotter_order=1, savefile=None)[source]¶
Build the QPE gate list for a Hamiltonian evolution without simulating it.
This produces the same QPE gate sequence as
qpe_sample, excluding any gates already present in itsinitial_circ, and skips the tensor network simulation; use it for resource analysis and circuit serialization.- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the QPE-Toolbox
Hamiltonianclass.n_phase_bits (int) – Number of phase estimation qubits.
evolution_time (float) – Total evolution time for the controlled-U operations.
n_trotter_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps for the
U(t)evolution; ifEXACT, evolution is exact.global_phase (float) – Global phase added to the controlled-U operations.
trotter_order (int, default
1) – Order of Trotter decomposition for time evolution.savefile (str or os.PathLike or None, default
None) – If notNone, path to which the serialized gates are written as JSON. Not supported for exact time evolution (n_trotter_steps=EXACT).
- Returns:
gates_count (dict) – Dictionary mapping gate labels to their counts.
gates_list (list of Gate) – Gate sequence of the full QPE circuit.
- Raises:
ValueError – If
savefileis given together with exact time evolution (n_trotter_steps=EXACT).
- qpe_toolbox.estimation.quantum_phase_estimation.qpe_first_stage(hamiltonian, initial_circ, evolution_time, n_trotter_steps, global_phase, *, trotter_order=1, verbosity=0)[source]¶
Perform the first stage of the quantum phase estimation algorithm.
This includes:
Applying a Hadamard wall on the phase register.
Controlled-U operations with the Hamiltonian evolution.
Optional Trotterization for approximate time evolution.
- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the QPE-Toolbox
Hamiltonianclass.initial_circ (Circuit or CircuitMPS) – Initial state of the system.
evolution_time (float) – Total evolution time.
n_trotter_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps for the
U(t)evolution;EXACTfor exact evolution.global_phase (float) – Global phase applied to controlled-U operations.
trotter_order (int, default
1) – Trotter order for time evolution.verbosity (int, default
0) – Verbosity level. If >= 1, print progress and bond dimension information.
- Returns:
traces (dict) – Contains bond dimensions, computation times, and other metadata.
circ (Circuit or CircuitMPS) – Updated circuit with the first stage applied.
- qpe_toolbox.estimation.quantum_phase_estimation.exact_evolution_powers(hamiltonian, evolution_time, n_powers)[source]¶
Build the exact evolution unitaries \(U(t \, 2^k)\) for the QPE sequence.
- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the QPE-Toolbox
Hamiltonianclass.evolution_time (float) – Total evolution time
t.n_powers (int) – Number of powers to build, indexed by
k = 0, ..., n_powers - 1.
- Returns:
unitaries –
unitaries[k]holds the single dense gate implementing \(U(t \, 2^k) = e^{-i H t 2^k}\) on data-register-local qubits, without controls, as expected byqpe_circuitandqpe_gates.- Return type:
list of list of Gate
- qpe_toolbox.estimation.quantum_phase_estimation.evolution_powers(hamiltonian, evolution_time, n_trotter_steps, n_powers, *, trotter_order=1)[source]¶
Build the evolution unitaries \(U(t \, 2^k)\) for the QPE sequence.
Dispatch to
exact_evolution_powersortrotter_evolution_powersdepending onn_trotter_steps.- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the QPE-Toolbox
Hamiltonianclass.evolution_time (float) – Total evolution time
t.n_trotter_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps for the
U(t)evolution; multiplied by2**kfor powerkto keep the Trotter step size constant. UseEXACTfor exact time evolution.n_powers (int) – Number of powers to build, indexed by
k = 0, ..., n_powers - 1. The number of phase bits in textbook QPE, of repetitions in RPE.trotter_order (int, default
1) – Order of the Trotter decomposition. Ignored whenn_trotter_steps is EXACT.
- Returns:
unitaries –
unitaries[k]holds the gates of \(U(t \, 2^k)\) on data-register-local qubits, without controls, as expected byqpe_circuitandqpe_gates. Trotterized entries are one-shot generators.- Return type:
list of iterable of Gate
- qpe_toolbox.estimation.quantum_phase_estimation.set_search_window(hamiltonian, E_target, size_interval)[source]¶
Set up the energy search window for phase estimation.
- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the QPE-Toolbox
Hamiltonianclass.E_target (float) – Central target energy around which to search, in physical energy units (i.e. including
hamiltonian.e_constif present).size_interval (float) – Width of the energy interval (must be > 0).
- Returns:
E_max (float) – Upper bound of the search window in physical energy units:
E_target + size_interval / 2.evolution_time (float) – Total evolution time corresponding to the search interval.
global_phase (float) – Global phase applied to the circuit:
(E_max - e_const) * evolution_time.
Notes
Evolution time is chosen as
2 * pi / size_intervalto map the interval to [0, 2π].