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

Upgrade Runtime and Provider for notebook testing #1202

Merged
merged 2 commits into from
Apr 19, 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
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
30 changes: 13 additions & 17 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 @@ -149,9 +148,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 @@ -189,8 +186,8 @@ def find_notebooks() -> list[Path]:


def cancel_trailing_jobs(start_time: datetime) -> bool:
"""
Cancel any runtime jobs created after `start_time`.
"""Cancel any runtime jobs created after `start_time`.

frankharkins marked this conversation as resolved.
Show resolved Hide resolved
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 +197,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 +252,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 +266,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
if not all(results):
sys.exit(1)
sys.exit(0)


if __name__ == "__main__":
main()
Loading