nlsq.diagnostics.DiagnosticPlugin

class nlsq.diagnostics.DiagnosticPlugin(*args, **kwargs)

Bases: Protocol

Protocol for diagnostic plugins.

Users implement this protocol to create custom diagnostics that integrate with NLSQ’s health report system.

name

Unique plugin name. Should be a short, descriptive identifier. Convention: lowercase with hyphens (e.g., “optical-scattering”).

Type:

str

Protocol
--------
analyze(jacobian, parameters, residuals, \*\*context)

Run the plugin’s analysis and return results.

Example

>>> class OpticalScatteringPlugin:
...     @property
...     def name(self) -> str:
...         return "optical-scattering"
...
...     def analyze(
...         self,
...         jacobian: np.ndarray,
...         parameters: np.ndarray,
...         residuals: np.ndarray,
...         **context
...     ) -> PluginResult:
...         issues = []
...         # Domain-specific analysis...
...         if any(parameters < 0):
...             issues.append(ModelHealthIssue(...))
...         return PluginResult(
...             plugin_name=self.name,
...             data={"my_metric": value},
...             issues=issues,
...         )
...
>>> # Register the plugin
>>> PluginRegistry.register(OpticalScatteringPlugin())
__init__(*args, **kwargs)
analyze(jacobian, parameters, residuals, **context)

Run plugin analysis.

Parameters:
  • jacobian (np.ndarray) – Jacobian matrix at solution (n_residuals x n_params).

  • parameters (np.ndarray) – Fitted parameters.

  • residuals (np.ndarray) – Residuals at solution.

  • **context (Any) – Additional context passed from curve_fit: - xdata: Independent variable data - ydata: Dependent variable data - bounds: Parameter bounds - model: Model function - config: DiagnosticsConfig

Returns:

Analysis results with any detected issues.

Return type:

PluginResult

property name: str

Unique plugin name.

Should be a short, descriptive identifier. Convention: lowercase with hyphens (e.g., “optical-scattering”).

Returns:

The plugin’s unique name.

Return type:

str