lyopronto/high_level.py imports matplotlib at module scope:
import matplotlib.pyplot as plt
from matplotlib import rc as matplotlibrc
lyopronto/__init__.py imports high_level, so every import lyopronto initializes matplotlib and its backend — including for callers that only run simulations and never plot. On this machine:
>>> import lyopronto, sys
>>> any(m.startswith("matplotlib") for m in sys.modules)
True
matplotlib is only used by generate_visualizations and the four _plot_* helpers. Nothing else in the package touches it.
This costs import time for every consumer, and it makes matplotlib a hard import-time dependency for headless use (batch simulation, CI, a server-side API) where a missing or misconfigured backend then fails at import rather than at the point of use.
Suggested fix — load it in generate_visualizations, which is the only public entry point that plots, and pass plt to the private helpers rather than relying on a module global. After that change, import lyopronto reports matplotlib loaded: False.
Happy to open a PR; I have the change prepared against 4fb63df.
Found while working on SECQUOIA/LyoPRONTO, which carries this change.
lyopronto/high_level.pyimports matplotlib at module scope:lyopronto/__init__.pyimportshigh_level, so everyimport lyoprontoinitializes matplotlib and its backend — including for callers that only run simulations and never plot. On this machine:matplotlib is only used by
generate_visualizationsand the four_plot_*helpers. Nothing else in the package touches it.This costs import time for every consumer, and it makes matplotlib a hard import-time dependency for headless use (batch simulation, CI, a server-side API) where a missing or misconfigured backend then fails at import rather than at the point of use.
Suggested fix — load it in
generate_visualizations, which is the only public entry point that plots, and passpltto the private helpers rather than relying on a module global. After that change,import lyoprontoreportsmatplotlib loaded: False.Happy to open a PR; I have the change prepared against
4fb63df.Found while working on SECQUOIA/LyoPRONTO, which carries this change.