GradientNormPanel#

class lumopt2.utils.panels.GradientNormPanel(title: str | None = 'Gradient Norm', auto_log: bool = True, color: str = 'C3', marker: str = 's', linewidth: float = 2.0, markersize: float = 4.0)#

Live plot of the gradient L2 norm vs. iteration.

Renders a single line that auto-switches to a logarithmic y-axis once every observed gradient norm is strictly positive (the typical case for converging runs). Iterations without gradient data appear as nan and matplotlib draws gaps for them, so the panel works transparently for gradient-free optimizers - it simply re-titles itself to '<title> (N/A)' until a gradient shows up.

Attributes:
titlestr, optional

Panel title (default: 'Gradient Norm').

auto_logbool, optional

If True, switch to a logarithmic y-axis whenever every non-NaN gradient norm is strictly positive. Set to False to force a linear scale (default: True).

colorstr, optional

Matplotlib color spec for the trace (default: 'C3').

markerstr, optional

Matplotlib marker for the trace (default: 's').

linewidthfloat, optional

Line width for the trace (default: 2.0).

markersizefloat, optional

Marker size for the trace (default: 4.0).

Methods

GradientNormPanel.on_optimization_end(ax, ...)

Optional hook called once when the optimization completes.

GradientNormPanel.setup(ax, fig, project)

Create the persistent gradient-norm line on ax.

GradientNormPanel.update(ax, fig, project, state)

Push the latest gradient-norm history into the persistent line.

Attributes