MonitorCollection¶
- class jaxrens.postprocess.collection.MonitorCollection(monitors)[source]¶
Bases:
objectAggregate multiple Monitor objects (e.g. a pressure sweep cohort).
- classmethod from_directories(paths, labels=None, *, prefix='ns')[source]¶
Build a collection by loading one Monitor per directory.
- classmethod from_multi_run_directory(path, *, prefix=None, prefer_final=True, labels=None, config=None)[source]¶
Build a collection from a single multi-run output directory.
Multi-run NS (
run_ns_parallel/run_ns_multi_gpu) writes one combined checkpoint with leading batch shape(n_runs,)or(G, P)plus per-replica<prefix>.runNN.energiesfiles. This constructor flattens the leading batch axes, reads each per-replica energy log, and produces oneMonitorper replica.Convention: stored energies are treated as the full thermal variable (
dead_volumes = live_volumes = None). When the run used anEnsembleTerm, the stored energy is the NPT enthalpyH = U + P*V, so leaving volumesNoneyieldslog Z_NPT/Cp/ GibbsGdirectly from the standard thermodynamics functions (passing the bare cell volume column would double-count theP*Vterm). The bare cell-volume column from each.energieslog is stashed on each Monitor asvolume_traceso callers can compute<V>(T)separately.For single-run checkpoints (no batch axis) this builds a one-element collection using the same convention as the multi-run path (reading the
<prefix>.energieslog,dead_volumes=None, bare volume stashed asvolume_trace) rather than delegating toMonitor.from_directory, so single- and multi-replica collections behave identically.Config auto-discovery: when
configisNonethe constructor looks forconfig.yamlinpathand then inpath.parent(the standardexperiment_dir/output/layout). A found config supplies the run prefix (output.out_file_prefix) and — for an NPT pressure sweep whose pressure-list length matches the replica count — per-replica labels andpressure_gpa/pressure_eva3attributes attached to each Monitor. Passprefix=/labels=explicitly to override the inferred values, or hand a specific path viaconfig=to skip auto-discovery. When no config is found we fall back toprefix='ns'andrunNNlabels.- Parameters:
path (Path | str) – Directory produced by
jaxrens runon a multi-run config.prefix (str | None) – File prefix matching
output.out_file_prefix. IfNone(default), inferred from the config when present; otherwise falls back to"ns".prefer_final (bool) – Prefer
<prefix>.final.checkpoint.h5over the periodic<prefix>.checkpoint.h5; falls back further to<prefix>.initial.checkpoint.h5when the run is still in flight. Zero-byte files (mid-write) are skipped.labels (list[str] | None) – Per-replica display labels, length
n_total. IfNone, inferred from the config (e.g. NPT pressures); otherwise falls back tof"run{i:02d}".config (Path | str | None) – Explicit path to the run’s YAML config. When
None, auto-discovery looks inpaththenpath.parent.
- Returns:
Populated
MonitorCollection.- Raises:
FileNotFoundError – If no usable checkpoint is found, or if any
<prefix>.runNN.energiesfile is missing.ValueError – If
labelsis supplied with the wrong length, or if the checkpoint’s leading batch shape is unrecognised.
- Return type:
- add(monitor)[source]¶
Append a Monitor to the collection.
- Parameters:
monitor (Monitor) – Monitor to add.
- Return type:
None
- plot_energy_trace(*, ax=None, **kwargs)[source]¶
Overlay energy traces for all monitors on a single axes.
- Parameters:
ax – Existing axes. Created if None.
**kwargs – Forwarded to each
plot_energy_tracecall.
- Returns:
The Axes object.
- plot_heat_capacity(T, *, ax=None, **kwargs)[source]¶
Overlay C_v curves for all monitors.
- Parameters:
T (ndarray) – Temperature array.
ax – Existing axes. Created if None.
**kwargs – Forwarded to each
plot_heat_capacitycall.
- Returns:
The Axes object.
- plot_partition_function(T, *, ax=None, **kwargs)[source]¶
Overlay log Z curves for all monitors.
- Parameters:
T (ndarray) – Temperature array.
ax – Existing axes. Created if None.
**kwargs – Forwarded to each
plot_partition_functioncall.
- Returns:
The Axes object.
- plot_free_energy(T, *, ax=None, **kwargs)[source]¶
Overlay free energy curves for all monitors.
- Parameters:
T (ndarray) – Temperature array.
ax – Existing axes. Created if None.
**kwargs – Forwarded to each
plot_free_energycall.
- Returns:
The Axes object.
- plot_log_evidence_trace(*, ax=None, **kwargs)[source]¶
Overlay cumulative log Z traces for all monitors.
- Parameters:
ax – Existing axes. Created if None.
**kwargs – Forwarded to each
plot_log_evidence_tracecall.
- Returns:
The Axes object.
- plot_step_sizes(*, ax=None, per_run=False, **kwargs)[source]¶
Plot per-move step-size adaptation trace for the cohort.
Uses the collection-level
self.adaptation_tracepopulated byfrom_multi_run_directory(one shared.adaptation.h5for the whole cohort, indexed along ann_runsaxis). Falls back to per-monitor traces when the cohort-level trace is unavailable (e.g. collections built viafrom_directories).- Parameters:
ax – Existing axes. Created if None.
per_run (bool) – When True, draws one line per (move, replica) combination; when False, draws mean ± std across replicas.
**kwargs – Forwarded to the underlying plotting function.
- Returns:
The Axes object.
- plot_heatmap(T, observable='heat_capacity', *, ax=None, cmap='viridis', fmt='PT', vmin=None, vmax=None, do_colorbar=True, cbar_label=None, T_label='T', P_label=None, pressure_attr='auto', **obs_kwargs)[source]¶
Render a pressure-temperature heatmap of an observable.
Each monitor in the collection contributes one row of the
(n_P, n_T)grid. Pressure values are taken from thepressure_gpaorpressure_eva3attribute set byfrom_multi_run_directorywhen a config is found; when neither is present we fall back to ordinal replica indices (the heatmap then functions purely as a 2D overlay). Monitors are sorted by pressure before plotting sopcolormeshsees a monotonic axis.- Parameters:
T (ndarray) – Temperature grid, shape
(n_T,). Passed to each monitor’s observable method.observable (str | Callable[[...], ndarray]) – One of
"heat_capacity","free_energy","log_partition_function"/"log_Z","volume", or a callable(monitor, T, **obs_kwargs) -> array (n_T,).ax – Existing axes to plot into. Created if None.
cmap (str) – Forwarded to
plot_heatmap().P_labeldefaults to a unit-aware string whenpressure_attris resolved to a named field.fmt (str) – Forwarded to
plot_heatmap().P_labeldefaults to a unit-aware string whenpressure_attris resolved to a named field.vmin (float | None) – Forwarded to
plot_heatmap().P_labeldefaults to a unit-aware string whenpressure_attris resolved to a named field.vmax (float | None) – Forwarded to
plot_heatmap().P_labeldefaults to a unit-aware string whenpressure_attris resolved to a named field.do_colorbar (bool) – Forwarded to
plot_heatmap().P_labeldefaults to a unit-aware string whenpressure_attris resolved to a named field.cbar_label (str | None) – Forwarded to
plot_heatmap().P_labeldefaults to a unit-aware string whenpressure_attris resolved to a named field.T_label (str) – Forwarded to
plot_heatmap().P_labeldefaults to a unit-aware string whenpressure_attris resolved to a named field.P_label (str | None) – Forwarded to
plot_heatmap().P_labeldefaults to a unit-aware string whenpressure_attris resolved to a named field.pressure_attr (str) –
"auto"(default) preferspressure_gpathenpressure_eva3then ordinal indices; pass an explicit attribute name to force a choice, or"index"for replica indices.**obs_kwargs – Forwarded to the observable function (e.g.
k_B=8.617e-5).
- Returns:
The Axes object.
- plot_acceptance_rates(*, ax=None, per_run=False, **kwargs)[source]¶
Plot per-move acceptance-rate trace for the cohort.
Uses the cohort-wide
self.adaptation_trace(set byfrom_multi_run_directory) when present, falling back to per-monitor traces otherwise.- Parameters:
ax – Existing axes. Created if None.
per_run (bool) – When True, one line per (move, replica); when False, mean ± std across replicas.
**kwargs – Forwarded to the underlying plotting function.
- Returns:
The Axes object.