Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ct.lattice(@ct.electron) seems to change function scope #1643

Open
santoshkumarradha opened this issue May 12, 2023 Discussed in #1642 · 8 comments
Open

@ct.lattice(@ct.electron) seems to change function scope #1643

santoshkumarradha opened this issue May 12, 2023 Discussed in #1642 · 8 comments
Labels
good first issue Good for newcomers hacktoberfest Part of Hacktoberfest priority / high One of the top priorities in a week

Comments

@santoshkumarradha
Copy link
Member

Discussed in #1642

Originally posted by utf May 12, 2023
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:

import covalent as ct

@ct.lattice
@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)


dispatch_id = ct.dispatch(fibonacci)(1, 1)
result = ct.get_result(dispatch_id=dispatch_id, wait=True)

The error message I see on the UI is:

Traceback (most recent call last): 
File "/Users/alexganose/opt/miniconda3/envs/jobflow/lib/python3.9/site-packages/covalent/executor/utils/wrappers.py",
    line 47, in io_wrapper output = fn(*args, **kwargs)
File "/Users/alexganose/opt/miniconda3/envs/jobflow/lib/python3.9/site-packages/covalent/executor/base.py",
    line 109, in wrapper_fn output = fn(*new_args, **new_kwargs)
File "<ipython-input-1-ed3627cd8ac8>",
    line 16, in fibonacci NameError: name 'fibonacci' is not defined 

Is this something you would consider supporting in the future?

@Andrew-S-Rosen
Copy link
Contributor

Thanks for highlighting this! Would love to see this one fixed too! 👍🤞

@akshitjohry
Copy link

Hi
I would like to take a stab at this issue. Can you please assign it to me? Thanks

@athanzxyt
Copy link

Hi. So I assume to work on this issue, I have to build the Covalent source code locally; however, I can't seem to find instructions on how to do so. Please let me know where to look to do so or if I am approaching this issue wrong.

@wjcunningham7
Copy link
Member

This issue is a part of Hacktoberfest. Closing this issue will earn you 3 points.

rby added a commit to rby/covalent that referenced this issue Oct 5, 2023
This tries to reproduce the issue in AgnostiqHQ#1643 in a unit test.
However the test passes.
I also tried a functional test locally which passes as well.
rby added a commit to rby/covalent that referenced this issue Oct 5, 2023
This tries to reproduce the issue in AgnostiqHQ#1643 in a unit test.
However the test passes.
I also tried a functional test locally which passes as well.
rby added a commit to rby/covalent that referenced this issue Oct 5, 2023
Adds a unit test that fails to reproduce the issue for recursive
function calls.
@aazam-gh
Copy link

Hello, can I work on this :)

@santoshkumarradha
Copy link
Member Author

Thanks @aazam-gh ! Please feel free to submit a PR whenever you get a chance.

@aazam-gh
Copy link

@santoshkumarradha How do i run the job in VS Code? Do i need to create a separate file? I was able to run some other snippets directly from the python console and see the results in the UI. However this snippet gives me indentation errors.

@santoshkumarradha
Copy link
Member Author

Hey @aazam-gh, the snippet seems to be working fine when directly clicking the copy icon on the issue code. Maybe you accidentally copied some extra characters?

@jimmylism jimmylism added the priority / high One of the top priorities in a week label Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest Part of Hacktoberfest priority / high One of the top priorities in a week
Projects
None yet
Development

No branches or pull requests

8 participants