-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Make PrimitiveJob serializable #12963
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
35d0954
Make PrimtiveJob serializable
kt474 cb37866
fix style
kt474 e58cc67
fix init param order & ignore pylint
kt474 d99ff8e
Merge branch 'main' into update-primitve-job
kt474 34e283f
Merge branch 'main' into update-primitve-job
kt474 1fe465a
Merge branch 'main' into update-primitve-job
kt474 f997050
add reno
kt474 5b0b924
Merge branch 'main' into update-primitve-job
kt474 a6d1314
Remove default none
kt474 3459e6a
Merge branch 'update-primitve-job' of https://github.com/kt474/qiskit…
kt474 2c7e3ea
Merge branch 'main' into update-primitve-job
kt474 fac959a
Add comment in _prepare_dump()
kt474 7c4cc23
Update qiskit/primitives/primitive_job.py
kt474 37b594e
formatting
kt474 4468ff6
Update releasenotes/notes/serialize-primitive-job-aa97d0bf8221ea99.yaml
kt474 1b81f37
Merge branch 'main' into update-primitve-job
kt474 90b84fa
Merge branch 'main' into update-primitve-job
t-imamichi a4d92af
Merge branch 'main' into update-primitve-job
kt474 8f8aeae
implement __getstate__ and __setstate__
t-imamichi 574d437
Merge pull request #1 from t-imamichi/primitive-job-state
kt474 22b3579
Merge branch 'main' into update-primitve-job
kt474 327bdc7
lint
kt474 42e99c5
Update releasenotes/notes/serialize-primitive-job-aa97d0bf8221ea99.yaml
kt474 d9243b9
Update test/python/primitives/test_primitive_job.py
kt474 8e2bec4
Merge branch 'main' into update-primitve-job
kt474 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
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
5 changes: 5 additions & 0 deletions
5
releasenotes/notes/serialize-primitive-job-aa97d0bf8221ea99.yaml
This file contains hidden or 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,5 @@ | ||
--- | ||
features_primitives: | ||
- | | ||
To make :class:`.PrimitiveJob` serializable, :class:`.DataBin` has been | ||
updated to be pickleable. As a result, :class:`.PrimitiveResult` is now also pickleable. |
This file contains hidden or 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,51 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2025. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE.txt file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
"""Tests for PrimitiveJob.""" | ||
|
||
import pickle | ||
from test import QiskitTestCase | ||
|
||
import numpy as np | ||
from ddt import data, ddt | ||
|
||
from qiskit import QuantumCircuit | ||
from qiskit.primitives import PrimitiveJob, StatevectorSampler | ||
|
||
|
||
@ddt | ||
class TestPrimitiveJob(QiskitTestCase): | ||
"""Tests PrimitiveJob.""" | ||
|
||
@data(1, 2, 3) | ||
def test_serialize(self, size): | ||
"""Test serialize.""" | ||
n = 2 | ||
qc = QuantumCircuit(n) | ||
qc.h(range(n)) | ||
qc.measure_all() | ||
sampler = StatevectorSampler() | ||
job = sampler.run([qc] * size) | ||
obj = pickle.dumps(job) | ||
job2 = pickle.loads(obj) | ||
self.assertIsInstance(job2, PrimitiveJob) | ||
self.assertEqual(job.job_id(), job2.job_id()) | ||
self.assertEqual(job.status(), job2.status()) | ||
self.assertEqual(job.metadata, job2.metadata) | ||
result = job.result() | ||
result2 = job2.result() | ||
self.assertEqual(result.metadata, result2.metadata) | ||
self.assertEqual(len(result), len(result2)) | ||
for sampler_pub in result: | ||
self.assertEqual(sampler_pub.metadata, sampler_pub.metadata) | ||
self.assertEqual(sampler_pub.data.keys(), sampler_pub.data.keys()) | ||
np.testing.assert_allclose(sampler_pub.join_data().array, sampler_pub.join_data().array) |
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.
Uh oh!
There was an error while loading. Please reload this page.