Use this file to discover all available pages before exploring further.
View on GitHub
Open this notebook in GitHub to run it yourself
Quantum Phase Estimation (QPE) is a fundamental quantum function, at the core of the Shor, HHL, and amplitude estimation algorithms. QPE is a second order function, getting a quantum function U and returning an estimation of its eigenvalues. (Recall that any quantum function represents a unitary matrix.) A QPE that encodes the eigenvalues on m qubits involves a series of m controlled operations of U2k with 0≤k<m−1.This quantum advantage based on the QPE function relies on an ability to implement the power of a given unitary U efficiently. Otherwise, naive U is called ∑k=0m−12k=2m times – a number
that is exponential in the number of qubits.This tutorial shows how to leverage declarative and programmatic modeling for exploring the QPE function in the context of Hamiltonian simulation.Start with basic import:
Define a flexible QPE function.Instead of getting a single operand U, it gets a parametric operand, U(p), where p is an integer such that U(p)≡Up.That is, the power logic of U passes explicitly with the function. In addition, the QPE itself has an integer parameter for the phase register size.
Example QPE for Finding the Eigenvalues of an Hermitian Matrix
One use of the QPE is to find the eigenvalues of a given Hermitian matrix H.Canonical use cases: (a) the HHL algorithm for solving linear equations H⋅x=b, where the matrix eigenvalues need to be stored on a quantum register, and (b) finding the minimal energy of a molecule Hamiltonian H, preparing an initial guess for an eigenvector followed by a QPE that aims to detect the minimal eigenvalue.In both use cases, a QPE is performed on Hamiltonian evolutionU=e2πiH.
Hamiltonian evolution, or Hamiltonian simulation, is one of the promising uses of quantum computers, where the advantage over classical approaches is clear and transparent (as proposed by Richard Feynman in 1982). Nevertheless, constructing a quantum program for efficient Hamiltonian dynamics is not an easy task.The most common examples use approximated product formulas such as the Trotter-Suzuki (TS) formulas.
Write the Hamiltonian as a sum of Pauli strings H=∑i=0L−1a(k)P(k),
where a(k) are complex coefficients, and each of P(k) is a Pauli string of the form s0⊗s1⊗⋯⊗sL, with si∈{I,X,Y,Z}.Approximating Hamiltonian simulation with TS of order 1 refers to:e2πiH≈(Πi=0L−1era(k)P(k))r,where r is called the number of repetitions.
Given a Hamiltonian and a functional error ϵ, what is the required number of repetitions?
Apparently, this is not easy to answer.The literature provides several bounds for the number of repetitions for a given functional error and error metric; however, typically, these bounds are very rough, far from representing the actual number of repetitions to use.See Ref.[1] for a comprehensive study.
When performing a QPE, the challenge is even more pronounced:
For the QPE, a series of Hamiltonian simulations with an exponentially growing evolution coefficient, e2πiH,e212πiH,e222πiH,…,e2m−12πiH, is required.Which product formula to use for each step, assuming you keep the same error per step?Lacking good theoretical bounds for the aforementioned questions, resort to experimental exploration in the hope of finding theoretical clues and insights:
2.1.2 A Flexible TS for Plugging into the Flexible QPE
The Trotter-Suzuki of order 1 function, TS1, gets an Hamiltonian H, evolution coefficient t, and repetition r.Define a wrapper function:TS~1(H,t,p):=TS1(H,pt,r=f(p)).The function f(p) tries to capture how many repetitions can approximate (e2πiH)p=ep2πiH.Section 2.2 defines the “goodness of approximation”.Define ansatz for the repetition scaling f(p):f(p)≡{r0r0⌈(p/p0)γ⌉if p<p0,if p≥p0,where r0, p0, and γ are parameters to tune.
In this tutorial, the measure for goodness of approximation refers to the functionality of the full QPE function, rather than taking a rigorous operator norm per each Hamiltonian simulation step in the QPE.Ways of examining the approximated QPE:
By its ability to approximate an eigenvalue for a given eigenvector.
By comparing its resulting phase state with the one that results from a QPE with an exact Hamiltonian evolution, using a swap test.
Define auxiliary functions for parsing the PauliOperator object.For the demonstration, choose one of the eigenvectors of the matrix, and test the result of the approximated QPE with respect to the expected eigenvalue.
import numpy as npa_mat = pauli_operator_to_matrix(po).realw, v = np.linalg.eig(a_mat)chosen_eig = 2print("chosen eigenvector:", v[:, chosen_eig])print("the eigenvalue to estimate:", w[chosen_eig])
Output:
chosen eigenvector: [-0.08272059 -0.41789454 0.90270987 -0.06030213] the eigenvalue to estimate: 0.7031971279434319
*Note: For this example, the most naive upper bound for TS formula of order 1 and error ϵ=0.1 (defined by a spectral norm) gives r=O(4t2) [2], with t=2π for the first QPE step.This corresponds to r0∼160, and the following QPE steps grow exponentially rk∼160×4k.The result is a huge circuit depth, which you can relax by tuning the parameters of the ansatz.*Tighter bounds based on commutation relations[1] can give more reasonable numbers. However, the main purpose of this tutorial is to highlight the advantages of abstract, high-level modeling. Indeed, any known bound can be incorporated in the flexible Trotter-Suzuki by defining f(m) accordingly.
Continue with the same parameters from above for f(p).Construct a model that calls two QPEs in parallel; one with an approximated Hamiltonian simulation and the other with an exact one. Finally, perform a swap test between the resulting phases.Synthesize the model and visualize the resulting quantum program.
The results are good.You can try to reduce the r0 and/or γ parameters, and experimentally study the relation between the functional error and circuit depth.