Replies: 2 comments 12 replies
-
Hey @utf! Thanks for giving Covalent a shot and welcome to Covalent ! Just wanted to let you know that we fully support recursive functions within electrons. It seems like the issue you ran into is a little bug. But, no worries! A small tweak to the example you provided should solve the problem interim. import covalent as ct
@ct.electron
def fibonacci(smaller, larger, stop_point=1000):
"""Calculate the next number in the Fibonacci sequence.
If the number is larger than stop_point, the job will stop the workflow
execution, otherwise, a new job will be submitted to calculate the next number.
"""
total = smaller + larger
if total > stop_point:
return total
return fibonacci(larger, total, stop_point=stop_point)
@ct.lattice
def w(smaller, larger, stop_point=1000):
return fibonacci(smaller, larger, stop_point=stop_point)
dispatch_id = ct.dispatch(w)(1, 1) I believe that there may be an issue with the lattice decorator preventing the fibonacci function from being available in the local scope. This certainly warrants a bug report. CC: @kessler-frost |
Beta Was this translation helpful? Give feedback.
-
A very quick update, Pattern 1Just tried recursion at electron level, that does seem to work (both with and sans jupyter) import covalent as ct
@ct.electron
def f(x):
"""Calculate the next number in the Fibonacci sequence.
If the number is larger than stop_point, the job will stop the workflow
execution, otherwise, a new job will be submitted to calculate the next number.
"""
x+=1
return x if x>10 else f(x)
@ct.lattice
def w(x):
return f(x)
print("Normal result :",w(1))
dispatch_id = ct.dispatch(w)(1)
print("Covalent result :",ct.get_result(dispatch_id,wait=True).result) Pattern 2with sublattice import covalent as ct
@ct.electron
@ct.lattice
def fibonacci(smaller, larger,function, stop_point=1000):
"""Calculate the next number in the Fibonacci sequence.
If the number is larger than stop_point, the job will stop the workflow
execution, otherwise, a new job will be submitted to calculate the next number.
"""
total = smaller + larger
if total > stop_point:
return total
return function(larger, total, function,stop_point=stop_point)
@ct.lattice
def workflow(smaller, larger, stop_point=1000):
return fibonacci(smaller, larger,fibonacci, stop_point=stop_point)
dispatch_id = ct.dispatch(workflow)(1, 1,1000)
result = ct.get_result(dispatch_id=dispatch_id, wait=True)
print(result) this pattern send the recursive function in as input as well, the bug currently makes it such that the name space inside the inner lattice does not contain the lattice itself. But forcing the lattice as inputs takes away that problem, tho not ideal. Hope this would help until we solve the bug. |
Beta Was this translation helpful? Give feedback.
-
Firstly, thank you for the lovely code. The UI interface is particularly nice and easy to get started with.
One roadblock I've run into is support for recursive functions. For example, the following code snippet doesn't work:
The error message I see on the UI is:
Is this something you would consider supporting in the future?
Beta Was this translation helpful? Give feedback.
All reactions