diff --git a/qiskit/providers/ibmq/job/ibmqjob.py b/qiskit/providers/ibmq/job/ibmqjob.py index 5e99c1d7c..e91c7216f 100644 --- a/qiskit/providers/ibmq/job/ibmqjob.py +++ b/qiskit/providers/ibmq/job/ibmqjob.py @@ -189,12 +189,21 @@ def qobj(self): def properties(self): """Return the backend properties for this job. + The properties might not be available if the job hasn't completed, + in which case None is returned. + Returns: - BackendProperties: the backend properties used for this job. + BackendProperties: the backend properties used for this job, or None if + properties are not available. """ self._wait_for_submission() properties = self._api.job_properties(job_id=self.job_id()) + + # Backend properties of a job might not be available if the job hasn't + # completed. This is to ensure the properties returned are up to date. + if not properties: + return None return BackendProperties.from_dict(properties) # pylint: disable=arguments-differ diff --git a/test/ibmq/test_ibmq_job.py b/test/ibmq/test_ibmq_job.py index 7c4dcb698..4f72de726 100644 --- a/test/ibmq/test_ibmq_job.py +++ b/test/ibmq/test_ibmq_job.py @@ -407,6 +407,17 @@ def test_error_message_qasm(self, qe_token, qe_url): message = job_sim.error_message() self.assertIn('Job resulted in the following QASM status(es): ', message) + @slow_test + @requires_qe_access + def test_running_job_properties(self, qe_token, qe_url): + """Test fetching properties of a running job.""" + IBMQ.enable_account(qe_token, qe_url) + backend = least_busy(IBMQ.backends(simulator=False)) + + qobj = assemble(transpile(self._qc, backend=backend), backend=backend) + job = backend.run(qobj) + _ = job.properties() + def _bell_circuit(): qr = QuantumRegister(2, 'q')