-
Notifications
You must be signed in to change notification settings - Fork 143
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
Update runtime and process to be "with" context managers. #605
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a clean and easy implementation and include tests.
If you want, you could demonstrate this feature in the tutorial about execution:
https://github.com/lava-nc/lava/blob/main/tutorials/in_depth/tutorial04_execution.ipynb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Gavinator98
This looks very nice. Thanks for your work on this feature!
You are testing this feature with the RunContinuous
run condition only, which uses a non-blocking call by default. Could you please also add tests for the RunSteps
condition? One with RunSteps(num_steps=..., blocking=True)
(the default) and one with RunSteps(num_steps=..., blocking=False)
. It should be fine to only test these variants on the Process. You do not have to also test them for the runtime.
I also added a few minor suggestions. Could you please address those as well?
Thanks,
Mathis
Thanks for the feedback, I'll try and address your comments early next week. One question, most of the test code is derived from /tests/lava/magma/runtime/test_run_continuously_and_pause.py Would it make sense to refactor SimpleProcess, etc for both into a utils module? |
Sure, removing code duplication of unit tests is a valuable goal. Go for it and refactor shared code into a module but make sure you do not introduce dependencies between unit tests, where the behavior of one test is influenced by another. You will notice that we have a lot of code duplication in unit test infrastructure throughout Lava tests... Maybe you will set a good example here that others will follow. Thanks for your initiative! |
…ther than redefining it." This reverts commit 2af0ee7.
On further review, a majority of the tests have similar classes to |
Thanks, @Gavinator98 for this great new addition to Lava! If you are interested in contributing further in some form, do not hesitate to reach out. :) |
…lly stop runtime on exit (lava-nc#605) * Update runtime and process to be "with" context managers. Add tests to verify this. * Update docstrings to address feedback * Make process inherit __enter__ from AbstractContextManager rather than redefining it. * Add Stoppable abstract class for typing. * Revert "Make process inherit __enter__ from AbstractContextManager rather than redefining it." This reverts commit 2af0ee7. * Update enter docstring * Add tests for processes started with RunSteps --------- Co-authored-by: PhilippPlank <[email protected]>
Issue Number: #599
Objective of pull request: Update runtime and processes to be Python "with" context managers so it is easier to automatically call stop().
Pull request checklist
Your PR fulfills the following requirements:
flakeheaven lint src/lava tests/
) and (bandit -r src/lava/.
) pass locallypytest
) passes locallyPull request type
Please check your PR type:
What is the current behavior?
What is the new behavior?
Example:
Does this introduce a breaking change?
Supplemental information