Skip to main content

View on GitHub

Open this notebook in GitHub to run it yourself
Quantum Likelihood Estimation (QLE) [1, 2], is a hybrid algorithm for Hamiltonian learning, originally proposed for efficiently learning Hamiltonians from quantum experiments. The basic setting is that the algorithm can access the true Hamiltonian only through the evolution it generates, namely the unitary U(t)=e−iHtU(t)=e^{-iHt} for an arbitrarily chosen time tt. Such experiments on the true physical system are considered an expensive resource, analogous to oracle queries, and the goal is to perform as few experiments as possible. QLE has also been demonstrated experimentally [4]. Ref. [3] suggested an optimized approach based on an information-theoretic framework, minimizing the number of oracle calls by jointly optimizing all circuit parameters at each iteration. The QLE problem is defined as follows:
  • Input: A set of possible Hamiltonians that may govern the system.
  • Promise: One of the Hamiltonians is the true Hamiltonian of the system.
  • Output: The The true Hamiltonian.

Keywords: Hamiltonian learning, hybrid quantum-classical algorithms, Bayesian inference.
This notebook implements the Optimal Quantum Likelihood Estimation algorithm, as proposed in Ref. [3], and was developed in collaboration with the paper authors. As a reference, we also implement a naive Quantum Likelihood Estimation.
QLE frames Hamiltonian learning as Bayesian inference: a prior (“weights”) over a discrete set of candidate Hamiltonians is updated iteratively from measurement outcomes obtained after evolving the system for a chosen time tt. Thus, a quantum iteration consists of preparation, evolution and measurement. Between each two quantum steps, there is a classical processing phase, where we update the weights and design the next quantum step based on the weights. The efficiency of each step depends critically on how informative the measurement is. Standard QLE selects tt heuristically (e.g. via PGH) while keeping the state-preparation and measurement angles fixed. Ref. [3] proposes instead to jointly optimize all five circuit parameters - evolution time tt and angles (α,β,θ,ϕ)(\alpha, \beta, \theta, \phi) - at each iteration, so as to maximize the mutual information I(F;Y)I(F;Y) between the measurement outcome YY and the unknown Hamiltonian FF. The optimization is solved classically via simulated annealing. In the single-qubit benchmark of Ref. [3], this information-theoretic approach converges in roughly an order of magnitude fewer iterations than standard QLE.

Defining a Single Qubit Example

Following Ref. [3] we work with a single qubit example, which underlines the idea behind the optimal, information based optimization. We set the quantum model for a single qubit example The QLE circuit consists of three components. The initial state is parameterized by α∈[0,π]\alpha \in [0, \pi] and β∈[0,2π)\beta \in [0, 2\pi): ∣ψ1⟩=cos⁡(α) ∣0⟩+eiβsin⁡(α) ∣1⟩(1)|\psi_1\rangle = \cos(\alpha)\,|0\rangle + e^{i\beta}\sin(\alpha)\,|1\rangle \qquad (1) (Eq. (8) in Ref. [3]) After Hamiltonian evolution e−iHte^{-iHt}, the measurement basis is rotated by WW, parameterized by θ∈[0,π]\theta \in [0, \pi] and ϕ∈[0,2π)\phi \in [0, 2\pi): W=e−iθσy/2 e−iϕσz/2(2)W = e^{-i\theta\sigma_y/2}\,e^{-i\phi\sigma_z/2} \qquad (2) (Eq. (9) in Ref. [3])
The full circuit maps parameters λ⃗=(α,β,θ,ϕ)\vec{\lambda} = (\alpha, \beta, \theta, \phi) and evolution time tt to a measurement distribution. The probability of outcome a∈{0,1}a \in \{0, 1\} under hypothesis HjH_j is: pj(a)(t,λ⃗)=∣⟨a∣W e−iHjt ∣ψ1⟩∣2(3)p_j^{(a)}(t, \vec{\lambda}) = \bigl|\langle a \mid W\,e^{-iH_j t}\,|\psi_1\rangle\bigr|^2 \qquad (3) (Eq. (6) in Ref. [3]) Since each hypothesis corresponds to a different Hamiltonian, we synthesize one parametric quantum program per hypothesis.

Setting Up a Specific Hamiltonian Set

We define the pool of Hamiltonians and the true index for the demonstration.
Output:
Output:

Classical Functions for Maximum Likelihood

The QLE is based on Bayesian inference. We start with a normalized list of weights, each assigned for the different hypothesis HjH_j: w⃗=(w0,w1,…,wM−1),∑j=0M−1wj=1.\vec{w} = (w_0, w_1,\dots, w_{M-1}), \qquad \sum^{M-1}_{j=0}w_j = 1. Then, upon measuring outcome yy from the true system, the likelihood of hypothesis HjH_j is Lj=pj(y)\mathcal{L}_j = p_j^{(y)}. The Bayesian weight update from step kk to k+1k+1 reads: wj(k+1)=wj(k) pj(y)∑iwi(k) pi(y)(4),w_j^{(k+1)} = \frac{w_j^{(k)}\,p_j^{(y)}}{\displaystyle\sum_i w_i^{(k)}\,p_i^{(y)}} \qquad (4), where the denominator guarantees that the weights vector stays normalized; See (Eq. (7) in Ref. [3]). Below we define the functions get_probs_from_qprog, which computes {pj(a)}a\{p_j^{(a)}\}_a via exact statevector simulation, and bayes_update that performs one step of Eq. (4).

A Standard Quantum Likelihood

In the naive QLE algorithm, we simply follow a series of Bayesian updates, where the evolution time tt at each iteration can varies, and the other model parameters λ⃗\vec{\lambda} are fixed. Here tt is selected by the Particle Guess Heuristic (PGH): draw two hypotheses Hi, HjH_i,\,H_j from the current weight distribution and set t=1∥Hi−Hj∥(5)t = \frac{1}{\|H_i - H_j\|} \qquad (5) (See Ref. [3])
Next, we define the main run_qle function, which iterates the standard QLE loop: select tt via Eq. (5), sample the true Hamiltonian to obtain outcome yy, and apply the Bayes update (Eq. (4)) until the posterior weight of one hypothesis exceeds the convergence threshold.

Run for the Specific Example

Output:
Output:

Plotting the Convergence History

Output:
output

An Optimized Quantum Likelihood

Next, we follow the procedure introduced in Ref. [3]. We find the optimal parameters that maximizes the mutual information, and use simulated annealing for finding them. The optimized QLE selects (t,λ⃗)(t, \vec{\lambda}) by minimizing the conditional Shannon entropy H(F∣Y)H(F|Y) over the current posterior {wj}\{w_j\}: H(F∣Y)=∑yp(y) H(F∣Y=y),p(y)=∑jwj pj(y)(6)H(F|Y) = \sum_y p(y)\,H(F \mid Y{=}y), \qquad p(y) = \sum_j w_j\,p_j^{(y)} \qquad (6) (Eq. (10) in Ref. [3]) Minimizing H(F∣Y)H(F|Y) is equivalent to maximizing the mutual information I(F;Y)I(F;Y) between the true Hamiltonian FF and the measurement outcome YY. Below, we define conditional_entropy_cost_batch that calculates the cost function for a batch of parameters.
We also define two utility functions for wrapping the parameters values in a periodic range (since we consider angles here), and the simulated annealing optimizer optimize_entropy_sa.
Finally we define the main run_optimized_qle function, that runs over the optimized QLE steps. Compared to the standard QLE (run_qle), we replace the PGH with the simulated annealing optimizer: at each iteration the optimal (t,λ⃗)(t, \vec{\lambda}) minimizing H(F∣Y)H(F|Y) is found, the true system is sampled, and the Bayes update (Eq. (4)) is applied.

Run for the Specific Example

Output:
Output:

Plotting the Convergence History

Output:
output

Summary

In this notebook we implemented two versions of the Quantum Likelihood Estimation algorithm: the standard version, and a version that utilizes information-based optimization. We demonstrated that information-based optimization yields faster convergence, compared to the standard version.

References

[1]: Wiebe N, Granade C, Ferrie C and Cory D G 2014 Hamiltonian learning using imperfect quantum resources Phys. Rev. A 89 042314 [2]: Wiebe N, Granade C, Ferrie C and Cory D G 2014 Hamiltonian learning and certification using quantum resources Phys. Rev. Lett. 112 190501 [3]: Levi, Alon and Ossi, Ziv and Cohen, Eliahu and Te’eni, Amit. Optimal quantum likelihood estimation. Quantum Science and Technology 11 015029 (2025) [4]: Wang J et al 2017 Experimental quantum Hamiltonian learning Nat. Phys. 13 551-555