Skip to content

Eager matplotlib.pyplot imports defeat lazy-import design: every startup loads matplotlib #328

Description

@stanlrt

From /simplify codebase sweep (2026-06-10).

These modules lazy-import torch via lazy_import but import matplotlib.pyplot eagerly:

  • metrics/factory.py:9, metrics/visualizers.py:6 (pulled eagerly by metrics/__init__.py:53,61)
  • transparency/report.py:17, transparency/results.py:11
  • robustness/report.py:15, robustness/results.py:11
  • transparency/visualisers/base_visualiser.py:9

Because pipeline/phases/registry.py:25-28 imports all three phase modules, ANY import of the orchestrator (every CLI run, every raitap.run(), even from raitap.metrics import metrics_prediction_pair in the robustness/transparency phases) loads matplotlib unconditionally.

Cost: ~0.3-1s import time and tens of MB RSS added to every startup, including metrics-only tabular runs and programmatic embedders that disable reporting/visualisation.

Fix: same pattern already used for torch -- plt = lazy_import("matplotlib.pyplot") under the TYPE_CHECKING split, or move plt.close/figure code behind function-local imports. Mechanical, matches the project's existing lazy convention.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions