Skip to content
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

Test notebooks on pull request #483

Merged
merged 25 commits into from
Dec 14, 2023
Merged

Test notebooks on pull request #483

merged 25 commits into from
Dec 14, 2023

Conversation

frankharkins
Copy link
Member

@frankharkins frankharkins commented Dec 6, 2023

Adds a GitHub action to test notebook code examples on pull request.

Handling notebooks that submit jobs

We only want to submit jobs to IBM Quantum very rarely (such as updating notebook outputs once per qiskit release), but runtime doesn't have a way of restricting the types of job you can send.

In this PR, I've limited cell execution to 100s. This should be short enough to do most local tasks and to get backend information, but not nearly long enough for a job to run on the open provider (usually takes hours).

If someone accidentally makes a PR with a notebook that submits jobs, the script will timeout and raise an error. On exit, the script cancels any jobs created since it started running. This means they won't take up any resources, and the author will be alerted when CI fails.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@Eric-Arellano
Copy link
Collaborator

qiskit_ibm_runtime.accounts.exceptions.InvalidAccountError: "Invalid token value. Expected a non-empty string, got ''."

Should we skip these notebooks? Or somehow the specific code blocks? We want to be careful that CI doesn't burn through a bunch of compute resources.

Comment on lines +35 to +47
- name: Check for notebooks that require LaTeX
id: latex-changed-files
uses: tj-actions/changed-files@af2816c65436325c50621100d67f6e853cd1b0f1
with:
# Add your notebook to this list if it needs latex to run
files: |
docs/build/circuit-visualization.ipynb

- name: Install LaTeX dependencies
if: steps.latex-changed-files.outputs.any_changed == 'true'
run: |
sudo apt-get update
sudo apt-get install texlive-pictures texlive-latex-extra poppler-utils
Copy link
Member Author

Choose a reason for hiding this comment

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

I've replaced the bash logic with this, should be easier to understand, and the step will now appear as "skipped" in the action log if it doesn't run.

@frankharkins
Copy link
Member Author

See 358eb2f and 1ff5fed for examples of this working.

Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

This is looking excellent 🙌

scripts/nb-tester/test-notebook.py Outdated Show resolved Hide resolved
scripts/nb-tester/test-notebook.py Outdated Show resolved Hide resolved
scripts/nb-tester/test-notebook.py Outdated Show resolved Hide resolved
scripts/nb-tester/test-notebook.py Outdated Show resolved Hide resolved
scripts/nb-tester/test-notebook.py Outdated Show resolved Hide resolved
Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Looks great! But we probably want Arnau to review it first

Copy link
Collaborator

@arnaucasau arnaucasau left a comment

Choose a reason for hiding this comment

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

Great job Frank! I've been testing the script with different arguments and files, and besides a small thing (see below), all worked really well! I like a lot the way you wrote the test using actions to get the changed files, and good thinking adding the conditional to install the latex packages only when necessary!

scripts/nb-tester/test-notebook.py Outdated Show resolved Hide resolved
Co-authored-by: Arnau Casau <47946624+arnaucasau@users.noreply.github.com>
@frankharkins frankharkins added this pull request to the merge queue Dec 14, 2023
Merged via the queue into main with commit 557cb4a Dec 14, 2023
2 checks passed
@frankharkins frankharkins deleted the FH/notebook-ci branch December 14, 2023 15:00
github-merge-queue bot pushed a commit that referenced this pull request Dec 18, 2023
This PR addresses a couple of edge cases I didn't consider in #483.

- ~~Adds a token for `qiskit_ibm_provider`, and checks for trailing jobs
as we already do for runtime.~~
  
Turns out provider and runtime share saved account info, and
`QiskitRuntimeService.jobs` includes provider jobs, which means the
script already handles this fine.
- Don't run job-submitting notebooks without the `--submit-jobs` flag,
even if passed explicitly.

Currently, PR tests will fail if we edit these notebooks as the script
will try to run them and they'll time out.
To avoid having two lists of "notebooks that submit jobs" (one in the
script and one in the action), I'm requiring the flag.
frankharkins added a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
Adds a GitHub action to test notebook code examples on pull request.

### Handling notebooks that submit jobs

We only want to submit jobs to IBM Quantum _very_ rarely (such as
updating notebook outputs once per qiskit release), but runtime doesn't
have a way of restricting the types of job you can send.

In this PR, I've limited cell execution to 100s. This should be short
enough to do most local tasks and to get backend information, but not
nearly long enough for a job to run on the open provider (usually takes
hours).

If someone accidentally makes a PR with a notebook that submits jobs,
the script will timeout and raise an error. On exit, the script cancels
any jobs created since it started running. This means they won't take up
any resources, and the author will be alerted when CI fails.

---------

Co-authored-by: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com>
Co-authored-by: Arnau Casau <47946624+arnaucasau@users.noreply.github.com>
frankharkins added a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
This PR addresses a couple of edge cases I didn't consider in Qiskit#483.

- ~~Adds a token for `qiskit_ibm_provider`, and checks for trailing jobs
as we already do for runtime.~~
  
Turns out provider and runtime share saved account info, and
`QiskitRuntimeService.jobs` includes provider jobs, which means the
script already handles this fine.
- Don't run job-submitting notebooks without the `--submit-jobs` flag,
even if passed explicitly.

Currently, PR tests will fail if we edit these notebooks as the script
will try to run them and they'll time out.
To avoid having two lists of "notebooks that submit jobs" (one in the
script and one in the action), I'm requiring the flag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Test Jupyter notebooks in CI
3 participants