accelmo.dashboard.fit

The live terminal dashboard of a gradient-descent fit.

accelmo.dashboard.fit.LEFT_WIDTH_FRACTION = 0.66

Share of the terminal width the progress panel takes.

accelmo.dashboard.fit.SHORT_FIT_STEPS = 30

Fits shorter than this many steps get a smaller plot.

accelmo.dashboard.fit.REFRESH_PER_SECOND = 1

Redraws per second, so the resource line moves during a long step.

accelmo.dashboard.fit.ETA_WINDOW = 10

Epochs averaged for the epoch time and ETA.

accelmo.dashboard.fit.STALL_EPOCHS = 10

Epochs without a new best before the status turns “stalled”.

accelmo.dashboard.fit.DIVERGENCE_FACTOR = 10.0

A loss this many times the best one is flagged as diverging.

accelmo.dashboard.fit.MOVED_SIGMAS = 1.0

A knob counts as moved when it is this many prior widths from its start.

accelmo.dashboard.fit.FACTOR_BELOW_RATIO = 0.01

A reduction of the loss beyond this is printed as a factor, not a percentage.

accelmo.dashboard.fit.PHASES = ('data', 'model', 'workers', 'fit', 'uncertainty')

The stages of a run, in order; the strip at the top shows each one’s state.

accelmo.dashboard.fit.format_duration(seconds)[source]

73 -> 1m13s; 4000 -> 1h06m.

Return type:

str

Parameters:

seconds (float)

accelmo.dashboard.fit.format_change(first, best)[source]

How far best is below first: a percentage, or a factor when it is large.

Return type:

Text

Parameters:
  • first (float)

  • best (float)

class accelmo.dashboard.fit.Best(epoch, chi2, validation, true_diff, knobs)[source]

Bases: object

The best epoch so far.

Parameters:
  • epoch (int)

  • chi2 (float)

  • validation (float | None)

  • true_diff (float | None)

  • knobs (dict[str, float])

epoch: int
chi2: float
validation: float | None
true_diff: float | None
knobs: dict[str, float]
class accelmo.dashboard.fit.PhaseState(status='pending', detail='', started=0.0, seconds=0.0, skipped=False)[source]

Bases: object

One stage of the run: whether it has started or finished, and how long it took.

Parameters:
  • status (str)

  • detail (str)

  • started (float)

  • seconds (float)

  • skipped (bool)

status: str = 'pending'
detail: str = ''
started: float = 0.0
seconds: float = 0.0
skipped: bool = False
class accelmo.dashboard.fit.FitDashboard(title, *, console=None, enabled=True)[source]

Bases: object

The live terminal view of a fit: a strip of stages, progress, loss history and best-so-far.

Does nothing when the output is not a terminal; the run log has the numbers then. The display starts at the first phase() (or on entering the with block) and stays on screen after close(). Mark each stage of the run with phase(), state what the run is made of with fact(), call begin_fit() before the epoch loop and update() after every epoch.

Parameters:
  • title (str)

  • console (Console | None)

  • enabled (bool)

facts: dict[str, str]
run_log_path: Path | None
start_knobs: dict[str, float]
sigmas: dict[str, float]
gain_names: list[str]
stage_epochs: int | None
chi2: list[float]
validation: list[float | None]
epoch_times: list[float]
best: Best | None
stop_reason: str | None
begin_fit(*, max_epochs, n_points, n_params, start_knobs, knob_sigmas, gain_names=(), stage_epochs=None, loss_is_total=False, unit='epoch', rate_name='lr')[source]

Start the fit stage.

n_points and n_params give the degrees of freedom of the reduced chi-square (loss is chi-square per point); n_points=None shows the total chi-square. knob_sigmas are the prior widths of the magnet knobs, start_knobs their starting values, gain_names the BPM gains. With loss_is_total the loss given to update() is the chi-square itself, not per point. unit names a step (epoch, iter) and rate_name the step-size parameter shown beside the gradient (lr, λ).

Return type:

None

Parameters:
  • max_epochs (int)

  • n_points (int | None)

  • n_params (int)

  • start_knobs (Mapping[str, float])

  • knob_sigmas (Mapping[str, float])

  • gain_names (Sequence[str])

  • stage_epochs (int | None)

  • loss_is_total (bool)

  • unit (str)

  • rate_name (str)

fact(label, value)[source]

Show label: value in the run panel.

Return type:

None

Parameters:
  • label (str)

  • value (object)

skip(name)[source]

Hide stage name: this run does not have it.

Return type:

None

Parameters:

name (str)

set_detail(name, detail)[source]

Text shown after stage name in the strip.

Return type:

None

Parameters:
  • name (str)

  • detail (str)

phase(name)[source]

Mark stage name running for the duration of the block, then done (or failed).

Return type:

Iterator[None]

Parameters:

name (str)

uncertainty_progress(done, total, eta)[source]

Show how far the uncertainty stage has got.

Return type:

None

Parameters:
  • done (int)

  • total (int)

  • eta (float | None)

close()[source]

Stop redrawing; the last frame stays on screen.

Return type:

None

finish(reason)[source]

The fit stage is over: show why the loop ended.

Return type:

None

Parameters:

reason (str)

update(*, epoch, loss, validation_loss, grad_norm, lr, epoch_time, true_diff, knobs, new_best, note=None)[source]

Record one finished epoch and redraw.

Return type:

None

Parameters:
  • epoch (int)

  • loss (float)

  • validation_loss (float | None)

  • grad_norm (float)

  • lr (float)

  • epoch_time (float)

  • true_diff (float | None)

  • knobs (Mapping[str, float])

  • new_best (bool)

  • note (str | None)

rejected(*, epoch, loss, grad_norm, lr, epoch_time)[source]

Record a step the optimiser turned down (loss is NaN when the orbit was lost).

Return type:

None

Parameters:
  • epoch (int)

  • loss (float)

  • grad_norm (float)

  • lr (float)

  • epoch_time (float)