Skip to content

Commit

Permalink
better module deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
1ucian0 committed Aug 14, 2024
1 parent 20b51e6 commit 336aed1
Showing 1 changed file with 29 additions and 8 deletions.
37 changes: 29 additions & 8 deletions qiskit/providers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
GateProperties
Nduv
"""
import importlib
import warnings

from .backendconfiguration import (
Expand All @@ -52,12 +53,32 @@
from .jobstatus import JobStatus
from .pulsedefaults import PulseDefaults, Command

_NAME_MAP = {
# public object name mapped to containing module
"BackendConfiguration": "qiskit.providers.models.backendconfiguration",
"PulseBackendConfiguration": "qiskit.providers.models.backendconfiguration",
"QasmBackendConfiguration": "qiskit.providers.models.backendconfiguration",
"UchannelLO": "qiskit.providers.models.backendconfiguration",
"GateConfig": "qiskit.providers.models.backendconfiguration",
"BackendProperties": "qiskit.providers.models.backendproperties",
"GateProperties": "qiskit.providers.models.backendproperties",
"Nduv": "qiskit.providers.models.backendproperties",
"BackendStatus": "qiskit.providers.models.backendstatus",
"JobStatus": "qiskit.providers.models.jobstatus",
"PulseDefaults": "qiskit.providers.models.pulsedefaults",
"Command": "qiskit.providers.models.pulsedefaults",
}

warnings.warn(
"qiskit.providers.models is deprecated since Qiskit 1.2 and will be removed in Qiskit 2.0. "
"With the removal of Qobj, there is no need for these schema-conformant objects. If you still need "
"to use them, it could be because you are using a BackendV1, which is also deprecated in favor "
"of BackendV2.",
DeprecationWarning,
2,
)

def __getattr__(name):
if (module_name := _NAME_MAP.get(name)) is not None:
warnings.warn(
"qiskit.providers.models is deprecated since Qiskit 1.2 and will be "
"removed in Qiskit 2.0. With the removal of Qobj, there is no need for these "
"schema-conformant objects. If you still need to use them, it could be because "
"you are using a BackendV1, which is also deprecated in favor of BackendV2.",
DeprecationWarning,
stacklevel=2,
)
return getattr(importlib.import_module(module_name), name)
raise AttributeError(f"module 'qiskit.providers.models' has no attribute '{name}'")

0 comments on commit 336aed1

Please sign in to comment.