View on GitHub
Open this notebook in GitHub to run it yourself
- Define classical and quantum functions for constructing the algorithm.
- Take a specific example, a matrix and some initial state.
- Choose a resolution for the solution.
- Find the related eigenvalues using QPE and analyze the results.
Classical functions
Matrix rescaling
As QPE obtains a phase in the form , there is meaning only for . However, the matrix can have any eigenvalue. To fix this discrepancy, the values of the matrix are rescaled. If you can use a normalization function to map those values into . Perform the normalization procedure by: a. Defining the functionget_normalization that finds a rough estimation for the eigenvalue with the largest absolute value.
This yields a value \bar{\lambda} = {\max}\left\{|\lambda_\max|,|\lambda_\min|\right\}, such that you can assume .
b.
Defining the function normalize_hamiltonian that normalizes by the Hamiltonian, and thus its eigenvalues, such that the evaluated span is then .
(Note that in this case correspond to the same phase, however, this is an edge case where the normalized Hamiltonian has exactly those two eigenvalues. To avoid this, you can apply an extra factor of , where is the size of the phase variable).
QPE precision estimator
For QPE algorithms, the precision is set by phase register size , such that the resolution is . If the matrix needs to be normalized, the resolution will be distorted. In the case of normalization, the span of results for the QPE stretches between the lowest and highest possible phase, thus the resolution is mapped to .Quantum functions
Use the built-inqpe_flexible function, which allows you to prescribe the “telescopic” expansion of the powered unitary via the unitary_with_power “QCallable” (see Flexible QPE tutorial).
Define two examples for the powered unitary:
Approximated evolution: A first order Suzuki Trotter with power-logic
Wrap the Trotter-Suzuki function of order 2 with a “power-logic” for the repetition as a function of its power.Setting a specific example
Set the matrix
Define the matrix to submit. This can be any Hermitian matrix with size by with a positive integer. Throughout the code this matrix is given in the variableM.
Set the initial vector
Choose the vector that will be defined later as the initial condition for the run. There are two options: (1) define a random initial vector, or (2) choose some eigenvector of the matrix. For the demonstration, proceed with the first option:Output:
Preparing the matrix for QPE
Output:
Choose the algorithm’s precision
Choose the precision using then_qpe parameter or set your desired resolution.
Output:
Normalize the matrix
Transform the matrix to ensure its eigenvalues are between to . The QPE procedure is performed on the new normalized matrix. After the phases are obtained, gather the original phases of the pre-normalized matrix by performing opposite steps to this normalization procedure.Building the quantum model
Create a quantum model of the QPE algorithm using the Classiq platform with your desired constraints and preferences. Run two different models, with a unitary implementation, which is exact; or with an approximated prodcut formula. Synthesize the models and compare the resulting quantum programs. The exact version is a non-scalable approach, but a convenient one for small usecases.Output:
Output:
Measuring and analyzing the results
Execute the quantum programs and analyze the results, in comparison to the expected classical ones.Execute the quantum program
Send the quantum programs for execution by a chosen backend and print the raw results.number_of_solutions value determines how many results are analyzed.
Get the solution by multiplying back the normalization coefficient.
Output:
Plot the solution’s histogram and compare to classical results
Output:

References
[1]: [Michael A. Nielsen and Isaac L. Chuang. 2- Quantum Computation and Quantum Information: 10th Anniversary Edition, Cambridge University Press, New York, NY, USA. ](https://archive.org/details/QuantumComputationAndQuantumInformation10thAnniversaryEdition)