maximum_likelihood_ae
This module contains the MLAE class. Given a quantum oracle operator, this class estimates the probability of a given target state using the Maximum Likelihood Amplitude Estimation based on the paper:
Suzuki, Y., Uno, S., Raymond, R., Tanaka, T., Onodera, T., & Yamamoto, N. Amplitude estimation without phase estimation Quantum Information Processing, 19(2), 2020 arXiv: quant-ph/1904.10246v2
Author: Gonzalo Ferro Costas & Alberto Manzano Herrero
- class QQuantLib.AE.maximum_likelihood_ae.MLAE(oracle: qat.lang.AQASM.QRoutine, target: list, index: list, **kwargs)
Class for using Maximum Likelihood Quantum Amplitude Estimation (MLAE) algorithm
- Parameters:
oracle (QLM gate) – QLM gate with the Oracle for implementing the Grover operator: init_q_prog and q_gate will be interpreted as None
target (list of ints) – python list with the target for the amplitude estimation
index (list of ints) – qubits which mark the register to do the amplitude estimation
kwargs (dictionary) – dictionary that allows the configuration of the MLAE algorithm
qpu (kwargs, QLM solver) – solver for simulating the resulting circuits
schedule (kwargs, list of two lists) – the schedule for the algorithm
optimizer (kwargs,) – an optimizer with just one possible entry
delta (kwargs, float) – tolerance to avoid division by zero warnings
ns (kwargs, int) – number of grid points for brute scipy optimizer
mcz_qlm (kwargs, bool) – for using or not QLM implementation of the multi controlled Z gate
- static cost_function(angle: float, m_k: list, n_k: list, h_k: list) float
This method calculates the -Likelihood of angle theta for a given schedule m_k,n_k
Notes
\[L(\theta,\mathbf{h}) = -\sum_{k = 0}^M\log{l_k(\theta|h_k)}\]- Parameters:
angle (float) – Angle (radians) for calculating the probability of measure a positive event.
m_k (list of ints) – number of times the grover operator was applied.
n_k (list of ints) – number of total events measured for the specific m_k
h_k (list of ints) – number of positive events measured for each m_k
- Returns:
cost – the aggregation of the individual likelihoods
- Return type:
float
- property index
creating index property
- static likelihood(theta: float, m_k: int, n_k: int, h_k: int) float
Calculates Likelihood from Suzuki paper. For h_k positive events of n_k total events, this function calculates the probability of this taking into account that the probability of a positive event is given by theta and by m_k The idea is use this function to minimize it for this reason it gives minus Likelihood
Notes
\[l_k(\theta|h_k) = \sin^2\left((2m_k+1)\theta\right)^{h_k} \ \cos^2 \left((2m_k+1)\theta\right)^{n_k-h_k}\]- Parameters:
theta (float) – Angle (radians) for calculating the probability of measure a positive event.
m_k (int) – number of times the grover operator was applied.
n_k (int) – number of total events measured for the specific m_k
h_k (int) – number of positive events measured for each m_k
- Returns:
Gives the Likelihood p(h_k with m_k amplifications|theta)
- Return type:
float
- static log_likelihood(theta: float, m_k: int, n_k: int, h_k: int) float
Calculates log of the likelihood from Suzuki paper.
Notes
\[\log{l_k(\theta|h_k)} = 2h_k\log\big[\sin\left((2m_k+1) \ \theta\right)\big] +2(n_k-h_k)\log\big[\cos\left((2m_k+1) \ \theta\right)\big]\]- Parameters:
theta (float) – Angle (radians) for calculating the probability of measure a positive event.
m_k (int) – number of times the grover operator was applied.
n_k (int) – number of total events measured for the specific m_k
h_k (int) – number of positive events measured for each m_k
- Returns:
Gives the log Likelihood p(h_k with m_k amplifications|theta)
- Return type:
float
- mlae(schedule, optimizer)
This method executes a complete Maximum Likelihood Algorithm, including executing schedule, defining the correspondent cost function and optimizing it.
- Parameters:
schedule (list of two lists) – the schedule for the algorithm
optimizer (optimization routine.) – the optimizer should receive a function of one variable the angle to be optimized. Using lambda functions is the recommended way.
- Returns:
result (optimizer results) – the type of the result is the type of the result of the optimizer
h_k (list) – list with number of positive outcomes from quantum circuit for each pair element of the input schedule
cost_function_partial (function) – partial cost function with the m_k, n_k and h_k fixed to the obtained values of the different experiments.
- property oracle
creating oracle property
- run() float
run method for the class.
- Returns:
list with the estimation of a
- Return type:
result
Notes
\[a^* = \sin^2(\theta^*) \; where \; \theta^* = \arg \ \min_{\theta} L(\theta,\mathbf{h})\]
- run_schedule(schedule)
This method execute the run_step method for each pair of values of a given schedule.
- Parameters:
schedule (list of two lists) – the schedule for the algorithm
- Returns:
h_k – list with the h_k result of each pair of the input schedule
- Return type:
list
- run_step(m_k: int, n_k: int) int
This method executes on step of the MLAE algorithm
- Parameters:
m_k (int) – number of times to apply the self.q_gate to the quantum circuit
n_k (int) – number of shots
- Returns:
h_k (int) – number of positive events
routine (QLM Routine object)
- property schedule
creating schedule property
- set_exponential_schedule(n_t: int, n_s: int)
Creates a scheduler of exponential increasing of m_ks.
- Parameters:
n_t (int) – number of maximum applications of the grover operator
n_s (int) – number of shots for each m_k grover applications
- set_linear_schedule(n_t: int, n_s: int)
Creates a scheduler of linear increasing of m_ks.
- Parameters:
n_t (int) – number of maximum applications of the grover operator
n_s (int) – number of shots for each m_k grover applications
- property target
creating target property