-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Changes from 18 commits
35d0954
cb37866
e58cc67
d99ff8e
34e283f
1fe465a
f997050
5b0b924
a6d1314
3459e6a
2c7e3ea
fac959a
7c4cc23
37b594e
4468ff6
1b81f37
90b84fa
a4d92af
8f8aeae
574d437
22b3579
327bdc7
42e99c5
d9243b9
8e2bec4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
@@ -46,19 +48,31 @@ def _submit(self): | |
| self._future = executor.submit(self._function, *self._args, **self._kwargs) | ||
| executor.shutdown(wait=False) | ||
|
|
||
| def _prepare_dump(self): | ||
t-imamichi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """This method allows PrimitiveJob to be serialized""" | ||
| _ = 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: | ||
|
|
||
| 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 | ||
kt474 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| updated to be pickleable. As a result, :class:`.PrimitiveResult` is now also pickleable. | ||
Uh oh!
There was an error while loading. Please reload this page.