perf: defer matplotlib imports and lazy-load plot submodule#427
Merged
perf: defer matplotlib imports and lazy-load plot submodule#427
Conversation
Replace module-level matplotlib imports with autoarray.plot.utils wrappers across all plot files. Update plot_utils imports to use the new autogalaxy.util.plot_utils path. Lazy-load the plot submodule via __getattr__ in autolens/__init__, deferring matplotlib import cost to first plot access. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace module-level
import matplotlib.pyplot as pltwithsubplots()wrappers fromautoarray.plot.utilsacross all plot files. Updateplot_utilsimports to use the newautogalaxy.util.plot_utilspath. Lazy-load the plot submodule via__getattr__inautolens/__init__.Combined with scipy deferral (PyAutoArray#259, PyAutoFit#1186) and matplotlib deferral (PyAutoGalaxy#330), total
import autolenstime drops from ~2.7s to ~1.9s (30% reduction).Part of #426. Depends on PyAutoLabs/PyAutoArray#259, PyAutoLabs/PyAutoGalaxy#330.
API Changes
None — internal changes only.
Test Plan
pytest test_autolens/ -x— 245 passed/smoke-testFull API Changes (for automation & release notes)
Internal
import matplotlib.pyplot as pltremoved from plot files, replaced withsubplotsfromautoarray.plot.utilsfrom autogalaxy.plot.plot_utilsimports updated tofrom autogalaxy.util.plot_utilsautolens.plotsubmodule lazy-loaded via__getattr__inautolens/__init__🤖 Generated with Claude Code