Skip to content
This repository was archived by the owner on Jul 28, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Changed
Qiskit Terra package.
- The exception hierarchy has been revised: the package base exception is
``IBMQError``, and they have been grouped in ``.exception`` modules. (#5)
- Ensured that retrieved jobs come from their appropriate backend (#23)



Expand Down
10 changes: 9 additions & 1 deletion qiskit/providers/ibmq/ibmqbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ def retrieve_job(self, job_id):
IBMQBackendError: if retrieval failed
"""
try:
job_info = self._api.get_status_job(job_id)
job_info = self._api.get_job(job_id)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a self-reminder that, in this PR, the endpoint called was changed as get_status_job does not support field inclusion yet, so the backend name is not provided. This is meant to be temporary - hopefully it will be implemented in the API soon, and then we can go back to using get_status_job, which is more efficient.

if job_info['backend']['name'] != self.name():
warnings.warn('Job "{}" belongs to another backend than the one queried. '
'The query was made on backend "{}", '
'but the job actually belongs to backend "{}".'
.format(job_id, job_info['backend']['name'], self.name()))
raise IBMQBackendError('Failed to get job "{}": '
'job does not belong to backend "{}".'
.format(job_id, job_info['backend']['name']))
if 'error' in job_info:
raise IBMQBackendError('Failed to get job "{}": {}'
.format(job_id, job_info['error']))
Expand Down
25 changes: 25 additions & 0 deletions test/ibmq/test_ibmq_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,31 @@ def test_retrieve_job(self, qe_token, qe_url):
else:
self.assertEqual(job.qobj(), None)

@slow_test
@requires_qe_access
def test_retrieve_job_uses_appropriate_backend(self, qe_token, qe_url):
"""Test that retrieved jobs come from their appropriate backend."""
IBMQ.enable_account(qe_token, qe_url)
simulator_backend = IBMQ.get_backend('ibmq_qasm_simulator')
backends = IBMQ.backends(simulator=False)
real_backend = least_busy(backends)

qobj_sim = compile(self._qc, simulator_backend)
job_sim = simulator_backend.run(qobj_sim)

qobj_real = compile(self._qc, real_backend)
job_real = real_backend.run(qobj_real)

# test a retrieved job's backend is the same as the queried backend
self.assertEqual(simulator_backend.retrieve_job(job_sim.job_id()).backend().name(),
simulator_backend.name())
self.assertEqual(real_backend.retrieve_job(job_real.job_id()).backend().name(),
real_backend.name())

# test retrieve requests for jobs that exist on other backends throw errors
self.assertRaises(IBMQBackendError, simulator_backend.retrieve_job, job_real.job_id())
self.assertRaises(IBMQBackendError, real_backend.retrieve_job, job_sim.job_id())

@requires_qe_access
def test_retrieve_job_error(self, qe_token, qe_url):
"""Test retrieving an invalid job."""
Expand Down