-
Notifications
You must be signed in to change notification settings - Fork 11
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
Introduce Parallel Execution Component and Make Args & Components Copyable #332
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…nnections Explicit
The RunParallelThread component runs its body on an independent thread. As that allows parallel execution of the body, it needs to be copied so the independent execution threads don't walk all over each other. They are also executed with a copy of the context. For that reason changes to the context don't propagate out.
MFA-X-AI
requested changes
Jun 17, 2024
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.
Awesome! Looks like it works in the base case.
I've noticed that the outArgs for Finish
need to be updated for workflow components. Here's an example:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File ~\Documents\Github\xircuits-parallel\xai_components\xai_utils\RunParallelExample.py:45
43 parser = ArgumentParser()
44 (args, _) = parser.parse_known_args()
---> 45 main(args)
46 print('\nFinished Executing')
File ~\Documents\Github\xircuits-parallel\xai_components\xai_utils\RunParallelExample.py:39, in main(args)
37 ctx = {}
38 ctx['args'] = args
---> 39 flow = RunParallelExample()
40 flow.next = None
41 flow.do(ctx)
File ~\Documents\Github\xircuits-parallel\xai_components\xai_utils\RunParallelExample.py:16, in RunParallelExample.__init__(self)
14 self.c_1 = RunParallelThread()
15 self.c_2 = Print()
---> 16 self.c_3 = InnerSleep()
17 self.c_0.items.value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
18 self.c_1.n_workers.value = 3
File ~\Documents\Github\xircuits-parallel\xai_components\xai_utils\InnerSleep.py:17, in InnerSleep.__init__(self)
15 self.c_0.less_than.value = 2
16 self.c_1.sleep_timer.connect(self.c_0.value)
---> 17 self.output.connect(self.c_0.value)
18 self.c_0.next = self.c_1
19 self.c_1.next = None
AttributeError: 'OutArg' object has no attribute 'connect'
MFA-X-AI
approved these changes
Jun 17, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
A long standing issue with Xircuits is that we can only really do things in serial. One of the reasons for that is that the component connections are all set up at initialization. When we run things in parallel, that setup results in concurrent reads and writes.
This PR introduces
__copy__
and__deepcopy__
implementations forInArg
,OutArg
,InCompArg
andBaseComponent
as well as a connection setup that will continue to work with copies.Allowing copies of a sub-graph thereby allows us to run them in parallel. An utility component
RunParallelThread
can be used together with any iterating component to easily enable parallel execution of that iteration. This is especially useful when it is IO heavy.As this PR includes changes to
xai_components/base.py
and compiler changes that depend on that particular change, users will have to update theirbase.py
file, for that reason I'm marking this as a breaking change. Failing to do so will result in the following error message when trying to run a compiled file:RunParallelExample.xircuits
inxai_utils
includes an example for howRunParallelThread
can be used:Pull Request Type
Type of Change
Tests
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
**1. Use RunParallelExample.xircuits **
Tested on?