Skip to content

Commit

Permalink
Expose job cost estimation values (#976)
Browse files Browse the repository at this point in the history
* Expose job cost estimation values

* address comments

* fix black

* Update qiskit_ibm_runtime/runtime_job.py

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>

* fix black, update reno

---------

Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>
  • Loading branch information
kt474 and jyu00 authored Aug 7, 2023
1 parent 2e8911a commit e480693
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions qiskit_ibm_runtime/runtime_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def __init__(
self._service = service
self._session_id = session_id
self._tags = tags
self._usage_estimation: Dict[str, Any] = {}

decoder = result_decoder or DEFAULT_DECODERS.get(program_id, None) or ResultDecoder
if isinstance(decoder, Sequence):
Expand Down Expand Up @@ -655,3 +656,20 @@ def tags(self) -> List:
Tags assigned to the job that can be used for filtering.
"""
return self._tags

@property
def usage_estimation(self) -> Dict[str, Any]:
"""Return the usage estimation infromation for this job.
Returns:
``quantum_seconds`` which is the estimated quantum time
of the job in seconds. Quantum time represents the time that
the QPU complex is occupied exclusively by the job.
"""
if not self._usage_estimation:
response = self._api_client.job_get(job_id=self.job_id())
self._usage_estimation = {
"quantum_seconds": response.pop("estimated_running_time_seconds", None),
}

return self._usage_estimation
6 changes: 6 additions & 0 deletions releasenotes/notes/job-cost-estimation-d0ba83dbc95c3f67.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
Added a new property, :meth:`~qiskit_ibm_runtime.RuntimeJob.usage_estimation`
that returns the estimated running time, ``quantum_seconds``. Quantum time
represents the time that the QPU complex is occupied exclusively by the job.
8 changes: 8 additions & 0 deletions test/integration/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ def test_job_metrics(self, service):
self.assertIn("timestamps", metrics)
self.assertIn("qiskit_version", metrics)

@run_integration_test
def test_usage_estimation(self, service):
"""Test job usage estimation"""
job = self._run_program(service)
job.wait_for_final_state()
self.assertTrue(job.usage_estimation)
self.assertIn("quantum_seconds", job.usage_estimation)

@run_integration_test
def test_updating_job_tags(self, service):
"""Test job metrics."""
Expand Down

0 comments on commit e480693

Please sign in to comment.