-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Wrap qiskit.Aer and qiskit.IBMQ with lazy loading object #5619
Conversation
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
42a48fa
to
a77faa3
Compare
I thought these preloading of modules was to be removed. Are these to be removed later? |
My thinking was that this is a prerequisite for a deprecation and eventual removal of the attributes (it will probably be a long deprecation because these are widely used today). This gives us a place to raise a deprecation warnings (which wouldn't be an option otherwise while we still support py3.6) in the future while also fixing a potential import cycle today so we can move forward on removing the namespace packages.. |
Great. Tired of getting aer warnings when Aer doesn't even build on the platform. |
Ugh, this is failing the tutorials because ignis is using |
Actually now I'm not sure what's going on. That line is wrong (per the upgrade notes) but it's not clear why it's using BasicAer (which is what I'm assuming is the cause of the timeouts) there. Aer is installed in the tutorial job and |
In Qiskit/qiskit#5619 how the qiskit.Aer provider gets loaded will be changing and it will always be present, not just when Aer is installed. In the topological codes fitters it was checking for the presence of Aer using qiskit.Aer which won't continue to work moving forward. To avoid this potential issue (and potentially unblock Qiskit/qiskit#5619) this commit switches to using 'from qiskit.providers.aer import Aer' instead which lives in the qiskit-aer project itself and will always import error if aer isn't installed.
In Qiskit/qiskit#5619 how the qiskit.Aer provider gets loaded will be changing and it will always be present, not just when Aer is installed. In the topological codes fitters it was checking for the presence of Aer using qiskit.Aer which won't continue to work moving forward. To avoid this potential issue (and potentially unblock Qiskit/qiskit#5619) this commit switches to using 'from qiskit.providers.aer import Aer' instead which lives in the qiskit-aer project itself and will always import error if aer isn't installed.
This reverts commit ac9611c.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, one comment on the release note.
In Qiskit#5582 we added a script that is used to ensure we don't import slow optional dependencies in the default 'import qiskit' path. Since that PR merged we've managed to remove a few more packages from the default import path (see Qiskit#5619, Qiskit#5485, and Qiskit#5620) which we should add the same checks to to ensure we don't regress and accidently start importing them again in the default path. This commit adds all these packages to the list of imports not allowed as part of 'import qiskit'.
In #5582 we added a script that is used to ensure we don't import slow optional dependencies in the default 'import qiskit' path. Since that PR merged we've managed to remove a few more packages from the default import path (see #5619, #5485, and #5620) which we should add the same checks to to ensure we don't regress and accidently start importing them again in the default path. This commit adds all these packages to the list of imports not allowed as part of 'import qiskit'.
In Qiskit/qiskit#5619 how the qiskit.Aer provider gets loaded will be changing and it will always be present, not just when Aer is installed. In the topological codes fitters it was checking for the presence of Aer using qiskit.Aer which won't continue to work moving forward. To avoid this potential issue (and potentially unblock Qiskit/qiskit#5619) this commit switches to using 'from qiskit.providers.aer import Aer' instead which lives in the qiskit-aer project itself and will always import error if aer isn't installed. (cherry picked from commit 2e3298f)
* 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 * 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
…it#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 Qiskit/qiskit#5089, Qiskit/qiskit#4767, and Qiskit/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/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/qiskit#5532 * Fix lint * Fix test lint * DNM: test with ignis patch * Revert "DNM: test with ignis patch" This reverts commit ac9611c3ace30d101a70bda06e1987df14662182. * Use ignis from source for tutorial job * Update release note to be more clear
Summary
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.
Details and comments
Fixes #5532