Skip to content

advanced IBMQBackend.jobs() filtering#585

Merged
atilag merged 13 commits into
Qiskit:masterfrom
ewinston:job_filter
Jun 29, 2018
Merged

advanced IBMQBackend.jobs() filtering#585
atilag merged 13 commits into
Qiskit:masterfrom
ewinston:job_filter

Conversation

@ewinston
Copy link
Copy Markdown
Contributor

@ewinston ewinston commented Jun 20, 2018

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,

job_list = backend.jobs(limit=5, filter={'backend.name'='ibmq_qasm_simulator, 'shots': 1024,
                                         'qasms.result.data.counts.00': {'gt': 400},
                                         'qasms.result.data.counts.11': {'gt': 400}})

To get jobs from 30 days ago,

past_day_30 = datetime.datetime.now() - datetime.timedelta(days=30)
my_filter = {'creationDate': {'lt': past_day_30.isoformat()}}
job_list = backend.jobs(limit=5, filter=my_filter)

@ajavadia
Copy link
Copy Markdown
Member

I think we forgot to update the CHANGELOG in #501.. can you do it here, since they touch the same feature?

ewinston added 3 commits June 21, 2018 12:59
Previously when using the filter keyword it would return jobs from any backend satisfying the filter.
@ewinston
Copy link
Copy Markdown
Contributor Author

@ajavadia I updated the CHANGELOG.

Copy link
Copy Markdown
Member

@atilag atilag left a comment

Choose a reason for hiding this comment

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

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.

Comment thread qiskit/backends/ibmq/ibmqbackend.py Outdated
list(IBMQJob): list of IBMQJob instances

Raises:
ValueError: status keyword value unrecognized
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.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sounds good

Comment thread qiskit/backends/ibmq/ibmqbackend.py Outdated
if status == JobStatus.RUNNING:
this_filter = {'status': 'RUNNING',
'infoQueue': {'exists': False}}
api_filter = {**api_filter, **this_filter}
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.

Just a simple suggestion, I found this code clearer:

api_filter.update( this_filter )

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sounds good

'infoQueue.status': 'PENDING_IN_QUEUE'}
api_filter = {**api_filter, **this_filter}
elif status == JobStatus.CANCELLED:
this_filter = {'status': 'CANCELLED'}
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 this_filter is not used anywhere.

elif status == JobStatus.CANCELLED:
this_filter = {'status': 'CANCELLED'}
elif status == JobStatus.DONE:
this_filter = {'status': 'COMPLETED'}
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.

Same as above, this is not used anywhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks

elif status == JobStatus.DONE:
this_filter = {'status': 'COMPLETED'}
elif status == JobStatus.ERROR:
this_filter = {'status': {'regexp': '^ERROR'}}
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.

... and same as above, this is not used anywhere.

Comment thread qiskit/backends/ibmq/ibmqbackend.py Outdated
elif status == JobStatus.ERROR:
this_filter = {'status': {'regexp': '^ERROR'}}
else:
raise ValueError('unrecongized value for "status" keyword '
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.

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):
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.

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? :))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@ewinston ewinston changed the title [WIP] advanced IBMQBackend.jobs() filtering advanced IBMQBackend.jobs() filtering Jun 28, 2018
@atilag atilag merged commit 61392d7 into Qiskit:master Jun 29, 2018
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* Implement advanced backend.jobs() filtering
@ewinston ewinston deleted the job_filter branch April 6, 2021 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants