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

Make PrimitiveJob serializable #12963

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

kt474
Copy link
Member

@kt474 kt474 commented Aug 15, 2024

Summary

In qiskit-ibm-runtime we want to add job methods to our QiskitRuntimeLocalService (Issue Qiskit/qiskit-ibm-runtime#1607). In order to save PrimitiveJob objects locally we need a way to serialize them. It's currently not serializable due to the use of ThreadPoolExecutor:

executor = ThreadPoolExecutor(max_workers=1) # pylint: disable=consider-using-with
self._future = executor.submit(self._function, *self._args, **self._kwargs)

Credit to @t-imamichi

Details and comments

Also fixes #12787

@kt474 kt474 requested review from a team as code owners August 15, 2024 17:23
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core
  • @ajavadia
  • @levbishop
  • @t-imamichi

@coveralls
Copy link

coveralls commented Aug 15, 2024

Pull Request Test Coverage Report for Build 12378436884

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 14 of 20 (70.0%) changed or added relevant lines in 1 file are covered.
  • 59 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.02%) to 88.951%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/primitives/primitive_job.py 14 20 70.0%
Files with Coverage Reduction New Missed Lines %
qiskit/circuit/library/quantum_volume.py 1 93.18%
qiskit/circuit/library/arithmetic/adders/adder.py 2 91.49%
crates/qasm2/src/lex.rs 4 91.98%
crates/qasm2/src/parse.rs 6 97.62%
crates/circuit/src/circuit_data.rs 7 95.43%
qiskit/transpiler/passes/synthesis/hls_plugins.py 39 87.02%
Totals Coverage Status
Change from base Build 12275601740: 0.02%
Covered Lines: 79430
Relevant Lines: 89296

💛 - Coveralls

@t-imamichi t-imamichi added mod: primitives Related to the Primitives module Changelog: New Feature Include in the "Added" section of the changelog labels Aug 16, 2024
@kt474 kt474 requested a review from t-imamichi December 5, 2024 16:14
@t-imamichi
Copy link
Member

It looks good overall. Could you add a reno to describe that both DataBin and PrimitiveJob become serializable?

t-imamichi
t-imamichi previously approved these changes Dec 11, 2024
Copy link
Member

@t-imamichi t-imamichi left a comment

Choose a reason for hiding this comment

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

LGTM. Could you ask someone else to review it too just in case?

@@ -46,19 +48,30 @@ def _submit(self):
self._future = executor.submit(self._function, *self._args, **self._kwargs)
executor.shutdown(wait=False)

def _prepare_dump(self):
Copy link
Member

Choose a reason for hiding this comment

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

I recall that this method is used when we serialize a job. But, this method is not used any other methods of this class. So, it might be good to add a comment just in case though it is a private method.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added in fac959a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog mod: primitives Related to the Primitives module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make DataBin pickle-able
5 participants