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

Commit

Permalink
Merge branch 'main' into dr-global-phase-param
Browse files Browse the repository at this point in the history
  • Loading branch information
kt474 committed Aug 8, 2023
2 parents 1c0c940 + 954c5a2 commit 950726c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
7 changes: 3 additions & 4 deletions qiskit_ibm_provider/ibm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ def run(
shots = int(shots)
if not self.configuration().simulator:
circuits = self._deprecate_id_instruction(circuits)
options = {"backend": self.name}

run_config_dict = self._get_run_config(
program_id=program_id,
Expand Down Expand Up @@ -515,7 +514,7 @@ def run(
return self._runtime_run(
program_id=program_id,
inputs=run_config_dict,
options=options,
backend_name=self.name,
job_tags=job_tags,
image=image,
)
Expand All @@ -524,7 +523,7 @@ def _runtime_run(
self,
program_id: str,
inputs: Dict,
options: Dict,
backend_name: str,
job_tags: Optional[List[str]] = None,
image: Optional[str] = None,
) -> IBMCircuitJob:
Expand All @@ -533,7 +532,7 @@ def _runtime_run(
try:
response = self.provider._runtime_client.program_run(
program_id=program_id,
backend_name=options["backend"],
backend_name=backend_name,
params=inputs,
hgp=hgp_name,
job_tags=job_tags,
Expand Down
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 950726c

Please sign in to comment.