eclipse-qrisp / Qrisp

Qrisp - a framework for high-level programming of Quantum computers
https://www.qrisp.eu/
Eclipse Public License 2.0
93 stars 26 forks source link

Bug: IterationEnvironment #82

Open renezander90 opened 1 month ago

renezander90 commented 1 month ago

The following code yields:

Exception: Tried to invoke IterationEnvironment with code creating/deleting QuantumVariables

from qrisp import *

def test(qarg, t, steps):
    rx(np.pi*t/steps,qarg)

def U(qarg, t=1, steps=1, iter=1):
   print(qarg.qs.qv_list)
   with IterationEnvironment(qarg.qs, iteration_amount=iter*steps):
        test(qarg, t, steps)

qv = QuantumVariable(3)
res = QPE(qv,U,precision=3,kwargs={"t":3,"steps":2},iter_spec=True)

It does work for "steps":1. But why does it work in that case anyway? In the first QPE step, qv.qs does not contain the _qperes in any case.

positr0nium commented 1 month ago

This IterationEnvironment behavior is still super clunky. I'll look into it how it can be handled better.

As a hotfix you can call merge([qarg]) as the first command of U. This will merge the qarg qs into the environment qs.