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

Fixes for speedier Python-Julia interaction #32

Merged
merged 20 commits into from
Aug 27, 2024
Merged

Conversation

kshyatt-aws
Copy link
Member

Issue #, if available: N/A

Description of changes:

  • Have all instances of the simV2 classes share a Julia process (cuts precompilation time and reduces memory pressure)
  • Add a benchmarking script to make sure we don't regress in the future
  • Handle Julia errors in a serializable way (for process)

Testing done:

  • tox passed locally
  • local benchmarks look much better

Merge Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.

General

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kshyatt-aws kshyatt-aws requested a review from a team as a code owner August 26, 2024 20:17
.github/workflows/benchmark.yml Outdated Show resolved Hide resolved
Comment on lines +80 to +86
def setup_pool():
global __JULIA_POOL__
__JULIA_POOL__ = Pool(processes=1)
__JULIA_POOL__.apply(setup_julia)
atexit.register(__JULIA_POOL__.join)
atexit.register(__JULIA_POOL__.close)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this thread safe? what if two Python threads call this at the same time? (i.e. should you wrap this in some kind of lock?)

src/braket/simulator_v2/julia_workers.py Outdated Show resolved Hide resolved
src/braket/simulator_v2/julia_workers.py Outdated Show resolved Hide resolved
.github/workflows/benchmark.yml Outdated Show resolved Hide resolved
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.9
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to benchmark across multiple python version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We certainly can, I just wanted to be sparing with the amount of resource use at first.


def setup_pool():
global __JULIA_POOL__
__JULIA_POOL__ = Pool(processes=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming this will be used by the batched executions, should this take in a param for setup_pool called processes which has a default of 1?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because Julia handles the batches itself behind the scenes. We only need one process to chat back and forth with Julia.

@kshyatt-aws
Copy link
Member Author

Moved benchmarking to a new PR: #35

@kshyatt-aws kshyatt-aws merged commit a6e9e80 into ksh/nobraket Aug 27, 2024
10 checks passed
@kshyatt-aws kshyatt-aws deleted the ksh/speed branch August 27, 2024 20:37
kshyatt-aws added a commit that referenced this pull request Aug 28, 2024
* change: nobraket branch

* change: Remove threading tests thanks to new pythoncall version

* fix: make tests compatible with xdist

* fix: Use proper BraketSimulator.jl version

* Use a `ProcessPoolExecutor` to talk to Julia (#30)

* fix: Use new BraketSimulator.jl version

* fix: Force a Julia registry update in CI to catch new versions

* update tests (#31)

* update tests

* add a test optimization

* refactor pyproject file to have test dependencies in their own file

* Update requirements-test.txt

* Update requirements-test.txt

---------

Co-authored-by: Coull <[email protected]>

* Fixes for speedier Python-Julia interaction (#32)

* change: Use multiprocessing Pool rather than ProcessPoolExecutor

* fix: No sigterm screaming

* fix: Force close and join at exit

* fix: Faster

* fix: handle julia error in serializable way

* change: Add benchmark workflow to CI

* change: Point to latest unblocking branch

* fix: linting

* fix: Don't turn off juliapkg in tox

* Update src/braket/simulator_v2/julia_workers.py

Co-authored-by: Ryan Shaffer <[email protected]>

* Update src/braket/simulator_v2/julia_workers.py

Co-authored-by: Ryan Shaffer <[email protected]>

* fix: one-line pip in benchmark

* fix: typo

* fix: Use benchmark-json option correctly

* change: Add initial output.json

* fix: Actually include benchmark script

* fix: Don't deploy benchmark results to gh-pages

* fix: restore GH token

* fix: Remove benchmarks for now

* change: Point to new BraketSimulator 0.0.4

---------

Co-authored-by: Ryan Shaffer <[email protected]>

* fix: Don't turn off pyjuliapkg to make sure dpes do install

* fix: Don't return the julia Main module to unlock jupyter

* fix: Return to not using JuliaError type in case Julia isn't loaded

---------

Co-authored-by: Coull <[email protected]>
Co-authored-by: Abe Coull <[email protected]>
Co-authored-by: Ryan Shaffer <[email protected]>
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.

3 participants