|
19 | 19 | from jax.lax import while_loop, cond
|
20 | 20 | import jax
|
21 | 21 |
|
22 |
| -from qrisp.jasp import TracingQuantumSession, check_for_tracing_mode, delete_qubits_p, AbstractQubitArray |
| 22 | +from qrisp.jasp import TracingQuantumSession, delete_qubits_p, AbstractQubitArray |
23 | 23 |
|
24 | 24 | 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 | + """ |
25 | 101 |
|
26 | 102 | def return_function(*trial_args):
|
27 | 103 |
|
|
0 commit comments