-
Notifications
You must be signed in to change notification settings - Fork 85
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
Mock hardware when testing notebooks #1184
Conversation
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
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.
Great work, Frank!
It would be good to start running this change in CI. That's fine if you prefer it to be a follow up. For the broken notebooks, we can exclude them with an ignore list and then open up an issue to fix them
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
This will take effect as soon as the PR is merged; is that ok? RE ignore list: We only run changed notebooks on PR so the broken notebooks shouldn't block anyone who's not working on them. |
The code looks good, but let's wait to merge this until we decide how to deal with Becky's concern that some of our output will leak that we're running on simulators Maybe we should not apply this patch for certain allow-listed notebooks, like the ones about how to interact with the hardware? Or we allow-list which notebooks should be mocked? Always using simulators unconditionally seems like it can cause issues. |
This feature should only be used to test code and catch bugs, not to generate notebook outputs. It does give you the option to write the simulator results to the notebook, but I don't think it's that dangerous. We could write a test for it if needed. |
But we instruct people to get output from the PR CI build: Lines 127 to 131 in 124e143
And when they run locally with
Perhaps we should consider something like this?
|
This PR (mostly) solves 1. It doesn't regress on 2 as we don't run job-submitting notebooks in CI anyway. Writers can still get hardware outputs locally using I'll update the README with the caveat about getting a notebook from CI. Maybe I can emit a warning whenever the patched
The first two bullets are basically what this PR does, just the argument to not patch is |
I'm hesitant to make submitting jobs the default as it'd be easy for a writer to unknowingly send lots of jobs to IBM Quantum, and if they kill the script while waiting, those jobs would continue to run. |
Non-job-submitting notebooks will now run with the patched simulator. For example:
I wasn't very clear in differentiating between submitting jobs vs using Runtime but not for a job. It seems we have a few categories of notebooks:
This PR will regress with the first category of notebooks like -- What if we had our CI reflect these 3 categories?
In the script itself, notebook authors would need to categorize which of the 3 buckets it falls into. Wdyt? |
This is now working (including cells with |
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.
Nice! Is my understanding correct?
- If the notebook is not listed in the TOML file, we don't patch it. We do write the output
- If the notebook is in
submit-jobs
:- if you use
--submit-jobs
, we use Runtime and--write
will work - if you don't use
--submit-jobs
, we use simulators and--write
will be ignored
- if you use
- If the notebook is in no_mock:
- always skipped unless you use
--submit-jobs
or--only-unmockable
- always skipped unless you use
Sgtm. This README should probably be updated. Maybe mention how we use simulation in CI to test notebooks that submit jobs, but we do not upload their output?
When you make a pull request with a changed notebook, you can get a version of that notebook that was executed in a uniform environment from CI. To do this, click "Show all checks" in the info box at the bottom of the pull request page on GitHub, then choose "Details" for the "Test notebooks" job. From the job page, click "Summary", then download "Executed notebooks".
--
Also PR description could use an update
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.
Great work!
@@ -30,7 +30,7 @@ jobs: | |||
|
|||
- name: Execute notebooks | |||
timeout-minutes: 350 | |||
run: tox -- --write --only-submit-jobs | |||
run: tox -- --write --only-unmockable |
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.
In our meeting, we were planning on this running all submit-jobs notebooks so that we can ensure they work on hardware + download the output.
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.
I've changed the option back to --only-submit-jobs
, which will run all job-submitting notebooks without the mock backend.
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
We only really use this in the cron job, in which we want to run all job-submitting notebooks.
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
This uses the approach discussed in Qiskit#1174 to test notebooks that submit jobs to IBM Quantum. The script behaviour has changed a bit: * We now have a list of `notebooks_no_mock`, these could include notebooks with large circuits or that demonstrate features not available on the fake backend. Future work could partially test these using the approach in [Qiskit#1173](Qiskit#1173). * By default, it runs all notebooks except `notebooks_no_mock`, with the patched package. * `--submit-jobs` will run **all** notebooks, without the patched package. * `--only-unmockable` will run only `notebooks_no_mock`, without the patched package. The following notebooks do **not** work with this patch, but some of them might not have worked anyway. * `tutorials/variational-quantum-eigensolver/notebook.ipynb` * `tutorials/submitting-transpiled-circuits/notebook.ipynb` * `tutorials/build-repitition-codes/notebook.ipynb` --------- Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
This uses the approach discussed in #1174 to test notebooks that submit jobs to IBM Quantum.
The script behaviour has changed a bit:
notebooks_no_mock
, these could include notebooks with large circuits or that demonstrate features not available on the fake backend. Future work could partially test these using the approach in #1173.notebooks_no_mock
, with the patched package.--submit-jobs
will run all notebooks, without the patched package.--only-unmockable
will run onlynotebooks_no_mock
, without the patched package.The following notebooks do not work with this patch, but some of them might not have worked anyway.
tutorials/variational-quantum-eigensolver/notebook.ipynb
tutorials/submitting-transpiled-circuits/notebook.ipynb
tutorials/build-repitition-codes/notebook.ipynb