Skip to content

Commit d31ce23

Browse files
committed
Updates IQAE documentation
1 parent 3fad319 commit d31ce23

File tree

4 files changed

+47
-56
lines changed

4 files changed

+47
-56
lines changed

documentation/source/reference/Primitives/IQAE.rst

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,5 @@ Iterative Quantum Amplitude Estimation
55

66
.. currentmodule:: qrisp
77

8-
.. autofunction:: acc_IQAE
8+
.. autofunction:: IQAE
99

10-
.. autofunction:: quantCirc
11-
12-
.. autofunction:: compute_thetas
13-
14-
.. autofunction:: update_angle
15-
16-
.. autofunction:: compute_Li

documentation/source/reference/Primitives/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This submodule of Qrisp provides a collection of commonly used buildings blocks
1818
* - :ref:`Quantum Amplitude Estimation <QAE>`
1919
- estimating the amplitude of a target state
2020
* - :ref:`Iterative Quantum Amplitude Estimation <IQAE>`
21-
- resource efficient QAE
21+
- resource efficient quantum amplitude estimation
2222
* - :ref:`phase_polynomials`
2323
- provides functions for applying diagonal Hamiltonians given by polynomials
2424
* - :ref:`Grover's Algorithm <grover_tools>`

src/qrisp/alg_primitives/iterative_qae.py

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,16 @@
2020
import numpy as np
2121

2222

23-
def acc_IQAE(qargs,state_function, oracle_function, eps, alpha, kwargs_oracle = {}):
23+
def IQAE(qargs,state_function, oracle_function, eps, alpha, kwargs_oracle = {}):
2424
r"""
25-
Accelerated Quantum Amplitude Estimation (IQAE). This function performs QAE with a fraction of the quantum resources of the well known QAE algorithm.
26-
See `Accelerated Quantum Amplitude Estimation without QFT <https://arxiv.org/abs/2407.16795>`_
25+
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>`_.
26+
See `Accelerated Quantum Amplitude Estimation without QFT <https://arxiv.org/abs/2407.16795>`_.
27+
28+
The problem of quantum amplitude estimation is described as follows:
29+
30+
* Given a unitary operator :math:`\mathcal{A}`, let :math:`\ket{\Psi}=\mathcal{A}\ket{0}`.
31+
* Write :math:`\ket{\Psi}=\ket{\Psi_1}+\ket{\Psi_0}` as a superposition of the orthogonal good and bad components of :math:`\ket{\Psi}`.
32+
* Find an estimate for :math:`a=\langle\Psi_1|\Psi_1\rangle`, the probability that a measurement of $\ket{\Psi}$ yields a good state.
2733
2834
Parameters
2935
----------
@@ -38,48 +44,46 @@ def acc_IQAE(qargs,state_function, oracle_function, eps, alpha, kwargs_oracle =
3844
A Python function tagging the good state :math:`\ket{\Psi_1}`.
3945
This function will receive the variables in the list ``args`` as arguments in the
4046
course of this algorithm.
41-
eps: Float
42-
Accuracy of the algorithm. Choose to be :math:`> 0`. See paper for explanation.
43-
alpha: Float
44-
Confidence level of the algorithm. Choose to be :math:`\in (0,1)`. See paper for explanation.
47+
eps : float
48+
Accuracy $\epsilon>0$ of the algorithm.
49+
alpha : float
50+
Confidence level $\alpha\in (0,1)$ of the algorithm.
4551
kwargs_oracle : dict, optional
4652
A dictionary containing keyword arguments for the oracle. The default is {}.
4753
4854
Returns
4955
-------
50-
a_l, a_u : Float, Float
51-
Confidence bounds on the amplitude which is to be estimated.
56+
a : float
57+
An enstimate $\hat{a}$ of $a$ such that
58+
59+
.. math::
60+
61+
\mathbb P\{|\hat{a}-a|<\epsilon\}\geq 1-\alpha
5262
5363
Examples
5464
--------
5565
56-
We show the same QAE **Numerical integration** example which can also be found in the original QAE documentation.
66+
We show the same **Numerical integration** example which can also be found in the :ref:`QAE documentation <QAE>`.
5767
5868
We wish to evaluate
5969
6070
.. math::
6171
6272
A=\int_0^1f(x)\mathrm dx.
6373
64-
For this, we set up the corresponding ``state_function`` acting on the ``input_list``:
74+
For this, we set up the corresponding ``state_function`` acting on the variables in ``input_list``:
6575
6676
::
6777
68-
from qrisp import QuantumFloat, QuantumBool, control, z, h, ry, QAE
78+
from qrisp import QuantumFloat, QuantumBool, control, z, h, ry, IQAE
6979
import numpy as np
7080
7181
n = 6
7282
inp = QuantumFloat(n,-n)
7383
tar = QuantumBool()
7484
input_list = [inp, tar]
75-
76-
We define the oracle:
7785
78-
def oracle_function(qb):
79-
z(qb)
80-
81-
82-
For the ``state_function`` we want to evaluate $f(x)=\sin^2(x)$:
86+
For example, if $f(x)=\sin^2(x)$, the ``state_function`` can be implemented as follows:
8387
8488
::
8589
@@ -91,24 +95,27 @@ def state_function(inp, tar):
9195
with control(inp[k]):
9296
ry(2**(k+1)/N,tar)
9397
94-
Finally, we apply QAE and obtain an estimate $a$ for the value of the integral $A=0.27268$.
98+
We define the ``oracle_function``:
99+
100+
::
101+
102+
def oracle_function(inp, tar):
103+
z(inp)
104+
105+
Finally, we apply IQAE and obtain an estimate $a$ for the value of the integral $A=0.27268$.
95106
96107
::
97108
98109
eps = 0.01
99110
alpha = 0.01
100111
101-
a_l, a_u = acc_QAE(input_list, state_function, oracle_function,eps=eps, alpha=alpha )
112+
a = IQAE(input_list, state_function, oracle_function, eps=eps, alpha=alpha)
102113
103-
>>> a_l
114+
>>> a
104115
0.26782038552705856
105116
106-
>>> a_u
107-
0.2741565776801965
108-
109117
"""
110118

111-
112119
E = 1/2 * pow(np.sin(np.pi * 3/14), 2) - 1/2 * pow(np.sin(np.pi * 1/6), 2)
113120
F = 1/2 * np.arcsin(np.sqrt(2 * E))
114121

@@ -119,32 +126,30 @@ def state_function(inp, tar):
119126
K_i = 1
120127
m_i = 0
121128
index_tot = 0
122-
while break_cond > 2 * eps :
129+
while break_cond > 2 * eps:
123130
index_tot +=1
124131

125132
alp_i = C*alpha * eps * K_i
126133
N_i = int(np.ceil(1/(2 * pow(E, 2) ) * np.log(2/alp_i) ) )
127134

128-
# perform quantum-stuff
135+
# Perform quantum step
129136
qargs_dupl = [qarg.duplicate() for qarg in qargs]
130137
A_i = quantCirc( int((K_i -1 )/2) , N_i, qargs_dupl, state_function,
131138
oracle_function, kwargs_oracle )
132139

133140
for qarg in qargs_dupl:
134141
qarg.delete()
135142

136-
137143
#for qarg in qargs_dupl:
138144
#qarg.delete()
139145

140-
# compute new thetas
146+
# Compute new thetas
141147
theta_b, theta_sh = compute_thetas(m_i, K_i, A_i, E)
142-
#compute new Li
148+
# Compute new Li
143149
L_new, m_new = compute_Li(m_i , K_i, theta_b, theta_sh)
144150

145151
m_i = m_new
146152
K_i = L_new * K_i
147-
148153

149154
break_cond = abs( theta_b - theta_sh )
150155

@@ -153,19 +158,17 @@ def state_function(inp, tar):
153158
return final_res
154159

155160

156-
157-
def quantCirc(k,N, qargs,state_function,
158-
oracle_function, kwargs_oracle ):
161+
def quantCirc(k, N, qargs, state_function, oracle_function, kwargs_oracle):
159162
"""
160163
Performs the quantum diffusion step, i.e. Quantum Amplitude Amplification,
161164
in accordance to `Accelerated Quantum Amplitude Estimation without QFT <https://arxiv.org/abs/2407.16795>`_
162165
163166
Parameters
164167
----------
165168
k : int
166-
The amount of amplification steps, i.e. the power of :math:`\mathcal{Q}` in amplitude amplification.
169+
The amount of amplification steps, i.e., the power of :math:`\mathcal{Q}` in amplitude amplification.
167170
N : int
168-
The amount of shots, i.e. the amount of times the last qubit is measured after the amplitude amplification steps.
171+
The amount of shots, i.e., the amount of times the last qubit is measured after the amplitude amplification steps.
169172
state_function : function
170173
A Python function preparing the state :math:`\ket{\Psi}`.
171174
This function will receive the variables in the list ``args`` as arguments in the
@@ -192,15 +195,14 @@ def quantCirc(k,N, qargs,state_function,
192195
res_dict = qargs[-1].get_measurement(shots = N)
193196

194197
# case of single dict return, this should not occur but to be safe
195-
if True not in list(res_dict.keys()):
198+
if True not in list(res_dict.keys()):
196199
return 0
197200

198201
a_i = res_dict[True]
199202

200203
return a_i
201204

202205

203-
204206
# theta arithmetics
205207
def compute_thetas(m_i, K_i, A_i, E):
206208
"""
@@ -219,7 +221,6 @@ def compute_thetas(m_i, K_i, A_i, E):
219221
:math:`\epsilon` limit
220222
"""
221223

222-
223224
b_max = max(A_i - E, 0)
224225
sh_min = min(A_i + E, 1)
225226

@@ -235,13 +236,12 @@ def compute_thetas(m_i, K_i, A_i, E):
235236
return theta_b, sh_theta
236237

237238

238-
239239
def update_angle(old_angle, m_in):
240240
"""
241-
Subroutine to compute new angles
241+
Subroutine to compute new angles#
242+
242243
Parameters
243244
----------
244-
245245
old_angle : Float
246246
Ond angle from last iteration.
247247
m_in : Int
@@ -269,8 +269,6 @@ def update_angle(old_angle, m_in):
269269
return final_intermed
270270

271271

272-
273-
274272
def compute_Li(m_i , K_i, theta_b, theta_sh):
275273
"""
276274
Helper function to perform statistical evaluation and compute further values for the next iteration.

src/qrisp/algorithms/qmci.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
********************************************************************************/
1717
"""
1818

19-
from qrisp import h, acc_IQAE, cx, z, auto_uncompute, QuantumBool
19+
from qrisp import h, IQAE, cx, z, auto_uncompute, QuantumBool
2020

2121
def uniform(*args):
2222
for arg in args:
@@ -90,7 +90,7 @@ def oracle_function(*args):
9090
tar = args[2]
9191
z(tar)
9292

93-
a = acc_IQAE(qargs, state_function, oracle_function, eps= 0.01, alpha= 0.01)
93+
a = IQAE(qargs, state_function, oracle_function, eps=0.01, alpha=0.01)
9494

9595
V = V0*a
9696
return V

0 commit comments

Comments
 (0)