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

feat: Instruction classes and execution results now support the pickle module #1795

Merged
merged 10 commits into from
Jul 30, 2024

Conversation

MarquessV
Copy link
Contributor

@MarquessV MarquessV commented Jul 29, 2024

Description

This closes #1719 (along w/ an additional request to support QPUExecuteResponse), and #1791 (but for all instruction classes).

Waiting on some upstream changes to land, once they do, this PR should pass CI.

Checklist

  • The PR targets the master branch
  • The above description motivates these changes.
  • The change is atomic and can be described by a single commit (your PR will be squashed on merge).
  • All changes to code are covered via unit tests.
  • Parameters and return values have type hints with PEP 484 syntax.
  • Functions and classes have useful Sphinx-style docstrings.
  • (New Feature) The docs have been updated accordingly.

Copy link

github-actions bot commented Jul 29, 2024

🐰Bencher

ReportTue, July 30, 2024 at 17:51:13 UTC
Projectpyquil
Branch1719-more-pickleable-types
Testbedci-runner-linux
Click to view all benchmark results
BenchmarkLatencyLatency Results
nanoseconds (ns) | (Δ%)
Latency Upper Boundary
nanoseconds (ns) | (%)
test/benchmarks/test_program.py::test_copy_everything_except_instructions✅ (view plot)10,348,544,208.00 (+0.54%)10,536,846,752.01 (98.21%)
test/benchmarks/test_program.py::test_instructions✅ (view plot)3,896,421,725.20 (-0.73%)4,051,015,766.66 (96.18%)
test/benchmarks/test_program.py::test_iteration✅ (view plot)3,926,822,893.80 (-0.25%)4,063,221,555.28 (96.64%)

Bencher - Continuous Benchmarking
View Public Perf Page
Docs | Repo | Chat | Help

@MarquessV MarquessV marked this pull request as ready for review July 29, 2024 18:43
@MarquessV MarquessV requested a review from a team as a code owner July 29, 2024 18:44
Comment on lines 228 to 233
# result_data=ResultData.from_qvm(
# QVMResultData.from_memory_map({
# "int": RegisterData.from_i8([[1, 2, 3], [4, 5, 6]]),
# "float": RegisterData.from_f64([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]])
# })
# )
Copy link
Contributor

Choose a reason for hiding this comment

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

Stale?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, removed.

Comment on lines 242 to 250
def test_pickle_qpu_execute_response(mock_encrypted_program):
response = QPUExecuteResponse(
job_id="some-job-id",
_executable=mock_encrypted_program,
execution_options=ExecutionOptions.default()
)
pickled_response = pickle.dumps(response)
unpickled_response = pickle.loads(pickled_response)
assert unpickled_response == response
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we could have a function that specifically takes Any and does this pickle roundtripping. Not sure if we'll ever add more logic to this, but having it in one place would make that easier.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorta like in test/unit/test_quilbase.py

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that idea, I parametrized the response types over a single test implementation.

Copy link
Contributor

@jselig-rigetti jselig-rigetti left a comment

Choose a reason for hiding this comment

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

This is great, and will be appreciated by many!

Do you know if pickling allow objects to be serialized/deserialized between Python runtimes on separate architectures? For example, if someone were to pickle execution results on ppc64le using pyquil-grpc-web would they then be able to unpickle(?) from arm64 pyquil?

Not a blocking question, just curious.

pyproject.toml Outdated Show resolved Hide resolved
Co-authored-by: jselig-rigetti <[email protected]>
@MarquessV
Copy link
Contributor Author

Do you know if pickling allow objects to be serialized/deserialized between Python runtimes on separate architectures? For example, if someone were to pickle execution results on ppc64le using pyquil-grpc-web would they then be able to unpickle(?) from arm64 pyquil?

While that isn't something I have first-hand experience with, the pickling format should be platform-agnostic. There are versioned protocols, but none of them mention platform specificity as an issue.

Copy link

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
7203 6317 88% 87% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
pyquil/api/init.py 100% 🟢
pyquil/control_flow_graph.py 100% 🟢
pyquil/quilbase.py 94% 🟢
TOTAL 98% 🟢

updated for commit: d9c132e by action🐍

@MarquessV MarquessV merged commit ac93417 into master Jul 30, 2024
22 checks passed
@MarquessV MarquessV deleted the 1719-more-pickleable-types branch July 30, 2024 19:48
numpy = "^1.25"
scipy = "^1.11"
rpcq = "^3.11.0"
networkx = ">=2.5"
qcs-sdk-python = "0.19.0"
qcs-sdk-python = "0.19.2"
quil = ">=0.11.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prior to qcs-sdk-python 0.19.2, quil was required to be a specific version. That was meant to ensure compatibility between downstream users of both packages, but in practice that has been over-restrictive. This allows quil to be updated separately from qcs-sdk-python, at least between breaking changes.

pyproject.toml Outdated
@@ -19,12 +19,13 @@ packages = [{ include = "pyquil" }]
exclude = ["pyquil/conftest.py"]

[tool.poetry.dependencies]
python = "^3.9,<=3.14"
python = "^3.9,<=4.0"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will close #1793.

pyproject.toml Outdated Show resolved Hide resolved
Comment on lines 228 to 233
# result_data=ResultData.from_qvm(
# QVMResultData.from_memory_map({
# "int": RegisterData.from_i8([[1, 2, 3], [4, 5, 6]]),
# "float": RegisterData.from_f64([[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]])
# })
# )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, removed.

Comment on lines 242 to 250
def test_pickle_qpu_execute_response(mock_encrypted_program):
response = QPUExecuteResponse(
job_id="some-job-id",
_executable=mock_encrypted_program,
execution_options=ExecutionOptions.default()
)
pickled_response = pickle.dumps(response)
unpickled_response = pickle.loads(pickled_response)
assert unpickled_response == response
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like that idea, I parametrized the response types over a single test implementation.

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.

Make QAMExecutionResult serializable
3 participants