-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delay scikit-learn import until first use (#1061)
### Summary This commit pushes the import of scikit-learn lower into the code, so that it does not occur until first usage. ### Details and comments Previously, scikit-learn was in a `try` block which allowed for code that did not use scikit-learn to work fine when it was not installed. However, sometimes scikit-learn can be installed but have errors (like in #1050) which were not caught by the `try` block. Further delaying the import can help in this case. Additionally, scikit-learn is a little bit of a slow import, so not importing it when it is not needed gives a little bit of efficiency (maybe; mostly it imports scipy modules but those might get imported any way by other analysis code). --------- Co-authored-by: Helena Zhang <[email protected]>
- Loading branch information
1 parent
fd9f65e
commit 0a9da6a
Showing
7 changed files
with
240 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
fixes: | ||
- | | ||
The importing of ``scikit-learn`` was moved from module-level imports | ||
inside of ``try`` blocks to dynamic imports at first usage of the | ||
``scikit-learn`` specific feature. This change should avoid errors in the | ||
installation of ``scikit-learn`` from preventing a user using features of | ||
``qiskit-experiments`` that do not require ``scikit-learn``. See `#1050 | ||
<https://github.com/Qiskit/qiskit-experiments/issues/1050>`_. |
Oops, something went wrong.