-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test notebooks on pull request (#483)
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>
- Loading branch information
1 parent
db103fb
commit 557cb4a
Showing
3 changed files
with
183 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# This code is a Qiskit project. | ||
# | ||
# (C) Copyright IBM 2023. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
name: Test notebooks | ||
on: | ||
pull_request: | ||
paths: | ||
- "docs/**/*.ipynb" | ||
- "!docs/api/**/*" | ||
workflow_dispatch: | ||
jobs: | ||
execute: | ||
name: Execute notebooks | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" | ||
cache: "pip" | ||
|
||
- name: Get all changed files | ||
id: all-changed-files | ||
uses: tj-actions/changed-files@af2816c65436325c50621100d67f6e853cd1b0f1 | ||
|
||
- 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 | ||
- name: Install Python packages | ||
# This is to save our account in the next step. Note that the | ||
# package will be re-installed during the "Run tox" step. | ||
run: pip install qiskit-ibm-runtime tox | ||
|
||
- name: Save IBM Quantum account | ||
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} | ||
shell: python | ||
run: | | ||
from qiskit_ibm_runtime import QiskitRuntimeService | ||
QiskitRuntimeService.save_account( | ||
channel="ibm_quantum", | ||
instance="ibm-q/open/main", | ||
token="${{ secrets.IBM_QUANTUM_TEST_TOKEN }}", | ||
set_as_default=True | ||
) | ||
- name: Cache tox environment | ||
uses: actions/cache@v3 | ||
with: | ||
path: ".tox" | ||
key: ${{ hashFiles('scripts/nb-tester/requirements.txt') }} | ||
|
||
- name: Run tox | ||
run: tox -- ${{ steps.all-changed-files.outputs.all_changed_files }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters