Skip to content

Commit 4cbe23f

Browse files
committed
Ignore warnings
These are emitted through the logging module, which is clunkier to work with
1 parent 5093a8f commit 4cbe23f

File tree

1 file changed

+19
-1
lines changed
  • scripts/nb-tester/qiskit_docs_notebook_tester

1 file changed

+19
-1
lines changed

scripts/nb-tester/qiskit_docs_notebook_tester/config.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,30 @@
2525

2626
# We always run the following code in the kernel before running the notebook
2727
PRE_EXECUTE_CODE = """\
28+
import logging
29+
import re
2830
# Import with underscores to avoid interfering with user-facing code.
2931
from matplotlib import set_loglevel as _set_mpl_loglevel
3032
31-
3233
# See https://github.com/matplotlib/matplotlib/issues/23326#issuecomment-1164772708
3334
_set_mpl_loglevel("critical")
35+
36+
37+
# Ignore server configuration warnings from qiskit-ibm-runtime; we can't control these and they seem to be benign
38+
def _runtime_warnings_filter(record):
39+
return False
40+
ignore_patterns = {
41+
# If you add more patterns, make sure to add the filter to the correct logger path using getLogger
42+
r'Remote backend "[_a-z]+" for service instance .+ could not be instantiated due to an invalid server-side configuration',
43+
r"Unable to create configuration for [_a-z]+. 'NoneType' object has no attribute 'basis_gates'"
44+
}
45+
if any(re.match(pattern, record.getMessage()) for pattern in ignore_patterns):
46+
return False
47+
return True
48+
49+
# We must add the filter to each module that emits warnings to be filtered
50+
logging.getLogger("qiskit_ibm_runtime.utils.backend_decoder").addFilter(_runtime_warnings_filter)
51+
logging.getLogger("qiskit_ibm_runtime.qiskit_runtime_service").addFilter(_runtime_warnings_filter)
3452
"""
3553

3654

0 commit comments

Comments
 (0)