-
Notifications
You must be signed in to change notification settings - Fork 159
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
[WIP] Local mode job class #2057
Draft
kt474
wants to merge
5
commits into
Qiskit:main
Choose a base branch
from
kt474:local-job-class
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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,88 @@ | ||
# This code is part of Qiskit. | ||
# | ||
# (C) Copyright IBM 2024. | ||
# | ||
# 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. | ||
|
||
"""Qiskit runtime local mode job class.""" | ||
|
||
from typing import Any, Dict, Literal | ||
from datetime import datetime | ||
|
||
from qiskit.primitives.primitive_job import PrimitiveJob | ||
from qiskit_ibm_runtime.models import BackendProperties | ||
from .fake_backend import FakeBackendV2 # pylint: disable=cyclic-import | ||
|
||
|
||
class LocalRuntimeJob(PrimitiveJob): | ||
"""Job class for qiskit-ibm-runtime's local mode.""" | ||
|
||
def __init__( # type: ignore[no-untyped-def] | ||
self, | ||
future, | ||
backend: FakeBackendV2, | ||
primitive: Literal["sampler", "estimator"], | ||
*args, | ||
**kwargs, | ||
) -> None: | ||
"""LocalRuntimeJob constructor. | ||
|
||
Args: | ||
future: Thread executor the job is run on. | ||
backend: The backend to run the primitive on. | ||
""" | ||
super().__init__(*args, **kwargs) | ||
self._future = future | ||
self._backend = backend | ||
self._primitive = primitive | ||
self._created = datetime.now() | ||
self._running = datetime.now() | ||
self._finished = datetime.now() | ||
|
||
def metrics(self) -> Dict[str, Any]: | ||
"""Return job metrics. | ||
|
||
Returns: | ||
A dictionary with job metrics including but not limited to the following: | ||
|
||
* ``timestamps``: Timestamps of when the job was created, started running, and finished. | ||
* ``usage``: Details regarding job usage, the measurement of the amount of | ||
time the QPU is locked for your workload. | ||
""" | ||
return { | ||
"bss": {"seconds": 0}, | ||
"usage": {"quantum_seconds": 0, "seconds": 0}, | ||
"timestamps": { | ||
"created": self._created, | ||
"running": self._running, | ||
"finished": self._finished, | ||
}, | ||
} | ||
|
||
def backend(self) -> FakeBackendV2: | ||
"""Return the backend where this job was executed.""" | ||
return self._backend | ||
|
||
def useage(self) -> float: | ||
"""Return job usage in seconds.""" | ||
return 0 | ||
|
||
def properties(self) -> BackendProperties: | ||
"""Return the backend properties for this job""" | ||
return self._backend.properties() | ||
|
||
@property | ||
def creation_date(self) -> datetime: | ||
"""Job creation date in local time.""" | ||
return self._created | ||
|
||
@property | ||
def primitive_id(self) -> str: | ||
"""Primitive name.""" | ||
return self._primitive |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.