-
Notifications
You must be signed in to change notification settings - Fork 2.9k
advanced IBMQBackend.jobs() filtering #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f7d0409
0c92e7e
ca1eb36
67d19ac
0017ab6
1fc368d
381c6c2
f6b82cc
afbe80c
26cc808
f957804
75d4fa2
97ba015
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import time | ||
| import unittest | ||
| from concurrent import futures | ||
| import datetime | ||
|
|
||
| import numpy | ||
| from scipy.stats import chi2_contingency | ||
|
|
@@ -291,6 +292,46 @@ def test_retrieve_job_error(self): | |
| backend = _least_busy(backends) | ||
| self.assertRaises(IBMQBackendError, backend.retrieve_job, 'BAD_JOB_ID') | ||
|
|
||
| def test_get_jobs_filter_job_status(self): | ||
| backends = self._provider.available_backends() | ||
| backend = _least_busy(backends) | ||
| job_list = backend.jobs(limit=5, skip=0, status=JobStatus.DONE) | ||
| self.log.info('found %s matching jobs', len(job_list)) | ||
| for i, job in enumerate(job_list): | ||
| 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): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? :))
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| # TODO: consider generalizing backend name | ||
| backend = self._provider.get_backend('ibmq_qasm_simulator') | ||
| my_filter = {'backend.name': 'ibmq_qasm_simulator', | ||
| 'shots': 1024, | ||
| 'qasms.result.data.counts.00': {'lt': 500}} | ||
| self.log.info('searching for at most 5 jobs with 1024 shots, a count ' | ||
| 'for "00" of < 500, on the ibmq_qasm_simulator backend') | ||
| job_list = backend.jobs(limit=5, skip=0, db_filter=my_filter) | ||
| self.log.info('found %s matching jobs', len(job_list)) | ||
| for i, job in enumerate(job_list): | ||
| self.log.info('match #%d', i) | ||
| result = job.result() | ||
| self.assertTrue(any(cresult['data']['counts']['00'] < 500 | ||
| for cresult in result._result['result'])) | ||
| for circuit_name in result.get_names(): | ||
| self.log.info('\tcircuit_name: %s', circuit_name) | ||
| counts = result.get_counts(circuit_name) | ||
| self.log.info('\t%s', str(counts)) | ||
|
|
||
| def test_get_jobs_filter_date(self): | ||
| backends = self._provider.available_backends() | ||
| backend = _least_busy(backends) | ||
| past_day_30 = datetime.datetime.now() - datetime.timedelta(days=30) | ||
| my_filter = {'creationDate': {'lt': past_day_30.isoformat()}} | ||
| job_list = backend.jobs(limit=5, db_filter=my_filter) | ||
| self.log.info('found %s matching jobs', len(job_list)) | ||
| for i, job in enumerate(job_list): | ||
| self.log.info('match #%d: %s', i, job.creation_date) | ||
| self.assertTrue(job.creation_date < past_day_30.isoformat()) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main(verbosity=2) | ||
There was a problem hiding this comment.
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.