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

Add job usage method #1827

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Changes from 1 commit
Commits
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
14 changes: 13 additions & 1 deletion qiskit_ibm_runtime/base_runtime_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,23 @@ def cancel_result_streaming(self) -> None:
return
self._ws_client.disconnect(WebsocketClientCloseCode.CANCEL)

def usage(self) -> Dict[str, Any]:
"""Return job usage in seconds."""
try:
metrics = self._api_client.job_metadata(self.job_id())
return metrics.get("usage")
kt474 marked this conversation as resolved.
Show resolved Hide resolved
except RequestsApiError as err:
raise IBMRuntimeError(f"Failed to get job metadata: {err}") from None

def metrics(self) -> Dict[str, Any]:
"""Return job metrics.

Returns:
Job metrics, which includes timestamp information.
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``: Job usage metrics

kt474 marked this conversation as resolved.
Show resolved Hide resolved

Raises:
IBMRuntimeError: If a network error occurred.
Expand Down