-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap qiskit.Aer and qiskit.IBMQ with lazy loading object (#5619)
* Wrap qiskit.Aer and qiskit.IBMQ with lazy loading object This commit migrates the qiskit.Aer and qiskit.IBMQ module attributes to be lazy loading instances of lazy loading wrapper classes. The intent here is to avoid importing from qiskit-aer or qiskit-ibmq-provider from qiskit-terra, while this is safe while the packages share a shared namespace we've been actively working to remove the use of namespace packaging (see #5089, #4767, and #559) and the circular dependency caused by re-exporting these attributes is blocking progress on this. By using a lazy loading wrapper class we avoid an import type circular dependency and opportunistically use qiskit-aer and/or qiskit-ibmq-provider at runtime only if they're present after everything is imported. This also may have some benefit for the overall import performance of qiskit (being tracked in #5100) as it removes qiskit-aer and qiskit-ibmq-provider from the import path unless they're being used. Although the presence of qiskit.__qiskit_version__ might prevent any performance improvements as it still imports all the elements to get version information (and will be tackled in a separate PR). Fixes #5532 * Fix lint * Fix test lint * DNM: test with ignis patch * Revert "DNM: test with ignis patch" This reverts commit ac9611c. * Use ignis from source for tutorial job * Update release note to be more clear
- Loading branch information
Showing
8 changed files
with
130 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
releasenotes/notes/lazy-load-provider-factory-bdfb3925a2514ef7.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
upgrade: | ||
- | | ||
The ``qiskit.Aer`` and ``qiskit.IBMQ`` top level attributes are now lazy | ||
loaded. This means that the objects will always now exist and warnings will | ||
no longer be raised on import if ``qiskit-aer`` or ``qiskit-ibmq-provider`` | ||
are not installed (or can't be found by Python). If you were checking for | ||
the presence of ``qiskit-aer`` or ``qiskit-ibmq-provider`` using these | ||
module attributes and explicitly comparing to ``None`` or looking for the | ||
absence of the attribute this no longer will work because they are always | ||
defined as an object now. In other words running something like:: | ||
try: | ||
from qiskit import Aer | ||
except ImportError: | ||
print("Aer not available") | ||
or:: | ||
try: | ||
from qiskit import IBMQ | ||
except ImportError: | ||
print("IBMQ not available") | ||
will no longer work. Instead to determine if those providers are present | ||
you can either explicitly use ``qiskit.providers.aer.Aer`` and | ||
``qiskit.providers.ibmq.IBMQ``:: | ||
try: | ||
from qiskit.providers.aer import Aer | ||
except ImportError: | ||
print("Aer not available") | ||
try: | ||
from qiskit.providers.ibmq import IBMQ | ||
except ImportError: | ||
print("IBMQ not available") | ||
or check ``bool(qiskit.Aer)`` and ``bool(qiskit.IBMQ)`` instead, for | ||
example:: | ||
import qiskit | ||
if not qiskit.Aer: | ||
print("Aer not available") | ||
if not qiskit.IBMQ: | ||
print("IBMQ not available") | ||
This change was necessary to avoid potential import cycle issues between | ||
the qiskit packages and also to improve the import time when Aer or IBMQ | ||
are not being used. | ||
- | | ||
The user config file option ``suppress_packaging_warnings`` option in the | ||
user config file and the ``QISKIT_SUPPRESS_PACKAGING_WARNINGS`` environment | ||
variable no longer has any effect and will be silently ignored. These | ||
warnings have been removed and will no longer be emitted at import time | ||
from the qiskit module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters