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

Commit

Permalink
Use new exclude_params query when retrieving jobs (#653)
Browse files Browse the repository at this point in the history
* use exclude_params

* add reno

* add test

* Update releasenotes/notes/exclude-params-645aefa765d5bf07.yaml

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

---------

Co-authored-by: merav-aharoni <merav@il.ibm.com>
  • Loading branch information
kt474 and merav-aharoni authored Jun 8, 2023
1 parent f8b3433 commit d0a39b2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
4 changes: 2 additions & 2 deletions qiskit_ibm_provider/api/clients/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def program_run(
**hgp_dict
)

def job_get(self, job_id: str) -> Dict:
def job_get(self, job_id: str, exclude_params: bool = None) -> Dict:
"""Get job data.
Args:
Expand All @@ -156,7 +156,7 @@ def job_get(self, job_id: str) -> Dict:
Returns:
JSON response.
"""
response = self._api.program_job(job_id).get()
response = self._api.program_job(job_id).get(exclude_params=exclude_params)
logger.debug("Runtime job get response: %s", response)
return response

Expand Down
12 changes: 10 additions & 2 deletions qiskit_ibm_provider/api/rest/program_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,21 @@ def __init__(
"""
super().__init__(session, "{}/jobs/{}".format(url_prefix, job_id))

def get(self) -> Dict:
def get(self, exclude_params: bool = None) -> Dict:
"""Return program job information.
Args:
exclude_params: If ``True``, the params will not be included in the response.
Returns:
JSON response.
"""
return self.session.get(self.get_url("self")).json(cls=RuntimeDecoder)
payload = {}
if exclude_params:
payload["exclude_params"] = "true"
return self.session.get(self.get_url("self"), params=payload).json(
cls=RuntimeDecoder
)

def job_type(self) -> str:
"""Return job type:
Expand Down
4 changes: 3 additions & 1 deletion qiskit_ibm_provider/ibm_backend_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,9 @@ def retrieve_job(self, job_id: str) -> IBMJob:
legacy = True
job_info = self._default_hgp._api_client.job_get(job_id)
else:
job_info = self._provider._runtime_client.job_get(job_id)
job_info = self._provider._runtime_client.job_get(
job_id, exclude_params=True
)
if job_info.get("program", {}).get("id") not in [
"circuit-runner",
"qasm3-runner",
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/exclude-params-645aefa765d5bf07.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
When retrieving a job with :meth:`~qiskit_ibm_provider.IBMBackendService.retrieve_job` the ``params``
will no longer be returned from the API. They will instead be loaded lazily
when they are actually needed.
9 changes: 9 additions & 0 deletions test/integration/test_ibm_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,3 +515,12 @@ def test_job_header(self):
job = self.sim_backend.run(self.bell, header=custom_header)
self.assertEqual(custom_header["test"], job.header()["test"])
self.assertLessEqual(custom_header.items(), job.header().items())

def test_lazy_loading_params(self):
"""Test lazy loading job params."""
job = self.sim_backend.run(self.bell)
job.wait_for_final_state()

rjob = self.provider.backend.retrieve_job(job.job_id())
self.assertFalse(rjob._params)
self.assertTrue(rjob.circuits)

0 comments on commit d0a39b2

Please sign in to comment.