pytams.diagnostic

Diagnostic class for pyTAMS.

Classes

DiagnosticPlugin

A base class for diagnostic plugins.

ScoreThresholdDiagnostic

Triggers when the score function crosses pre-defined levels.

DiagnosticAnalyst

A class to handle analysing diagnostic statistics.

Functions

diagnosticfactory(→ list[DiagnosticPlugin])

Parse input parameters to generate a list of DiagnosticPlugin.

Module Contents

class DiagnosticPlugin(dlabel: str, params: dict[Any, Any], tid: int, weight: float, workdir: pathlib.Path, fprocess: collections.abc.Callable[Ellipsis, Any], ddb: pytams.diagdb.DiagDB)[source]

A base class for diagnostic plugins.

Plugins are attached to the trajectory objects.

Variables:
  • _label – the diagnostic label

  • _tid – the ID of the trajectory the plugin is attached to

  • _weight – the weight of the trajectory

abstractmethod get_crossed_levels(new_snapshot: pytams.snapshot.Snapshot) list[float][source]

Test to know if diagnostic is needed.

update(old_snapshot: pytams.snapshot.Snapshot, new_snapshot: pytams.snapshot.Snapshot) None[source]

Standard entry point called after every MCMC step.

class ScoreThresholdDiagnostic(dlabel: str, params: dict[Any, Any], tid: int, tweight: float, workdir: pathlib.Path, fprocess: collections.abc.Callable[Ellipsis, Any], ddb: pytams.diagdb.DiagDB)[source]

Bases: DiagnosticPlugin

Triggers when the score function crosses pre-defined levels.

get_crossed_levels(new_snapshot: pytams.snapshot.Snapshot) list[float][source]

Get the list of level crossed during last step.

Parameters:

new_snapshot – the new (end of the time step) snapshot

Returns:

the list of score levels crossed

diagnosticfactory(params: dict[Any, Any], tid: int, tweight: float, workdir: pathlib.Path, fprocess: collections.abc.Callable[Ellipsis, Any], ddb: pytams.diagdb.DiagDB) list[DiagnosticPlugin][source]

Parse input parameters to generate a list of DiagnosticPlugin.

Parameters:
  • params – the input parameters

  • tid – the ID of the traj the diagnostic is attached to

  • tweight – the weight of the traj

  • workdir – the workdir associated with a trajectory

  • fprocess – the forward model diagnostic function

  • ddb – the diagnostic database to add the data to

class DiagnosticAnalyst(db_path: str)[source]

A class to handle analysing diagnostic statistics.

Let’s keep the analysis logic separated from the gathering logic. This class retrieves data from the diagnostic database and perform some computation (mostly conditional statistics on score iso-levels).

db[source]
get_diagnostic_data(label: str) dict[float, list[tuple[Any, float]]][source]

A user-facing access to the diag DB.

An alias to the DB access for the analyst.

Returns:

A dictionary mapping each score iso-level (float) to a list of tuples. Each tuple contains (unpickled_data, trajectory_weight).

compute_weighted_stats(label: str) dict[float, dict[str, Any]][source]

Aggregate data and compute mean/variance per level.