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

Redesign nb-tester interface #2405

Merged
merged 13 commits into from
Dec 9, 2024
Merged

Redesign nb-tester interface #2405

merged 13 commits into from
Dec 9, 2024

Conversation

frankharkins
Copy link
Member

@frankharkins frankharkins commented Nov 28, 2024

Attempt to simplify the way we control nb-tester.

This PR includes the patch information in the config file. Like before, each notebook is part of a group. The new aspect is each group can define how to patch each notebook in different situations.

This PR also adds tests and documentation for the config part of the script. If you exclude the new README and tests, this PR reduces the script size by ~100 LOC.

Config example

Take the following config file as an example.

[my-group]
test-strategy.ci = { patch="qiskit_ibm_runtime", backend="test-eagle" }
test-strategy.hardware = {}
notebooks = ["..."]

If we run nb-tester against this file with --test-strategy=ci, each notebook in the group will be patched with the test-eagle device. If we run it with --test-strategy=hardware, the notebooks will be run with no patch. Running with a test strategy not defined for that group (e.g. --test-strategy=new-strat) means that group will be skipped.

CLI example

You can also run the script without a config file with the --patch arg. In this case, all files listed after the --patch argument are part of the same "group". You must include a patch for this group using TOML syntax. For example:

test-docs-notebooks --patch '{ patch="qiskit-fake-provider", num_qubits=6 }' path/to/file.ipynb

Closes #2401

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

github-merge-queue bot pushed a commit that referenced this pull request Dec 3, 2024
Pre-work for #2405.

This PR refactors nb-tester to decouple the config logic, which decides
which notebooks to run and how to patch them, from the notebook
execution logic, which runs the notebooks.

The config logic is already the most complicated part of the program.
This PR decouples config and execution by moving them to separate files
and having them communicate only by a single `NotebookJob` interface.
Each `NotebookJob` contains a notebook path and instructions on how to
run that notebook. This means the config logic can be scoped to creating
a list of `NotebookJob` objects. This also makes the config logic easier
to test.

There _should_ be no behaviour changes in this PR.
@@ -14,7 +14,6 @@ dependencies = [
"nbformat~=5.10.4",
"ipykernel~=6.29.2",
"squeaky==0.7.0",
"tomli==2.2.1",
Copy link
Member Author

Choose a reason for hiding this comment

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

Switched to the built-in tomllib. I believe we kept tomli for a while for backwards-compatibility with older Python versions, but we now specify Python >= 3.11 in the pyproject.toml, so I think it's time to remove it here.

.github/workflows/notebook-test.yml Outdated Show resolved Hide resolved
@frankharkins frankharkins marked this pull request as ready for review December 3, 2024 15:23
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.

I like this interface! It's a good design to only allow specifying one test strategy at a time. If you want to run with multiple test strategies, then run once per test strategy. That keeps the interface and code more understandable.

Nit in the PR title that this is not a "refactor" but a "revamp" or "redesign".

Consider splitting out the changes I proposed with scripts/ci as a prefactor. Fwict, they can be separated out from everything else. We've messed up CI config before, so it's worth having close review on them.

.github/workflows/main.yml Outdated Show resolved Hide resolved
.github/workflows/notebook-test.yml Outdated Show resolved Hide resolved
scripts/config/notebook-testing.toml Outdated Show resolved Hide resolved
scripts/config/notebook-testing.toml Outdated Show resolved Hide resolved
scripts/nb-tester/qiskit_docs_notebook_tester/config.py Outdated Show resolved Hide resolved
@frankharkins frankharkins changed the title Refactor nb-tester interface Redesign nb-tester interface Dec 3, 2024
github-merge-queue bot pushed a commit that referenced this pull request Dec 5, 2024
Splits out part of #2405

This PR pulls some of our CI functionality out of the nb-tester package
and into separate scripts.
Copy link
Collaborator

@emilkovacev emilkovacev left a comment

Choose a reason for hiding this comment

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

Great PR! Thank you for implementing the file patch interface, I think it will be really powerful. I included a couple of suggestions for how to utilize patches, and a small formatting error.

scripts/nb-tester/qiskit_docs_notebook_tester/config.py Outdated Show resolved Hide resolved
scripts/nb-tester/qiskit_docs_notebook_tester/config.py Outdated Show resolved Hide resolved
scripts/nb-tester/README.md Outdated Show resolved Hide resolved
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.

Amazing work Frank! I left a small typo fix suggestion and a comment about the args that I think it's cool to know. I like a lot the new interface and the code looks good, so I think we can merge it once @emilkovacev's suggestions are implemented :)

scripts/nb-tester/README.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@emilkovacev emilkovacev left a comment

Choose a reason for hiding this comment

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

New patching interface works really well! I tested this against a few notebooks locally, and was able to very quickly and easily get them to run.

@frankharkins frankharkins added this pull request to the merge queue Dec 9, 2024
Merged via the queue into main with commit 6d112ea Dec 9, 2024
3 checks passed
@frankharkins frankharkins deleted the FH/nb-tester-config branch December 9, 2024 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[nb-tester]: Improve config
4 participants