-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
What is the expected enhancement?
IMPORT SPEED of top-level qiskit/__init__.py
Inspired by @mtreinish in #4958 .
Currently, it takes on the order of seconds to import just the base qiskit package, and that doesn't improve if you only import subpackages (e.g. qiskit.pulse) due to the top-level import of heavy packages in ./qiskit/__init__.py, e.g. qiskit.providers.ibmq which are always imported.
Here, I am mostly looking in this issue at import speed improvements in qiskit/__init__.py.
Possible Import Improvements
I see a few possible solutions, ranked in order of more breaking changes:
- (low-hanging fruit): defer
matplotlib.animationimport inqiskit.visualization.transition_visualizationto the animation function - (low-hanging fruit): defer
networkximport inqiskit.circuit.equivalenceto thedraw()and_build_basis_graph()(only used indraw()) functions so this isn't on the critical path every import. - Add an environment variable on the Aer & IBMQ provider imports to optionally disable them
- Add an environment variable on the
qiskit.circuitimports to optionally disable them. (e.g.QISKIT_DONT_IMPORT_TOP_LEVEL)
Import Time visualization
This can be checked visually with:
pip install tuna
pip install qiskit-terra qiskit-ibmq-provider
python -X importtime -c "import qiskit.pulse" 2> import_pulse.log
tuna import_pulse.logWhich yields (qiskit-terra==0.15.1, qiskit-ibmq-provider==0.8.0):
which is similar to that in #4958 (I must have a slower computer/not be running on SSD):
We see that import qiskit.pulse ends up importing the top-level qiskit init file anyways. As a side note, I'd really prefer not to spend ~3 seconds importing qiskit-terra every time.