From c46e6123b97256a1bbaaca29619ecb1bf14383d6 Mon Sep 17 00:00:00 2001 From: Eric Arellano <14852634+Eric-Arellano@users.noreply.github.com> Date: Fri, 19 Apr 2024 09:16:11 -0400 Subject: [PATCH] Upgrade Runtime and Provider for notebook testing (#1202) Notebooks were tested locally with `tox`. Everything succeeded except for `save-jobs.ipynb` because it doesn't work with other users' accounts. --- scripts/nb-tester/requirements.txt | 4 ++-- scripts/nb-tester/test-notebook.py | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/scripts/nb-tester/requirements.txt b/scripts/nb-tester/requirements.txt index abded1191f8..d154fb0897c 100644 --- a/scripts/nb-tester/requirements.txt +++ b/scripts/nb-tester/requirements.txt @@ -5,6 +5,6 @@ nbformat~=5.9.2 ipykernel~=6.29.2 qiskit[all]~=1.0 qiskit-aer~=0.14.0.1 -qiskit-ibm-runtime~=0.22.0 -qiskit-ibm-provider~=0.10.0 +qiskit-ibm-runtime~=0.23.0 +qiskit-ibm-provider~=0.11.0 squeaky==0.7.0 diff --git a/scripts/nb-tester/test-notebook.py b/scripts/nb-tester/test-notebook.py index 753c1e88a2a..9ce5dbdf454 100644 --- a/scripts/nb-tester/test-notebook.py +++ b/scripts/nb-tester/test-notebook.py @@ -12,7 +12,6 @@ import argparse import sys -import warnings import textwrap from dataclasses import dataclass from datetime import datetime @@ -150,7 +149,7 @@ def execute_notebook(path: Path, args: argparse.Namespace) -> bool: def _execute_notebook(filepath: Path, args: argparse.Namespace) -> nbformat.NotebookNode: """ - Use nbconvert to execute notebook + Use nbconvert to execute notebook. """ submit_jobs = args.submit_jobs or args.only_submit_jobs nb = nbformat.read(filepath, as_version=4) @@ -191,6 +190,7 @@ def find_notebooks() -> list[Path]: def cancel_trailing_jobs(start_time: datetime) -> bool: """ Cancel any runtime jobs created after `start_time`. + Return True if non exist, False otherwise. Notebooks should not submit jobs during a normal test run. If they do, the @@ -200,16 +200,11 @@ def cancel_trailing_jobs(start_time: datetime) -> bool: If a notebook submits a job but does not wait for the result, this check will also catch it and cancel the job. """ - # QiskitRuntimeService().jobs() includes qiskit-ibm-provider jobs too - service = QiskitRuntimeService() - - def _is_not_finished(job): - # Force runtime to update job status - # Workaround for Qiskit/qiskit-ibm-runtime#1547 - job.status() - return not job.in_final_state() - - jobs = list(filter(_is_not_finished, service.jobs(created_after=start_time))) + jobs = [ + job + for job in QiskitRuntimeService().jobs(created_after=start_time) + if not job.in_final_state() + ] if not jobs: return True @@ -260,7 +255,7 @@ def create_argument_parser() -> argparse.ArgumentParser: return parser -if __name__ == "__main__": +def main() -> None: args = create_argument_parser().parse_args() paths = map(Path, args.filenames or find_notebooks()) filtered_paths = filter_paths(paths, args) @@ -274,3 +269,7 @@ def create_argument_parser() -> argparse.ArgumentParser: if not all(results): sys.exit(1) sys.exit(0) + + +if __name__ == "__main__": + main()