advanced IBMQBackend.jobs() filtering#585
Conversation
|
I think we forgot to update the CHANGELOG in #501.. can you do it here, since they touch the same feature? |
Previously when using the filter keyword it would return jobs from any backend satisfying the filter.
|
@ajavadia I updated the CHANGELOG. |
atilag
left a comment
There was a problem hiding this comment.
Thanks Erick! We have simplified a lot this functionality, and seems good overall... I've just left some comments that will probably need to be addressed before merging.
| list(IBMQJob): list of IBMQJob instances | ||
|
|
||
| Raises: | ||
| ValueError: status keyword value unrecognized |
There was a problem hiding this comment.
Throwing ValueError in this case gives a lot semantic meaning, which could be very useful for our user's code, this is great, but in order to keep the policy of everything thrown from QISKit should inherit from QISKitError, I'd suggest adding even more semantic meaning by creating a new exception class here that inherits from ValueError and IBMQBackendError:
IBMQBackendValueError(IBMQBackendError, ValueError):
""" Value errors thrown within IBMQBackend """
pass
This way, user's code could capture exceptions by ValueError or QISKitError.
| if status == JobStatus.RUNNING: | ||
| this_filter = {'status': 'RUNNING', | ||
| 'infoQueue': {'exists': False}} | ||
| api_filter = {**api_filter, **this_filter} |
There was a problem hiding this comment.
Just a simple suggestion, I found this code clearer:
api_filter.update( this_filter )
What do you think?
| 'infoQueue.status': 'PENDING_IN_QUEUE'} | ||
| api_filter = {**api_filter, **this_filter} | ||
| elif status == JobStatus.CANCELLED: | ||
| this_filter = {'status': 'CANCELLED'} |
There was a problem hiding this comment.
This this_filter is not used anywhere.
| elif status == JobStatus.CANCELLED: | ||
| this_filter = {'status': 'CANCELLED'} | ||
| elif status == JobStatus.DONE: | ||
| this_filter = {'status': 'COMPLETED'} |
There was a problem hiding this comment.
Same as above, this is not used anywhere.
| elif status == JobStatus.DONE: | ||
| this_filter = {'status': 'COMPLETED'} | ||
| elif status == JobStatus.ERROR: | ||
| this_filter = {'status': {'regexp': '^ERROR'}} |
There was a problem hiding this comment.
... and same as above, this is not used anywhere.
| elif status == JobStatus.ERROR: | ||
| this_filter = {'status': {'regexp': '^ERROR'}} | ||
| else: | ||
| raise ValueError('unrecongized value for "status" keyword ' |
There was a problem hiding this comment.
Maybe raising: IBMQBackendValueError('...')?
| self.log.info('match #%d: %s', i, job.result()._result['status']) | ||
| self.assertTrue(job.status['status'] == JobStatus.DONE) | ||
|
|
||
| def test_get_jobs_filter_counts(self): |
There was a problem hiding this comment.
What about first sending the jobs before testing them? I'm only worried about what happens if there's no such jobs in the server, so the test always passes and is not testing anything. (... maybe am I being to much skeptical? :))
There was a problem hiding this comment.
I agree. I think I did this because of the trouble with assuring a job status for testing. It's a good argument for mocking the server.
* Implement advanced backend.jobs() filtering
Summary
Enable more advanced filtering when getting past jobs from IBM Q backends.
Details and comments
To get the last 5 jobs with errors:
job_list = backend.jobs(limit=5, status='ERROR')To get the last 5 jobs with 1024 shots and counts of 00 and 11 exceeding 400,
To get jobs from 30 days ago,