Skip to content

Migrate testing to cloud #3363

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 7 additions & 9 deletions .github/actions/set-up-notebook-testing/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ inputs:
install-linux-deps:
description: Whether to install extra dependencies
default: "false"
ibm-quantum-token:
default: ""
ibm-cloud-token:
description: "Token for quantum.cloud.ibm.com"
required: true
instance:
# We usually only want the same access as an open user, but occasionally we
# need higher priority to test notebooks that submit jobs in reasonable
# time
default: "ibm-q/open/main"
description: "CRN for quantum.cloud.ibm.com"
required: true
runs:
using: "composite"
steps:
Expand All @@ -35,14 +34,13 @@ runs:
run: pip install tox qiskit-ibm-runtime

- name: Save IBM Quantum account
if: ${{ inputs.ibm-quantum-token != '' }}
shell: python
run: |
from qiskit_ibm_runtime import QiskitRuntimeService
QiskitRuntimeService.save_account(
channel="ibm_quantum",
channel="ibm_cloud",
instance="${{ inputs.instance }}",
token="${{ inputs.ibm-quantum-token }}",
token="${{ inputs.ibm-cloud-token }}",
set_as_default=True
)

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ jobs:

- name: Setup Python environment
uses: ./.github/actions/set-up-notebook-testing
with:
ibm-cloud-token: ${{ secrets.IBM_CLOUD_TEST_TOKEN }}
instance: ${{ vars.IBM_CLOUD_TEST_CRN }}

- name: Check all notebooks are listed in the config file
run: python scripts/ci/check-all-notebooks-are-tested.py
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/notebook-test-cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:
- name: Setup environment
uses: ./.github/actions/set-up-notebook-testing
with:
ibm-quantum-token: ${{ secrets.IBM_QUANTUM_TEST_TOKEN }}
instance: "client-enablement/documentation/qiskit-documenta"
ibm-cloud-token: ${{ secrets.IBM_CLOUD_TEST_TOKEN }}
instance: ${{ vars.IBM_CLOUD_TEST_CRN }}
install-linux-deps: true

- name: Execute notebooks
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/notebook-test-extended.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ jobs:
- name: Setup environment
uses: ./.github/actions/set-up-notebook-testing
with:
ibm-quantum-token: ${{ secrets.IBM_QUANTUM_TEST_TOKEN }}
instance: "client-enablement/documentation/qiskit-documenta"
ibm-cloud-token: ${{ secrets.IBM_CLOUD_TEST_TOKEN }}
instance: ${{ vars.IBM_CLOUD_TEST_CRN }}
install-linux-deps: true

- name: Execute notebooks
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/notebook-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ jobs:
# Install Linux deps if the specific guides were changed, or
# if all files are being tested.
install-linux-deps: ${{ steps.check-deps.outputs.NEEDS_EXTRA_DEPS }}
ibm-quantum-token: ${{ secrets.IBM_QUANTUM_TEST_TOKEN }}
ibm-cloud-token: ${{ secrets.IBM_CLOUD_TEST_TOKEN }}
instance: ${{ vars.IBM_CLOUD_TEST_CRN }}

- name: Execute notebooks
env:
Expand Down
20 changes: 19 additions & 1 deletion scripts/nb-tester/qiskit_docs_notebook_tester/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,30 @@

# We always run the following code in the kernel before running the notebook
PRE_EXECUTE_CODE = """\
import logging
import re
# Import with underscores to avoid interfering with user-facing code.
from matplotlib import set_loglevel as _set_mpl_loglevel


# See https://github.com/matplotlib/matplotlib/issues/23326#issuecomment-1164772708
_set_mpl_loglevel("critical")


# Ignore server configuration warnings from qiskit-ibm-runtime; we can't control these and they seem to be benign
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, could you please check in with the Qiskit Runtime team in #qiskit-runtime-open in Slack about these? It would be good to confirm they're aware of them. We don't want users encountering these issues. Depending on their reply, we should probably create a GH issue to track reverting this patch.

def _runtime_warnings_filter(record):
return False
ignore_patterns = {
# If you add more patterns, make sure to add the filter to the correct logger path using getLogger
r'Remote backend "[_a-z]+" for service instance .+ could not be instantiated due to an invalid server-side configuration',
r"Unable to create configuration for [_a-z]+. 'NoneType' object has no attribute 'basis_gates'"
}
if any(re.match(pattern, record.getMessage()) for pattern in ignore_patterns):
return False
return True

# We must add the filter to each module that emits warnings to be filtered
logging.getLogger("qiskit_ibm_runtime.utils.backend_decoder").addFilter(_runtime_warnings_filter)
logging.getLogger("qiskit_ibm_runtime.qiskit_runtime_service").addFilter(_runtime_warnings_filter)
Comment on lines +37 to +51
Copy link
Member Author

Choose a reason for hiding this comment

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

Runtime emits warnings through logging rather than warnings, which is a bit clunkier to work with.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be useful feedback to share with the Runtime team

"""


Expand Down
3 changes: 2 additions & 1 deletion scripts/nb-tester/qiskit_docs_notebook_tester/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
from .config import NotebookJob, Result
from .post_process import post_process_notebook


# Keep this in sync with
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Keep this in sync with
# Keep this in sync with `OPEN_BACKENDS` in

# scripts/nb-tester/qiskit_docs_notebook_tester/patches/qiskit-ibm-runtime-open
OPEN_BACKENDS_TO_INTERNAL = {
"ibm_brisbane": "alt_brisbane",
"ibm_torino": "alt_torino",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ from qiskit_ibm_runtime import QiskitRuntimeService

QiskitRuntimeService._original_least_busy = QiskitRuntimeService.least_busy

# Backends that we have access to through both internal and open plans
# Keep this in sync with
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Keep this in sync with
#
# Keep this in sync with `OPEN_BACKENDS_TO_INTERNAL`

# scripts/nb-tester/qiskit_docs_notebook_tester/execute.py
OPEN_BACKENDS = ["brisbane", "torino"]

def is_open(backend):
return any(backend.name.endswith(f"_{name}") for name in OPEN_BACKENDS)

def patched_least_busy(self, *args, **kwargs):
open_backends = [b.name for b in self.backends(instance="ibm-q/open/main")]
return self._original_least_busy(filters=lambda backend: backend.name in open_backends)
return self._original_least_busy(filters=is_open)
Comment on lines 5 to +16
Copy link
Member Author

Choose a reason for hiding this comment

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

This function patches least_busy to make sure we only use open-provider backends. The existing logic won't work any more, so I've updated it with hardcoded names like we did in #3273.


QiskitRuntimeService.least_busy = patched_least_busy
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ deps =
-e scripts/nb-tester
-r scripts/nb-tester/requirements.txt
setenv = PYDEVD_DISABLE_FILE_VALIDATION=1
commands = test-docs-notebooks {posargs} --check-pending-deprecations --config-path scripts/config/notebook-testing.toml
commands = test-docs-notebooks {posargs} --check-pending-deprecations --config-path scripts/config/notebook-testing.toml --map-open-backends-to-internal

[testenv:{lint,fix}]
deps =
Expand Down