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

Make sure all notebooks are classified in notebooks.toml #1359

Merged
merged 2 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions scripts/nb-tester/notebooks.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
# Used to find all notebooks in the repo
all_notebooks = "[!.]*/**/*.ipynb"
# For notebooks to be tested "normally" (no mocking)
notebooks_normal_test = [
"docs/build/circuit-construction.ipynb",
"docs/build/circuit-library.ipynb",
"docs/build/circuit-visualization.ipynb",
"docs/build/classical-feedforward-and-control-flow.ipynb",
"docs/build/operators-overview.ipynb",
"docs/build/pulse.ipynb",
"docs/build/save-circuits.ipynb",
"docs/run/dynamic-circuits-considerations.ipynb",
"docs/run/get-backend-information.ipynb",
"docs/run/save-jobs.ipynb",
"docs/run/visualize-results.ipynb",
"docs/transpile/common-parameters.ipynb",
"docs/transpile/create-a-transpiler-plugin.ipynb",
"docs/transpile/custom-backend.ipynb",
"docs/transpile/custom-transpiler-pass.ipynb",
"docs/transpile/defaults-and-configuration-options.ipynb",
"docs/transpile/dynamical-decoupling-pass-manager.ipynb",
"docs/transpile/representing_quantum_computers.ipynb",
"docs/transpile/set-optimization.ipynb",
"docs/transpile/transpile-with-pass-managers.ipynb",
"docs/transpile/transpiler-plugins.ipynb",
"docs/transpile/transpiler-stages.ipynb",
"docs/verify/building_noise_models.ipynb",
"docs/verify/local-testing-mode.ipynb",
"docs/verify/plot-quantum-states.ipynb",
"docs/verify/simulate-with-qiskit-aer.ipynb",
"docs/verify/stabilizer-circuit-simulation.ipynb",
"tutorials/explore-composer/explore-composer.ipynb",
]

# Always exclude notebooks matching the following patterns
# Don't test the following notebooks (this section can include glob patterns)
notebooks_exclude = [
"scripts/ibm-quantum-learning-uploader/test/template.ipynb",
"**/.ipynb_checkpoints/**",
Expand All @@ -20,6 +49,8 @@ notebooks_that_submit_jobs = [
]

# The following notebooks submit jobs that are too big to mock with a simulator
# A job is "too big" if a cell can't run in under 5 mins, or we run out of
# memory on a reasonable device.
notebooks_no_mock = [
"docs/start/hello-world.ipynb",
]
34 changes: 32 additions & 2 deletions scripts/nb-tester/qiskit_docs_notebook_tester/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def patched_least_busy(self, *args, **kwarg):
@dataclass
class Config:
args: argparse.Namespace
all_notebooks: str
notebooks_normal_test: list[str]
notebooks_exclude: list[str]
notebooks_that_submit_jobs: list[str]
notebooks_no_mock: list[str]
Expand All @@ -58,6 +58,21 @@ class Config:
def all_job_submitting_notebooks(self) -> list[str]:
return [*self.notebooks_that_submit_jobs, *self.notebooks_no_mock]

@property
def all_notebooks_to_test(self) -> list[str]:
return [
*self.notebooks_normal_test,
*self.notebooks_that_submit_jobs,
*self.notebooks_no_mock,
]

@property
def all_notebooks(self) -> list[str]:
return [
*self.all_notebooks_to_test,
*self.notebooks_exclude,
]

@classmethod
def from_args(cls, args: argparse.Namespace) -> Config:
"""
Expand All @@ -76,7 +91,7 @@ def notebooks_to_execute(self) -> Iterator[Path]:
"""
Yield notebooks to be executed, printing messages for any skipped files.
"""
paths = map(Path, self.args.filenames or Path(".").glob(self.all_notebooks))
paths = map(Path, self.args.filenames or self.all_notebooks_to_test)
for path in paths:
if path.suffix != ".ipynb":
print(f"ℹ️ Skipping {path}; file is not `.ipynb` format.")
Expand All @@ -102,6 +117,20 @@ def notebooks_to_execute(self) -> Iterator[Path]:

yield path

def check_all_notebooks_are_classified(self) -> None:
unclassified = [
path for path in Path(".").glob("[!.]*/**/*.ipynb")
if not matches(path, self.all_notebooks)
]
if unclassified == []:
return
print(
f"\nThe following notebooks are not classified in {self.args.config_path}:\n "
+ "\n ".join(map(str, unclassified))
+ "\nAdd them to the appropriate group so we know how to test them.\n"
)
sys.exit(1)
frankharkins marked this conversation as resolved.
Show resolved Hide resolved

def should_patch(self, path: Path) -> bool:
if self.args.submit_jobs:
return False
Expand Down Expand Up @@ -314,6 +343,7 @@ def get_args() -> argparse.Namespace:

async def _main() -> None:
config = Config.from_args(get_args())
config.check_all_notebooks_are_classified()
paths = config.notebooks_to_execute()

# Execute notebooks
Expand Down
Loading