Skip to content

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 25 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
35d0954
Make PrimtiveJob serializable
kt474 Aug 15, 2024
cb37866
fix style
kt474 Aug 15, 2024
e58cc67
fix init param order & ignore pylint
kt474 Aug 16, 2024
d99ff8e
Merge branch 'main' into update-primitve-job
kt474 Aug 16, 2024
34e283f
Merge branch 'main' into update-primitve-job
kt474 Dec 3, 2024
1fe465a
Merge branch 'main' into update-primitve-job
kt474 Dec 10, 2024
f997050
add reno
kt474 Dec 10, 2024
5b0b924
Merge branch 'main' into update-primitve-job
kt474 Dec 10, 2024
a6d1314
Remove default none
kt474 Dec 12, 2024
3459e6a
Merge branch 'update-primitve-job' of https://github.com/kt474/qiskit…
kt474 Dec 12, 2024
2c7e3ea
Merge branch 'main' into update-primitve-job
kt474 Dec 12, 2024
fac959a
Add comment in _prepare_dump()
kt474 Dec 16, 2024
7c4cc23
Update qiskit/primitives/primitive_job.py
kt474 Dec 17, 2024
37b594e
formatting
kt474 Dec 17, 2024
4468ff6
Update releasenotes/notes/serialize-primitive-job-aa97d0bf8221ea99.yaml
kt474 Dec 18, 2024
1b81f37
Merge branch 'main' into update-primitve-job
kt474 Jan 22, 2025
90b84fa
Merge branch 'main' into update-primitve-job
t-imamichi Mar 24, 2025
a4d92af
Merge branch 'main' into update-primitve-job
kt474 Mar 26, 2025
8f8aeae
implement __getstate__ and __setstate__
t-imamichi Mar 27, 2025
574d437
Merge pull request #1 from t-imamichi/primitive-job-state
kt474 Mar 27, 2025
22b3579
Merge branch 'main' into update-primitve-job
kt474 Mar 27, 2025
327bdc7
lint
kt474 Mar 27, 2025
42e99c5
Update releasenotes/notes/serialize-primitive-job-aa97d0bf8221ea99.yaml
kt474 Mar 28, 2025
d9243b9
Update test/python/primitives/test_primitive_job.py
kt474 Mar 28, 2025
8e2bec4
Merge branch 'main' into update-primitve-job
kt474 Mar 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions qiskit/primitives/containers/data_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ def __init__(self, *, shape: ShapeInput = (), **data):
def __len__(self):
return len(self._data)

def __setattr__(self, *_):
raise NotImplementedError

def __repr__(self):
vals = [f"{name}={_value_repr(val)}" for name, val in self.items()]
if self.ndim:
Expand Down
33 changes: 23 additions & 10 deletions qiskit/primitives/primitive_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def __init__(self, function, *args, **kwargs):
super().__init__(str(uuid.uuid4()))
self._future = None
self._function = function
self._result = None
self._status = None
self._args = args
self._kwargs = kwargs

Expand All @@ -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):
_ = self.result()
_ = self.status()
self._future = None

def result(self) -> ResultT:
self._check_submitted()
return self._future.result()
if self._result is None:
self._check_submitted()
self._result = self._future.result()
return self._result

def status(self) -> JobStatus:
self._check_submitted()
if self._future.running():
return JobStatus.RUNNING
elif self._future.cancelled():
return JobStatus.CANCELLED
elif self._future.done() and self._future.exception() is None:
return JobStatus.DONE
return JobStatus.ERROR
if self._status is None:
self._check_submitted()
if self._future.running():
# we should not store status running because it is not completed
return JobStatus.RUNNING
elif self._future.cancelled():
self._status = JobStatus.CANCELLED
elif self._future.done() and self._future.exception() is None:
self._status = JobStatus.DONE
else:
self._status = JobStatus.ERROR
return self._status

def _check_submitted(self):
if self._future is None:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
features_primitives:
- |
To make :class:`.PrimitiveJob` serializable, `qiskit.primitives.containers.DataBin` has been
updated to be pickleable. As a result, :class:`.PrimitiveResult` is now also pickleable.
Loading