Skip to content

Commit

Permalink
Merge pull request #781 from delapuente/issue-780-master-is-failing
Browse files Browse the repository at this point in the history
Tests revealed a couple of bugs in the codebase.
  • Loading branch information
atilag committed Aug 16, 2018
2 parents 09af5d7 + 551cbf0 commit aed3368
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
12 changes: 9 additions & 3 deletions qiskit/backends/ibmq/ibmqbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""
import logging

from IBMQuantumExperience import ApiError
from qiskit import QISKitError
from qiskit._util import _camel_case_to_snake_case, AvailableToOperationalDict
from qiskit.backends import BaseBackend
Expand Down Expand Up @@ -237,9 +238,14 @@ def retrieve_job(self, job_id):
Raises:
IBMQBackendError: if retrieval failed
"""
job_info = self._api.get_job(job_id)
if 'error' in job_info:
raise IBMQBackendError('failed to get job id "{}"'.format(job_id))
try:
job_info = self._api.get_job(job_id)
if 'error' in job_info:
raise IBMQBackendError('Failed to get job "{}": {}'
.format(job_id, job_info['error']))
except ApiError as ex:
raise IBMQBackendError('Failed to get job "{}":{}'
.format(job_id, str(ex)))
is_device = not bool(self._configuration.get('simulator'))
job = IBMQJob(self._api, is_device,
job_id=job_info.get('id'),
Expand Down
6 changes: 0 additions & 6 deletions qiskit/backends/ibmq/ibmqjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,6 @@ def result(self, timeout=None, wait=5):
self._wait_for_submission()
try:
this_result = self._wait_for_job(timeout=timeout, wait=wait)
except TimeoutError as err:
# A timeout error retrieving the results does not imply the job
# is failing. The job can be still running. This is why we are not
# throwing an exception here.
return Result({'id': self._id, 'status': 'ERROR',
'result': str(err)})
except ApiError as api_err:
raise JobError(str(api_err))

Expand Down
3 changes: 0 additions & 3 deletions test/python/test_ibmqjob_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,9 @@ def test_never_complete_result_with_timeout(self):
job = self.run_with_api(NonQueuedAPI())

self.wait_for_initialization(job)
# We never make the API status to progress so it is stuck on RUNNING
with self.assertRaises(JobTimeoutError):
job.result(timeout=0.2)

self.assertEqual(job.status(), JobStatus.RUNNING)

def test_cancel_while_initializing_fails(self):
job = self.run_with_api(CancellableAPI())
can_cancel = job.cancel()
Expand Down
7 changes: 4 additions & 3 deletions test/python/test_quantumprogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from qiskit import (ClassicalRegister, QISKitError, QuantumCircuit,
QuantumRegister, QuantumProgram, Result)
from qiskit.backends import JobTimeoutError
from qiskit.qobj import Qobj
from qiskit.tools import file_io
from .common import requires_qe_access, QiskitTestCase, Path
Expand Down Expand Up @@ -1138,9 +1139,9 @@ def test_simulator_online_size(self, qe_token, qe_url):
qc.measure(qr, cr)
shots = 1
q_program.set_api(qe_token, qe_url)
result = q_program.execute(['qc'], backend=backend_name, shots=shots,
max_credits=3, seed=73846087)
self.assertRaises(QISKitError, result.get_data, 'qc')
with self.assertRaises(JobTimeoutError):
q_program.execute(['qc'], backend=backend_name, shots=shots,
max_credits=3, seed=73846087)

@requires_qe_access
def test_execute_several_circuits_simulator_online(self, qe_token, qe_url):
Expand Down

0 comments on commit aed3368

Please sign in to comment.