qpe_toolbox.estimation.robust_phase_estimation¶
Functions¶
|
Perform the Robust Phase Estimation (RPE) algorithm. |
|
Measure the raw RPE phases \(\phi_m\) for \(m = 0, \dots, M-1\). |
|
Refine the raw RPE phases \(\phi_m\) into the estimates \(\theta_m\). |
|
Estimate minus the phase of \(\bra{\psi_0} U \ket{\psi_0}\). |
|
Compute the angular distance between two angles. |
|
Refine the phase estimate at iteration |
Module Contents¶
- qpe_toolbox.estimation.robust_phase_estimation.robust_phase_estimation(hamiltonian, psi0, n_repetitions, n_trotter_steps, n_shots, *, t0=1.0, trotter_order=1, cutoff=1e-10, max_bond=None, rng=None, verbosity=0)[source]¶
Perform the Robust Phase Estimation (RPE) algorithm.
This routine estimates the phase associated with the unitary time evolution generated by a Hamiltonian using a sequence of Hadamard tests at increasing evolution times. It is the composition of the measurement stage
measure_rpe_phases(the raw phases \(\phi_m\)) and the classical retrieval stagerefine_rpe_phases(the refined phases \(\theta_m\)).The algorithm estimates the phase \(\varphi = E_0 t_0\) accumulated over the base evolution time \(t_0\). It refines this estimate over
n_repetitionsiterations indexed by \(m = 0, 1, \dots, M-1\), using the evolution time \(t_0 2^m\) at iteration \(m\) and gaining one bit of precision per iteration. The final estimate satisfies \(d(\theta, E_0 t_0) \leq 2^{-(M-1)}\pi/3\) with \(M\) the number of repetitions. Recover the energy as \(E_0 = \theta / t_0\).- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the
Hamiltonianclass.psi0 (MatrixProductState) – Initial quantum state \(\ket{\psi_0}\) of the system.
n_repetitions (int) – Number of RPE iterations \(M\). Iterations are indexed by \(m = 0, 1, \dots, M-1\) with evolution time \(t_0 2^m\), and each iteration adds one bit of precision. To reach a precision of order \(\varepsilon\), take \(M = \lceil \log_2 \varepsilon^{-1} \rceil\); the guaranteed bound is then \(2^{-(M-1)}\pi/3 \simeq 2\varepsilon\).
n_trotter_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps for the
m=0evolution; multiplied by2**mat each iteration to keep the Trotter step size constant. UseEXACTfor exact time evolution.n_shots (int or qpe_toolbox.EXACT) – Number of measurement shots used in the Hadamard test. Use
EXACTto compute probabilities exactly.t0 (float, default
1.0) – Base evolution time, equivalent to a rescaling of the Hamiltonian. The phase estimated is \(\varphi = E_0 t_0\). Choose \(t_0\) so that \(|E_0 t_0| < \pi\), otherwise the \(m = 0\) phase is ambiguous.trotter_order (int, default
1) – Order of the Trotter-Suzuki decomposition. Ignored when n_trotter_steps is EXACT.cutoff (float, default
1e-10) – Singular-value truncation threshold of the underlying CircuitMPS.max_bond (int or None, default
None) – Maximum bond dimension of the underlying CircuitMPS. IfNone, no explicit limit is imposed.rng (numpy.random.Generator, optional) – Random generator for the finite-shot sampling. Ignored when
n_shotsisEXACT.verbosity (int, default
0) – Verbosity level. If >= 1, print the measured and refined phases of every iteration. If >= 2, also print the measured phases as they are computed.
- Returns:
theta_values – Phase estimates \(\theta_0, \dots, \theta_{M-1}\) of \(\varphi = E_0 t_0\), one per iteration. The last element is the most accurate estimate; recover the energy as \(\theta / t_0\).
- Return type:
(M,) array of float
- qpe_toolbox.estimation.robust_phase_estimation.measure_rpe_phases(hamiltonian, psi0, n_repetitions, n_trotter_steps, n_shots, *, t0=1.0, trotter_order=1, cutoff=1e-10, max_bond=None, rng=None, verbosity=0)[source]¶
Measure the raw RPE phases \(\phi_m\) for \(m = 0, \dots, M-1\).
This is the measurement stage of Robust Phase Estimation, returning \(\phi_m = -\arg \bra{\psi_0} U^{2^m} \ket{\psi_0}\) with \(U = e^{-iHt_0}\). Feed the result to
refine_rpe_phasesto obtain the refined phase estimates.- Parameters:
hamiltonian (Hamiltonian) – Hamiltonian object from the
Hamiltonianclass.psi0 (MatrixProductState) – Initial quantum state \(\ket{\psi_0}\) of the system.
n_repetitions (int) – Number of RPE iterations \(M\).
n_trotter_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps for the
m=0evolution; multiplied by2**mat each iteration to keep the Trotter step size constant. UseEXACTfor exact time evolution.n_shots (int or qpe_toolbox.EXACT) – Number of measurement shots emulated at each iteration. Use
EXACTto return the exact phases.t0 (float, default
1.0) – Base evolution time, equivalent to a rescaling of the Hamiltonian. The measured phase is \(\phi_m = -\arg \bra{\psi_0} U^{2^m} \ket{\psi_0}\) with \(U = e^{-iHt_0}\).trotter_order (int, default
1) – Order of the Trotter-Suzuki decomposition.cutoff (float, default
1e-10) – Singular-value truncation threshold of the underlying CircuitMPS.max_bond (int or None, default
None) – Maximum bond dimension of the underlying CircuitMPS. IfNone, no explicit limit is imposed.rng (numpy.random.Generator, optional) – Random generator for the finite-shot sampling. Ignored when
n_shotsisEXACT.verbosity (int, default
0) – Verbosity level. If >= 2, print the phase measured at each iteration.
- Returns:
phi_values – Raw phase estimates \(\phi_0, \dots, \phi_{M-1}\) in radians.
- Return type:
(M,) array of float
- qpe_toolbox.estimation.robust_phase_estimation.refine_rpe_phases(phi_values)[source]¶
Refine the raw RPE phases \(\phi_m\) into the estimates \(\theta_m\).
This is the classical, simulation-free retrieval stage of Robust Phase Estimation. Starting from \(\theta_0 = \phi_0\), each \(\theta_m\) is the candidate \((\phi_m + 2\pi k)/2^m\) nearest to the previous estimate \(\theta_{m-1}\).
- Parameters:
phi_values ((M,) array_like of float) – Raw phase estimates \(\phi_0, \dots, \phi_{M-1}\) in radians, as returned by
measure_rpe_phases.- Returns:
theta_values – Refined phase estimates \(\theta_0, \dots, \theta_{M-1}\). The last element is the most accurate estimate.
- Return type:
(M,) array of float
- qpe_toolbox.estimation.robust_phase_estimation.estimate_overlap_phase(psi0, unitary, n_shots, *, cutoff=1e-10, max_bond=None, rng=None)[source]¶
Estimate minus the phase of \(\bra{\psi_0} U \ket{\psi_0}\).
The returned phase is \(\phi = -\arg \bra{\psi_0} U \ket{\psi_0}\), independent of the norm of
psi0. WithEXACTit is exact; with finiten_shotsthe real and imaginary parts of the overlap each carry the shot noise of a Hadamard test. For \(U = e^{-iHt}\) and an eigenstate \(\ket{\psi_0}\) of energy \(E_0\), the result is \(E_0 t\).- Parameters:
psi0 (MatrixProductState) – Initial quantum state \(\ket{\psi_0}\).
unitary (Gate or iterable of Gate) – The unitary \(U\), either a single gate (e.g. an exact \(U\)) or its gate decomposition as an iterable of gates (e.g. a Trotterized \(U\)), acting on the data register without controls.
n_shots (int or qpe_toolbox.EXACT) – Number of measurement shots emulated. Use
EXACTto use the exact expectation values.cutoff (float, default
1e-10) – Singular-value truncation threshold of the underlying CircuitMPS.max_bond (int or None, default
None) – Maximum bond dimension of the underlying CircuitMPS. IfNone, no explicit limit is imposed.rng (numpy.random.Generator, optional) – Random generator for the finite-shot sampling. Ignored when
n_shotsisEXACT.
- Returns:
phi – Estimated phase angle in radians.
- Return type:
- qpe_toolbox.estimation.robust_phase_estimation.angular_distance(phi, theta)[source]¶
Compute the angular distance between two angles.
The distance is defined modulo π and lies in the interval [0, π].