From 5834abb6089a8be60b3c820c768093b3ade4a6fa Mon Sep 17 00:00:00 2001 From: Jessie Yu Date: Tue, 4 Jun 2019 15:11:50 -0400 Subject: [PATCH 1/3] check for empty properties --- qiskit/providers/ibmq/job/ibmqjob.py | 8 +++++++- test/ibmq/test_ibmq_job.py | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/qiskit/providers/ibmq/job/ibmqjob.py b/qiskit/providers/ibmq/job/ibmqjob.py index a4ad50350..9a7ab821a 100644 --- a/qiskit/providers/ibmq/job/ibmqjob.py +++ b/qiskit/providers/ibmq/job/ibmqjob.py @@ -190,11 +190,17 @@ def properties(self): """Return the backend properties for this job. 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 2c6f70db3..b5abc59da 100644 --- a/test/ibmq/test_ibmq_job.py +++ b/test/ibmq/test_ibmq_job.py @@ -407,6 +407,16 @@ 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) + @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') From 2312e1204bdf455b6e7c03685ba997880a0d38dc Mon Sep 17 00:00:00 2001 From: Jessie Yu Date: Thu, 6 Jun 2019 09:47:11 -0400 Subject: [PATCH 2/3] update docstring --- qiskit/providers/ibmq/job/ibmqjob.py | 3 ++- test/ibmq/test_ibmq_job.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/qiskit/providers/ibmq/job/ibmqjob.py b/qiskit/providers/ibmq/job/ibmqjob.py index 9a7ab821a..282763f8a 100644 --- a/qiskit/providers/ibmq/job/ibmqjob.py +++ b/qiskit/providers/ibmq/job/ibmqjob.py @@ -187,7 +187,8 @@ def qobj(self): return Qobj.from_dict(self._qobj_payload) def properties(self): - """Return the backend properties for this job. + """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, or None if diff --git a/test/ibmq/test_ibmq_job.py b/test/ibmq/test_ibmq_job.py index b5abc59da..9d23f4f09 100644 --- a/test/ibmq/test_ibmq_job.py +++ b/test/ibmq/test_ibmq_job.py @@ -407,6 +407,7 @@ 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.""" From 75944ffda0eacd79b9cea3e8ffb5b55a18111c00 Mon Sep 17 00:00:00 2001 From: Jessie Yu Date: Thu, 6 Jun 2019 10:11:41 -0400 Subject: [PATCH 3/3] fix docstring --- qiskit/providers/ibmq/job/ibmqjob.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qiskit/providers/ibmq/job/ibmqjob.py b/qiskit/providers/ibmq/job/ibmqjob.py index 282763f8a..14e30449f 100644 --- a/qiskit/providers/ibmq/job/ibmqjob.py +++ b/qiskit/providers/ibmq/job/ibmqjob.py @@ -187,8 +187,10 @@ def qobj(self): return Qobj.from_dict(self._qobj_payload) 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. + """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, or None if