Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

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

* add reno & test

* update field name

* Update qiskit_ibm_provider/job/ibm_circuit_job.py

Co-authored-by: merav-aharoni <merav@il.ibm.com>

* update docstring and reno

---------

Co-authored-by: merav-aharoni <merav@il.ibm.com>
  • Loading branch information
kt474 and merav-aharoni committed Aug 7, 2023
1 parent 8a2b1c0 commit 954c5a2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
18 changes: 18 additions & 0 deletions qiskit_ibm_provider/job/ibm_circuit_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def __init__(
self._status = api_status_to_job_status(status)
self._client_version = self._extract_client_version(client_info)
self._set_result(result)
self._usage_estimation: Dict[str, Any] = {}

# Properties used for caching.
self._cancelled = False
Expand Down Expand Up @@ -513,6 +514,20 @@ def client_version(self) -> Dict[str, str]:
self.refresh()
return self._client_version

@property
def usage_estimation(self) -> Dict[str, Any]:
"""Return usage estimation information 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:
self.refresh()

return self._usage_estimation

def refresh(self) -> None:
"""Obtain the latest job information from the server.
Expand All @@ -536,6 +551,9 @@ def refresh(self) -> None:
raise IBMJobApiError(
"Unexpected return value received " "from the server: {}".format(err)
) from err
self._usage_estimation = {
"quantum_seconds": api_response.pop("estimated_running_time_seconds", None),
}
self._time_per_step = api_metadata.get("timestamps", None)
self._tags = api_response.pop("tags", [])
self._status = api_status_to_job_status(self._api_status)
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/job-cost-estimation-9d1b7bd37dd102c7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
Added a new property, :meth:`~qiskit_ibm_provider.job.IBMCircuitJob.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.
5 changes: 5 additions & 0 deletions test/integration/test_ibm_job_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ def test_invalid_job_tags(self):
job_tags=[1, 2, 3],
)

def test_cost_estimation(self):
"""Test cost estimation is returned correctly."""
self.assertTrue(self.sim_job.usage_estimation)
self.assertIn("quantum_seconds", self.sim_job.usage_estimation)

@skip("TODO refactor fake client")
def test_missing_required_fields(self):
"""Test response data is missing required fields."""
Expand Down

0 comments on commit 954c5a2

Please sign in to comment.