AdaptationLogger

class jaxrens.io.adaptation_log.AdaptationLogger(path, move_names, n_runs, mode='w', restart_iteration=0)[source]

Bases: BufferedH5Logger

Append-only HDF5 writer for per-iteration per-move step sizes and rates.

Buffers writes in memory and flushes to HDF5 every _FLUSH_INTERVAL entries (and on close()). The file is only created when the first write_entry call arrives, so runs without adaptation never produce an empty artefact.

Parameters:
  • path (Path | str) – Destination file path (.adaptation.h5).

  • move_names (list[str]) – Ordered list of move names.

  • n_runs (int) – Number of parallel NS runs (use 1 for single-run).

  • mode (str)

  • restart_iteration (int)

write_entry(iteration, step_sizes, acceptance_rates, adjustment_stats=None, n_evaluations=None, n_grad_evaluations=None)[source]

Buffer one entry. Auto-flushes every _FLUSH_INTERVAL entries.

Parameters:
  • iteration (int) – NS iteration index (Python int).

  • step_sizes (ndarray) – shape (n_runs, n_moves) or (n_moves,) for n_runs=1.

  • acceptance_rates (ndarray) – same shape rules as step_sizes.

  • adjustment_stats (dict[str, ndarray] | None) – optional dict of per-adjust-call diagnostics. Keys: “n_rounds”, “converged”, “cap_hits”, “floor_hits”, “bracket_detected” (all shape (n_runs, n_moves) or (n_moves,)), “reject_reason_counts” (shape (n_runs, n_moves, 4) or (n_moves, 4)). If None, no adjustment_stats group is written (v1 behaviour).

  • n_evaluations (ndarray | None) – optional shape (n_runs, n_moves) or (n_moves,) int64. Total backend calls per iter per move. When provided (together with n_grad_evaluations), schema v3 datasets are written.

  • n_grad_evaluations (ndarray | None) – optional, same shape as n_evaluations. Subset that used value_and_grad.

Return type:

None

close()[source]

Flush remaining buffer and close the logger.

If no entries were ever written, no file is created.

Return type:

None

static read(path)[source]

Load an .adaptation.h5 file into an AdaptationLog dataclass.

Supports schema v1 (no adjustment_stats), v2 (with adjustment_stats/ group), and v3 (v2 plus n_evaluations / n_grad_evaluations datasets). Legacy v1/v2 files produce n_evaluations=None and n_grad_evaluations=None.

Parameters:

path (Path | str) – Path to the HDF5 file.

Returns:

Populated AdaptationLog.

Return type:

AdaptationLog