Open diehoq opened 4 months ago
Hi Diego, I fixed the issue within https://github.com/eclipse-qrisp/Qrisp/commit/46bdb971c3dc720ed0d24eacca00d10d11ca34f0 . Your code unfortunately has more problems. The QuantumVariables res and r are allocated within the function and are not being uncomputed. This should however be managable by allocating res and r prior to the conjugation and replacing the line r = p - r with an in-place function.
The following in-place function should do :)
from qrisp import *
# Performs a modular inplace right subtraction, ie.
# r = p - r
def inpl_rsub(r, p):
x(r)
r.inpl_adder(r.modulus+1, r)
r += p
# Test function for a variety of inputs
for n in [5, 7, 13, 17, 19]:
for p in range(n):
r = QuantumModulus(n)
h(r)
init_r = r.duplicate(init = True)
inpl_rsub(r, p)
mes_res = multi_measurement([init_r, r])
for init_r, r in mes_res.keys():
if init_r is np.nan:
continue
if (p - init_r)%n != r:
print(f"Adder failed for input constellation r = {init_r}, p = {p}")
raise
Thank you for the fix. I get what you mean for the QuantumVariable res, but r is indeed uncomputed within the algorithm. Do you mean something else?
With the line r = r - p You create a new QuantumVariable and call it r. The reference to the previous r is lost. The new r is uncomputed, while the old r stays alive. You can fix it by using the in-place function that I gave, because it doesn't create a new QuantumVariable
Ah yes, indeed, and in this case you won't need to allocate it prior the conjugation
The following code raises Exception: Tried to perform operation cswap on unallocated qubit qbl_392.0, which seems to be a bug
ERROR: