Skip to content

Lazy imports#36

Merged
dihm merged 6 commits into
mainfrom
lazy_imports
Aug 18, 2025
Merged

Lazy imports#36
dihm merged 6 commits into
mainfrom
lazy_imports

Conversation

@dihm
Copy link
Copy Markdown
Contributor

@dihm dihm commented Aug 15, 2025

This PR implements lazy imports for leveldiagram and arc, which improves import time of rydiqule by about a second (2.8s to 1.8s). Note that leveldiagram will be imported at the first call of draw_diagram and arc is imported at the first instantiation of a Cell, so the extra import times will show up at that point.

While mostly alleviating a personal pet-peeve, these changes lay the ground work for allowing ARC to be an optional dependency, since it is only required for Cell and particularly for modeling Rydberg atoms. Nominally rydiqule has a wider purview, so making ARC officially optional at some future point may be desireable.

dihm added 4 commits August 7, 2025 21:42
Prevents one reason for matplotlib from being imported at rq import
This, with other tweaks, removes arc and matplotlib from rq import
unless asked for by the user (ie `draw_diagram` or `Cell` used).

Works, but is a bit ugly. Reduces `rq` import from 2.8s to 1.5s.
@dihm dihm requested a review from benjamin-n-miller August 15, 2025 02:47
@dihm dihm self-assigned this Aug 15, 2025
@dihm dihm added the enhancement New feature or request label Aug 15, 2025
@dihm
Copy link
Copy Markdown
Contributor Author

dihm commented Aug 18, 2025

For posterity sake, here are the import timings before and after lazy implementation. Note that these are with numpy 2. Numpy 1 imports are a fair bit slower overall.

Before:
rq_main_np2

After:
rq_lazy_np2

@dihm dihm merged commit 59d7fe3 into main Aug 18, 2025
5 checks passed
@dihm dihm deleted the lazy_imports branch August 18, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant