-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
0d4d4c4
change: Use multiprocessing Pool rather than ProcessPoolExecutor
kshyatt-aws 80c67f7
fix: No sigterm screaming
kshyatt-aws 05870ba
fix: Force close and join at exit
kshyatt-aws 58ccd81
fix: Faster
kshyatt-aws 8fd3340
fix: handle julia error in serializable way
kshyatt-aws 5f0a2d1
change: Add benchmark workflow to CI
kshyatt-aws 88a55d4
change: Point to latest unblocking branch
kshyatt-aws 7140d2d
fix: linting
kshyatt-aws 509479e
fix: Don't turn off juliapkg in tox
kshyatt-aws f550cab
Update src/braket/simulator_v2/julia_workers.py
kshyatt-aws 3e244c1
Update src/braket/simulator_v2/julia_workers.py
kshyatt-aws 3c6735b
fix: one-line pip in benchmark
kshyatt-aws 716bd9c
fix: typo
kshyatt-aws b62a8f9
fix: Use benchmark-json option correctly
kshyatt-aws 967dea4
change: Add initial output.json
kshyatt-aws 228932f
fix: Actually include benchmark script
kshyatt-aws 2280398
fix: Don't deploy benchmark results to gh-pages
kshyatt-aws e18ad32
fix: restore GH token
kshyatt-aws b10144a
fix: Remove benchmarks for now
kshyatt-aws 0041a2b
change: Point to new BraketSimulator 0.0.4
kshyatt-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Force close and join at exit
- Loading branch information
commit 05870ba88ba870bb8e26f113d8288149696024d5
There are no files selected for viewing
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from braket.ir.openqasm import Program as OpenQASMProgram | ||
from collections.abc import Sequence | ||
import json | ||
import sys | ||
from typing import List, Optional, Union | ||
|
||
def _handle_julia_error(error): | ||
import sys | ||
if isinstance(error, sys.modules["juliacall"].JuliaError): | ||
python_exception = getattr(error.exception, "alternate_type", None) | ||
if python_exception is None: | ||
py_error = error | ||
else: | ||
class_val = getattr(sys.modules["builtins"], str(python_exception)) | ||
py_error = class_val(str(error.exception.message)) | ||
raise py_error | ||
else: | ||
raise error | ||
return | ||
|
||
|
||
def translate_and_run( | ||
device_id: str, openqasm_ir: OpenQASMProgram, shots: int = 0 | ||
) -> str: | ||
jl = sys.modules["juliacall"].Main | ||
jl_shots = shots | ||
jl_inputs = json.dumps(openqasm_ir.inputs) if openqasm_ir.inputs else '{}' | ||
py_result = "" | ||
try: | ||
result = jl.BraketSimulator.simulate( | ||
device_id, | ||
openqasm_ir.source, | ||
jl_inputs, | ||
jl_shots, | ||
) | ||
py_result = str(result) | ||
except Exception as e: | ||
_handle_julia_error(e) | ||
|
||
return py_result | ||
|
||
|
||
def translate_and_run_multiple( | ||
device_id: str, | ||
programs: Sequence[OpenQASMProgram], | ||
shots: Optional[int] = 0, | ||
inputs: Optional[Union[dict, Sequence[dict]]] = {}, | ||
) -> List[str]: | ||
jl = sys.modules["juliacall"].Main | ||
irs = [program.source for program in programs] | ||
is_single_input = isinstance(inputs, dict) or len(inputs) == 1 | ||
py_inputs = {} | ||
if (is_single_input and isinstance(inputs, dict)) or not is_single_input: | ||
py_inputs = [inputs.copy() for _ in range(len(programs))] | ||
elif is_single_input and not isinstance(inputs, dict): | ||
py_inputs = [inputs[0].copy() for _ in range(len(programs))] | ||
else: | ||
py_inputs = inputs | ||
kshyatt-aws marked this conversation as resolved.
Show resolved
Hide resolved
|
||
full_inputs = [] | ||
for p_ix, program in enumerate(programs): | ||
if program.inputs: | ||
full_inputs.append(program.inputs | py_inputs[p_ix]) | ||
else: | ||
full_inputs.append(py_inputs[p_ix]) | ||
|
||
jl_inputs = json.dumps(full_inputs) | ||
|
||
try: | ||
results = jl.BraketSimulator.simulate( | ||
device_id, | ||
irs, | ||
jl_inputs, | ||
shots, | ||
) | ||
py_results = [str(result) for result in results] | ||
except Exception as e: | ||
_handle_julia_error(e) | ||
return py_results |
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.
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.
Assuming this will be used by the batched executions, should this take in a param for
setup_pool
calledprocesses
which has a default of1
?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.
No, because Julia handles the batches itself behind the scenes. We only need one process to chat back and forth with Julia.