Skip to content

Commit df5702c

Browse files
committed
wrote some documentation for the repeat until success component
1 parent 429deac commit df5702c

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. _RUS:
2+
3+
Repeat-Until-Success
4+
====================
5+
6+
.. currentmodule:: qrisp.jasp
7+
.. autofunction:: RUS

documentation/source/reference/Jasp/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,5 @@ If you are interested in how the QIR representation looks like, try calling
133133
QJIT
134134
Jaspr
135135
qache
136-
hb_control_flow
136+
hb_control_flow
137+
RUS

src/qrisp/jasp/rus.py

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,85 @@
1919
from jax.lax import while_loop, cond
2020
import jax
2121

22-
from qrisp.jasp import TracingQuantumSession, check_for_tracing_mode, delete_qubits_p, AbstractQubitArray
22+
from qrisp.jasp import TracingQuantumSession, delete_qubits_p, AbstractQubitArray
2323

2424
def RUS(trial_function):
25+
r"""
26+
Decorator to deploy repeat-until-success (RUS) components. At the core,
27+
RUS repeats a given quantum subroutine followed by a qubit measurement until
28+
the measurement returns the value ``1``. This step is prevalent
29+
in many important algorithms, among them the
30+
`HHL algorithm <https://arxiv.org/abs/0811.3171>`_ or the
31+
`LCU procedure <https://arxiv.org/abs/1202.5822>`_.
32+
33+
Within Jasp, RUS steps can be realized by providing the quantum subroutine
34+
as a "trial function", which returns a boolean value (the repetition condition) and
35+
possibly other return values.
36+
37+
It is important to note that the trial function can not receive quantum
38+
arguments. This is because after each trial, a new copy of these arguments
39+
would be required to perform the next iteration, which is prohibited by
40+
the no-clone theorem. It is however legal to provide classical arguments.
41+
42+
Parameters
43+
----------
44+
trial_function : callable
45+
A function returning a boolean value as the first return value. More
46+
return values are possible.
47+
48+
Returns
49+
-------
50+
callable
51+
A function that performs the RUS protocol with the trial function. The
52+
return values of this function are the return values of the trial function
53+
WITHOUT the boolean value.
54+
55+
Examples
56+
--------
57+
58+
To demonstrate the RUS behavior, we initialize a GHZ state
59+
60+
.. math::
61+
62+
\ket{\psi} = \frac{\ket{00000} + \ket{11111}}{\sqrt{2}}
63+
64+
and measure the first qubit into a boolean value. This will be the value
65+
to cancel the repetition. This will collapse the GHZ state into either
66+
$\ket{00000}$ (which will cause a new repetition) or $\ket{11111}$, which
67+
cancels the loop. After the repetition is canceled we are therefore
68+
guaranteed to have the latter state.
69+
70+
::
71+
72+
from qrisp.jasp import RUS, make_jaspr
73+
from qrisp import QuantumFloat, h, cx, measure
74+
75+
@RUS
76+
def rus_trial_function():
77+
qf = QuantumFloat(5)
78+
h(qf[0])
79+
80+
for i in range(1, 5):
81+
cx(qf[0], qf[i])
82+
83+
cancelation_bool = measure(qf[0])
84+
return cancelation_bool, qf
85+
86+
def call_RUS_example():
87+
88+
qf = rus_trial_function()
89+
90+
return measure(qf)
91+
92+
Create the ``jaspr`` and simulate:
93+
94+
::
95+
96+
jaspr = make_jaspr(call_RUS_example)()
97+
print(jaspr())
98+
# Yields, 31 which is the decimal version of 11111
99+
100+
"""
25101

26102
def return_function(*trial_args):
27103

0 commit comments

Comments
 (0)