qpe_toolbox.estimation.robust_phase_estimation

Functions

robust_phase_estimation(H, psi0, n_repetitions, ...[, ...])

Perform the Robust Phase Estimation (RPE) algorithm.

rpe_get_hadamard_output(H, psi0, evolution_time, ...)

Estimate the phase of \(\bra{\psi_0}\exp(-i H t)\ket{\psi_0}\) using Hadamard tests.

angular_distance(phi, theta)

Compute the angular distance between two angles.

rpe_update_theta(phi_m, theta_ref, m)

Refine the phase estimate at iteration m.

Module Contents

qpe_toolbox.estimation.robust_phase_estimation.robust_phase_estimation(H, psi0, n_repetitions, n_steps, n_shots, *, t0=1.0, trotter_order=1, verbosity=0, rng=None)[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.

The algorithm estimates the phase \(\varphi = E_0 t_0\) accumulated over the base evolution time \(t_0\). It refines this estimate over n_repetitions iterations 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:
  • H (Hamiltonian) – Hamiltonian object from the Hamiltonian class.

  • 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_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps used to approximate the time evolution. Use EXACT for exact time evolution.

  • n_shots (int or EXACT) – Number of measurement shots used in the Hadamard test. Use EXACT to 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_steps is EXACT.

  • verbosity (int, default 0) – Verbosity level. If >= 1, print intermediate phase estimates.

  • rng (numpy.random.Generator, optional) – Random generator for the Hadamard-test sampling. Ignored when n_shots is EXACT.

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.rpe_get_hadamard_output(H, psi0, evolution_time, n_steps, n_shots, *, trotter_order=1, rng=None)[source]

Estimate the phase of \(\bra{\psi_0}\exp(-i H t)\ket{\psi_0}\) using Hadamard tests.

This function computes the phase corresponding to the unitary evolution over time \(t\) by evaluating real and imaginary parts via Hadamard tests.

Parameters:
  • H (Hamiltonian) – Hamiltonian object defining the system.

  • psi0 (MatrixProductState) – Initial quantum state \(\ket{\psi_0}\).

  • evolution_time (float) – Time to evolve in \(\exp(-iHt)\).

  • n_steps (int or qpe_toolbox.EXACT) – Number of Trotter steps. Use EXACT for exact time evolution.

  • n_shots (int or qpe_toolbox.EXACT) – Number of measurement shots used in the Hadamard test. Use EXACT to compute probabilities exactly.

  • trotter_order (int, default 1) – Order of the Trotter-Suzuki decomposition.

  • rng (numpy.random.Generator, optional) – Random generator threaded through the two Hadamard tests, so the real and imaginary parts use independent samples. Ignored when n_shots is EXACT.

Returns:

phi_m – Estimated phase angle in radians.

Return type:

float

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, π].

Parameters:
  • phi (float or array of float) – First angle in radians.

  • theta (float or array of float) – Second angle in radians.

Returns:

d – Angular distance between phi and theta.

Return type:

float or array of float

qpe_toolbox.estimation.robust_phase_estimation.rpe_update_theta(phi_m, theta_ref, m)[source]

Refine the phase estimate at iteration m.

Parameters:
  • phi_m (float) – Phase estimate at iteration m, in radians.

  • theta_ref (float) – Reference angle (previous phase estimate \(\theta_{m-1}\)).

  • m (int) – Iteration index.

Returns:

theta_m – Refined phase estimate, the candidate nearest to theta_ref, wrapped into \([-\pi, \pi)\).

Return type:

float