Fail gracefully in lobpcg_test if matplotlib isn't installed.

There isn't yet a matplotlib that supports NumPy 2.0, so we need to support running tests without it.

PiperOrigin-RevId: 621228727
This commit is contained in:
Peter Hawkins 2024-04-02 10:47:55 -07:00 committed by jax authors
parent 00489be23d
commit 60458bb36a

View File

@ -288,7 +288,10 @@ class LobpcgTest(jtu.JaxTestCase):
# We import matplotlib lazily because (a) it's faster this way, and
# (b) concurrent imports of matplotlib appear to trigger some sort of
# collision on the matplotlib cache lock on Windows.
from matplotlib import pyplot as plt
try:
from matplotlib import pyplot as plt
except (ModuleNotFoundError, ImportError):
return # If matplotlib isn't available, don't emit plots.
os.makedirs(lobpcg_debug_plot_dir, exist_ok=True)
clean_matrix_name = _clean_matrix_name(matrix_name)