Quantum Monte Carlo Integration#

QMCI(qargs, function, distribution=None, mes_kwargs={})[source]#

Implements a general algorithm for Quantum Monte Carlo Integration. This implementation utilizes Iterative Quantum Amplitude Estimation. A detailed explanation can be found in the tutorial.

QMCI performs numerical integration of (high-dimensional) functions w.r.t. probability distributions:

\[\int_{[0,1]^n} f(x_1 ,\dotsc , x_n) \mathrm{d}\mu (x_1 ,\dotsc , x_n)\]
Parameters:
qargslist[QuantumFloat]

The quantum variables representing the \(x\)-axes (the variables on which the given function acts), and a quantum variable representing the \(y\)-axis.

functionfunction

A Python function which takes QuantumFloats as inputs, and returns a QuantumFloat containing the values of the integrand.

distributionfunction, optional

A Python function which takes QuantumFloats as inputs and applies the distribution over which to integrate. By default, the uniform distribution is applied.

mes_kwargsdict, optional

The keyword arguments for the measurement function. Default is an empty dictionary.

Returns:
float

The result of the numerical integration.

Examples

We integrate the function \(f(x)=x^2\) over the integral \([0,1]\). Therefore, the function is evaluated at \(8=2^3\) sampling points as specified by QuantumFloat(3,-3). The \(y\)-axis is representend by QuantumFloat(6,-6).

from qrisp import QuantumFloat
from qrisp.qmci import QMCI

def f(qf):
    return qf*qf

qf_x = QuantumFloat(3,-3)
qf_y = QuantumFloat(6,-6)
QMCI([qf_x,qf_y], f)
# Yields: 0.27373180511103606

This result is consistent with numerically calculating the integral by evaluating the function \(f\) at 8 sampling points:

N = 8
sum((i/N)**2 for i in range(N))/N
# Yields: 0.2734375

A detailed explanation of QMCI and its implementation in Qrisp can be found in the QMCI tutorial.