forked from Qiskit/qiskit
-
Notifications
You must be signed in to change notification settings - Fork 1
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
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 Qiskit#5089, Qiskit#4767, and Qiskit#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 Qiskit#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 Qiskit#5532
- Loading branch information
Showing
8 changed files
with
90 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
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
--- | ||
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. You can either explicitly use | ||
``qiskit.providers.aer.Aer`` and ``qiskit.providers.ibmq.IBMQ`` or | ||
check ``bool(qiskit.Aer)`` and ``bool(qiskit.IBMQ)`` instead to determine | ||
if those providers are present. 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 is 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
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