Decorator to turn a function returning a QuantumVariable into an in-place function. This can be helpful for manual uncomputation if we have a function returning some QuantumVariable, but we want the result to operate on some other variable, which is supposed to be uncomputed.
A function returning a QuantumVariable.
A function which performs the same operation as the input but now has the keyword argument target. Every instruction that would have been executed on the input functions result is executed on the QuantumVariable specified by target instead.
Given function did not return a QuantumVariable
Tried to redirect quantum function into QuantumVariable of differing size
We create a function that determins the AND value of its inputs and redirect it onto another QuantumBool.
from qrisp import QuantumBool, mcx, redirect_qfunction #This function has only two arguments and returns its result def AND(a, b): res = QuantumBool() mcx([a,b], res) return res a = QuantumBool(name = "a") b = QuantumBool(name = "b") c = QuantumBool(name = "c") #This function has two arguments and the keyword argument target redirected_AND = redirect_qfunction(AND) redirected_AND(a, b, target = c)
QuantumCircuit: -------------- b.0: ──■── │ a.0: ──■── ┌─┴─┐ c.0: ┤ X ├ └───┘ Live QuantumVariables: --------------------- QuantumBool b QuantumBool a QuantumBool c