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

Introduce Parallel Execution Component and Make Args & Components Copyable #332

Merged
merged 6 commits into from
Jun 17, 2024

Conversation

treo
Copy link
Contributor

@treo treo commented Jun 17, 2024

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 for InArg, OutArg, InCompArg and BaseComponent 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 their base.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:

AttributeError: 'InArg' object has no attribute 'connect'

RunParallelExample.xircuits in xai_utils includes an example for how RunParallelThread can be used:
image

Pull Request Type

  • Xircuits Core (Jupyterlab Related changes)
  • Xircuits Canvas (Custom RD Related changes)
  • Xircuits Component Library
  • Xircuits Project Template
  • Testing Automation
  • Documentation
  • Others (Please Specify)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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 **

1. Compile the file
2. Run it
3. See the output showing that each thread is sleeping a random amount of time and then outputs its input element, thereby showing that all elements are processed correctly, and they run in parallel instead of sequentially. 

Tested on?

  • Windows
  • Linux Ubuntu
  • Centos
  • Mac
  • Others (State here -> xxx )

treo added 4 commits June 17, 2024 12:03
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.
@treo treo requested a review from MFA-X-AI June 17, 2024 13:58
Copy link

Binder 👈 Launch a binder notebook on branch XpressAI/xircuits/paul/copy-able-connections

Copy link
Member

@MFA-X-AI MFA-X-AI left a 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:

image
image

---------------------------------------------------------------------------
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 MFA-X-AI merged commit c34d411 into master Jun 17, 2024
8 checks passed
@MFA-X-AI MFA-X-AI deleted the paul/copy-able-connections branch June 17, 2024 16:08
@MFA-X-AI MFA-X-AI restored the paul/copy-able-connections branch June 17, 2024 16:08
@treo treo mentioned this pull request Jun 18, 2024
16 tasks
@MFA-X-AI MFA-X-AI deleted the paul/copy-able-connections branch July 8, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants