diff --git a/qiskit_ibm_provider/job/ibm_circuit_job.py b/qiskit_ibm_provider/job/ibm_circuit_job.py index 6c445e630..225516199 100644 --- a/qiskit_ibm_provider/job/ibm_circuit_job.py +++ b/qiskit_ibm_provider/job/ibm_circuit_job.py @@ -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 @@ -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. @@ -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) diff --git a/releasenotes/notes/job-cost-estimation-9d1b7bd37dd102c7.yaml b/releasenotes/notes/job-cost-estimation-9d1b7bd37dd102c7.yaml new file mode 100644 index 000000000..b4551ee5f --- /dev/null +++ b/releasenotes/notes/job-cost-estimation-9d1b7bd37dd102c7.yaml @@ -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. diff --git a/test/integration/test_ibm_job_attributes.py b/test/integration/test_ibm_job_attributes.py index f333471db..402524115 100644 --- a/test/integration/test_ibm_job_attributes.py +++ b/test/integration/test_ibm_job_attributes.py @@ -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."""