Skip to content

Commit

Permalink
Upgrade Runtime and Provider for notebook testing (#1202)
Browse files Browse the repository at this point in the history
Notebooks were tested locally with `tox`. Everything succeeded except
for `save-jobs.ipynb` because it doesn't work with other users'
accounts.
  • Loading branch information
Eric-Arellano authored Apr 19, 2024
1 parent 5c8c0bb commit c46e612
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions scripts/nb-tester/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 12 additions & 13 deletions scripts/nb-tester/test-notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import argparse
import sys
import warnings
import textwrap
from dataclasses import dataclass
from datetime import datetime
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -274,3 +269,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
if not all(results):
sys.exit(1)
sys.exit(0)


if __name__ == "__main__":
main()

0 comments on commit c46e612

Please sign in to comment.