Skip to content

Commit

Permalink
Updates documentation QMCI
Browse files Browse the repository at this point in the history
  • Loading branch information
renezander90 committed Nov 28, 2024
1 parent 86aa503 commit 72f45c8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion documentation/source/general/tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To gradually qrispify your programming game you will start with the basics and g

- :ref:`Implementing Shor's algorithm <shor_tutorial>` will guide you through our state-of-the-art implementation of **Shor's algorithm**, allowing you to factor numbers and fiddle around encrypting and decrypting hidden messages.

- :ref:`The Quantum Monte Carlo Integration tutorial <QMCItutorial>` will show you how to integrate functions with **Quantum Monte Carlo methods**, using **accelerated Iterative Quantum Ampltide Estimation**.
- :ref:`The Quantum Monte Carlo Integration tutorial <QMCItutorial>` will show you how to integrate functions with **Quantum Monte Carlo methods**, using **Iterative Quantum Ampltide Estimation**.

- :ref:`Fault-Tolerant compilation of Shor's algorithm <ft_compilation_shor>` delves into the realm of **compiling for fault-tolerant quantum devices**, exploring the specialized techniques and considerations that set this stage apart from the compilation challenges encountered in NISQ environments. At the end you will also optimize the implementation of Shor's from the tutorial above.

Expand Down
6 changes: 3 additions & 3 deletions src/qrisp/alg_primitives/iterative_qae.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import numpy as np


def IQAE(qargs,state_function, oracle_function, eps, alpha, kwargs_oracle = {}):
def IQAE(qargs, state_function, oracle_function, eps, alpha, kwargs_oracle = {}):
r"""
Accelerated Quantum Amplitude Estimation (IQAE). This function performs :ref:`QAE <QAE>` with a fraction of the quantum resources of the well-known `QAE algorithm <https://arxiv.org/abs/quant-ph/0005055>`_.
See `Accelerated Quantum Amplitude Estimation without QFT <https://arxiv.org/abs/2407.16795>`_.
Expand All @@ -38,11 +38,11 @@ def IQAE(qargs,state_function, oracle_function, eps, alpha, kwargs_oracle = {}):
the quantum amplitude estimation is performed on.
state_function : function
A Python function preparing the state :math:`\ket{\Psi}`.
This function will receive the variables in the list ``args`` as arguments in the
This function will receive the variables in the list ``qargs`` as arguments in the
course of this algorithm.
oracle_function : function
A Python function tagging the good state :math:`\ket{\Psi_1}`.
This function will receive the variables in the list ``args`` as arguments in the
This function will receive the variables in the list ``qargs`` as arguments in the
course of this algorithm.
eps : float
Accuracy $\epsilon>0$ of the algorithm.
Expand Down
29 changes: 23 additions & 6 deletions src/qrisp/algorithms/qmci.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,56 @@ def uniform(*args):


def QMCI(qargs, function, distribution=None):
"""
Implements a general algorithms for `Quantum Monte Carlo Integration <https://www.nature.com/articles/s41598-024-61010-9>`.
r"""
Implements a general algorithm for `Quantum Monte Carlo Integration <https://www.nature.com/articles/s41598-024-61010-9>`_.
This implementation utilizes :ref:`IQAE`. A detailed explanation can be found in the :ref:`tutorial <QMCItutorial>`.
QMCI performs numerical integration of (high-dimensional) functions over probility distributions:
.. math::
\int_{[0,1]^n} f(x_1 , ... , x_n) \mathrm{d}\mu (x_1 , ... , x_n)
Parameters
----------
qargs : list[ref:`QuantumFloat`]
qargs : list[:ref:`QuantumFloat`]
The quantum variables the given ``function`` acts on.
function : function
A Python function which takes :ref:`QuantumFloats <QuantumFloat>` as inputs and applies the ``function`` which is to be integrated.
distribution : function
A Python function which takes :ref:`QuantumFloats <QuantumFloat>` as inputs and applies the distribution over which to integrate.
By default, the uniform distribution is applied.
Returns
-------
float
The result of the integration.
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$ points as specified by ``QuantumFloat(3,-3)``.
Therefore, the function is evaluated at $8=2^3$ sampling points as specified by ``QuantumFloat(3,-3)``.
::
from qrisp import QuantumFloat
from qrisp.algorithms.qmci import *
from qrisp.algorithms.qmci import QMCI
def f(qf):
return qf*qf
qf = QuantumFloat(3,-3)
QMCI([qf], 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
"""
if distribution==None:
Expand Down
31 changes: 31 additions & 0 deletions tests/test_QMCI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
\********************************************************************************
* Copyright (c) 2024 the Qrisp authors
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License, v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is
* available at https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
"""


def test_QMCI():
from qrisp import QuantumFloat
from qrisp.algorithms.qmci import QMCI
import numpy as np

def f(qf):
return qf*qf

qf = QuantumFloat(3,-3)
a = QMCI([qf], f)

assert np.abs(a-0.2734375)<0.01

0 comments on commit 72f45c8

Please sign in to comment.