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