bayesian_ae

This module contains the BAYESQAE class. Given a quantum oracle operator, this class estimates the probability of a given target state using the Bayesian Quantum Amplitude Estimation algorithm based on the paper:

Alexandra Ramôa and Luis Paulo Santos Bayesian Quantum Amplitude Estimation https://arxiv.org/abs/2412.04394 (2024)

Author: Gonzalo Ferro Costas & Alexandra Ramôa

class QQuantLib.AE.bayesian_ae.BAYESQAE(oracle: qat.lang.AQASM.QRoutine, target: list, index: list, **kwargs)

Class for Bayesian Quantum Amplitude Estimation algorithm (BAYESQAE)

Parameters:
  • oracle (QLM gate) – QLM gate with the Oracle for implementing the Grover operator

  • 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

  • kwars (dictionary) –

    dictionary that allows the configuration of the BAYESQAE algorithm: Implemented keys:

    qpuQLM solver

    solver for simulating the resulting circuits

    shotsint

    number of measurements on each iteration

    mcz_qlmbool

    for using or not QLM implementation of the multi controlled Z gate

bayesqae(**kwargs)

This function implements BAE algorithm.

Parameters:

kwargs (dictionary) – Configuration of the BAYESQAE algorithm

Returns:

  • a_m (float) – mean for the probability to be estimated

  • a_l (float) – lower bound for the probability to be estimated

  • a_u (float) – upper bound for the probability to be estimated

fake_quantum_measure_step(m_k, n_k, theta_good=None)

Simulates a Fake Quantum Amplitude Estimation experiment

Parameters:
  • m_k (int) – number of Grover operator applications

  • n_k (int) – number of shots

Returns:

p_k – probability of getting the Good state

Return type:

float

property index

creating index property

optimize_control(thetas, weights, control_bayes_shots, **kwargs)

Get the optimal control that minimizes an input utility function given an SMC prior probability

Parameters:
  • thetas (numpy array) – SMC Prior distribution of the desired parameter. Parameter Values

  • weights (numpy array) – SMC Prior distribution of the desired parameter. Weights.

  • control_shots (int) – Shots for simulating virtual QAE experiments mandatory for computing the expected values of the utility function

Returns:

m_opt – Optimal control based on the minimization of an utility function and a domain interval control

Return type:

int

property oracle

creating oracle property

quantum_measure_step(m_k, n_k)

Create the quantum routine and execute the measurement.

Parameters:
  • m_k (int) – number of Grover operator applications

  • n_k (int) – number of shots

Returns:

  • p_k (float) – probability of getting the Good state

  • routine (QLM Routine object) – qlm routine for the QAE step

run()

run method for the class.

Returns:

amplitude estimation parameter

Return type:

self.ae

property target

creating target property

QQuantLib.AE.bayesian_ae.LW_kernel(theta, **kwargs)

Liu-West kernel. Perturbation kernel used for enhancing resampling

Parameters:
  • theta (numpy array) – Input parameters from a SMC probability distribution.

  • kwargs (alpha_lw : float) – coeficient for creating new thetas

Returns:

new_theta – Perturbed parameters for SMC probability distribution using Liu-West kernel

Return type:

numpy array

QQuantLib.AE.bayesian_ae.Metropolis_kernel(theta, m_k, n_k, o_k, **kwargs)

Metropolis kernel. Perturbation kernel used for enhancing resampling

Parameters:
  • theta (numpy array) – Input parameters from a SMC probability distribution.

  • m_k (list) – Exponent of the Grover operator of the QAE experiment

  • n_k (list) – Number of shots of the QAE experiment

  • o_k (list) – Outcome of the QAE experiment

  • kwargs (c : float) – coeficient for standard deviation multiplication

Returns:

new_theta – Perturbed parameters for SMC probability distribution using Metropoli kernel

Return type:

numpy array

QQuantLib.AE.bayesian_ae.average_expectation(thetas, weights, m_k, n_k, **kwargs)

Computes the average expected value of a function for all posible outcomes froma QAE experiment with control m_k and number of shots n_k given a SMC prior probability function.

Parameters:
  • thetas (list) – SMC Prior distribution of the desired parameter. Parameter Values

  • weights (list) – SMC Prior distribution of the desired parameter. Weights.

  • m_k (int) – Exponent of the Grover operator of the QAE experiment

  • n_k (int) – Number of shots of the QAE experiment

  • kwargs (utility_function : function) – Function for computing its average expectation

Returns:

value_ – Desired average expectation

Return type:

float

QQuantLib.AE.bayesian_ae.bayesian_update(thetas, weights, m_k, n_k, o_k, resample=True, **kwargs)

Given a SMC prior probabilty distribution and a outcome of QAE experiment returns the SMC posterior probabilty distribution. It can performs resampling

Parameters:
  • thetas (numpy array) – SMC Prior distribution of the desired parameter. Parameter Values

  • weights (numpy array) – SMC Prior distribution of the desired parameter. Weights.

  • m_k (list) – Exponent of the Grover operator of the QAE experiment

  • n_k (list) – Number of shots of the QAE experiment

  • o_k (list) – Outcome of the QAE experiment

  • kwargs (threshold : float) – Threshold for resampling the SMC probability distribution

Returns:

  • new_thetas (numpy array) – SMC Posterior distribution of the desired parameter. Parameter Values

  • posterior_weights_ (numpy array) – SMC Posterior distribution of the desired parameter. Weights.

QQuantLib.AE.bayesian_ae.confidence_intervals(thetas, weights, delta)

Computes the confidence intervals for a confidence level delta of a given SMC probability distribution

Parameters:
  • thetas (list) – SMC Prior distribution of the desired parameter. Parameter Values

  • weights (list) – SMC Prior distribution of the desired parameter. Weights.

  • delta (float) – Desired confidence level

Returns:

  • theta_lower (float) – Lower value for confidence interval

  • theta_upper (float) – Upper value for confidence interval

QQuantLib.AE.bayesian_ae.ess(weights)

Compute the Effective Sample Size for an input weights

Parameters:

weights (numpy array) – array with the weights

Returns:

ess_ – efective sample size

Return type:

float

QQuantLib.AE.bayesian_ae.posterior_weights(thetas, weights, m_k, n_k, o_k)

Compute posterior probability weights given an input QAE experiment and a SMC prior probability distribution.

Parameters:
  • thetas (numpy array) – SMC Prior distribution of the desired parameter. Parameter Values

  • weights (numpy array) – SMC Prior distribution of the desired parameter. Weights.

  • m_k (int) – Exponent of the Grover operator of the QAE experiment

  • n_k (int) – Number of shots of the QAE experiment

  • o_k (int) – Outcome of the QAE experiment

Returns:

posterior_weights_ – Posterior distribution given the outcome of the QAE experiment

Return type:

numpy array

QQuantLib.AE.bayesian_ae.variance_function(thetas, weights, **kwargs)

Computes the exprected value of the variance for a SMC probability distribution

Parameters:
  • thetas (list) – SMC Prior distribution of the desired parameter. Parameter Values

  • weights (list) – SMC Prior distribution of the desired parameter. Weights.

Returns:

variance – Expected value of the variance under the input SMC probability distribution

Return type:

float

QQuantLib.AE.bayesian_ae.weighted_expectaction(thetas, weights, m_k, n_k, o_k, **kwargs)

Computes the expected value of an input utility function for a given outcome of a QAE experiment (m_k, n_k, h_k) and a SMC prior probability weighted by the total probability getting the o_k outcome.

Parameters:
  • thetas (list) – SMC Prior distribution of the desired parameter. Parameter Values

  • weights (list) – SMC Prior distribution of the desired parameter. Weights.

  • m_k (int) – Exponent of the Grover operator of the QAE experiment

  • n_k (int) – Number of shots of the QAE experiment

  • o_k (int) – Outcome of the QAE experiment

  • kwargs (utility_function : function) – Desired utility function for computing the expected value

Returns:

weighted_expectation_ – product of the expected value function for a given QAE experiment result and the probability of the given result

Return type:

float