accelmo.tracking.uncertainty¶
Stopping the training workers and folding their uncertainty parts into (A, B).
- class accelmo.tracking.uncertainty.UncertaintyPart(normal, reading_ids, sensitivities, variances)[source]¶
Bases:
objectOne worker’s contribution to the propagated knob covariance.
normalisΣ w J Jᵀ. Each rowrofsensitivitiesis the change in that worker’s gradient per unit noise on readingreading_ids[r](an observation, a start coordinate, or both), withvariances[r]its declared variance.- Parameters:
normal (numpy.ndarray)
reading_ids (numpy.ndarray)
sensitivities (numpy.ndarray)
variances (numpy.ndarray)
- normal: ndarray¶
- reading_ids: ndarray¶
- sensitivities: ndarray¶
- variances: ndarray¶
- accelmo.tracking.uncertainty.merge_uncertainty_parts(parts, n_knobs)[source]¶
Sum the normal matrices and merge rows that share a reading id.
G_eadds every part’s sensitivity to readinge(shared between workers, or used as both an observation and a start), sonoise_matrix()counts its noise once. Merging a merged part with further parts gives the same result.- Return type:
- Parameters:
parts (list[UncertaintyPart])
n_knobs (int)
- accelmo.tracking.uncertainty.eliminate_fitted_starts(normal, start, start_start)[source]¶
Schur complement of the fitted starts:
(A_kk - Σ_p P_p A_sk,p, P).normalis the knob blockA_kksummed over particles;start(particles, 4, knobs)andstart_start(particles, 4, 4)are each particle’s fullA_skandA_ss. The projectionP = A_ks A_ss⁻¹(particles, knobs, 4)takes a Jacobian toJ - P ∂m/∂c0.- Return type:
tuple[ndarray,ndarray]- Parameters:
normal (numpy.ndarray)
start (numpy.ndarray)
start_start (numpy.ndarray)
- accelmo.tracking.uncertainty.noise_matrix(part)[source]¶
B = Σ_e σ_e² G_e G_eᵀfor a merged part; readings without a finite variance add nothing.- Return type:
ndarray- Parameters:
part (UncertaintyPart)
- accelmo.tracking.uncertainty.second_order_bytes(n_params, batch_size)[source]¶
Upper estimate of one MAD-NG process holding
batch_sizeorder-2 maps inn_paramsknobs.One TPSA has a coefficient per monomial of order <= 2 in 6 variables and
n_paramsparameters.- Return type:
float- Parameters:
n_params (int)
batch_size (int)
- accelmo.tracking.uncertainty.second_order_blocker(pool, n_params, num_batches)[source]¶
Why the true Hessian cannot run, or
Nonewhen one worker’s second-order maps fit.n_paramsis the number of MAD-NG parameters (magnet knobs; gains live in Python). The check runs with the workers up, so the free memory already excludes their first-order footprint.- Return type:
str|None- Parameters:
pool (WorkerPool)
n_params (int)
num_batches (int)
- class accelmo.tracking.uncertainty.UncertaintyCollection(matrices=dict(), skipped=dict(), seconds=0.0)[source]¶
Bases:
objectWhat the uncertainty stage returned.
matricesmaps each Hessian that ran to its normal matrixAand noise matrixB;skippedmaps each requested Hessian that did not run to the reason;secondsis the stage’s wall time.- Parameters:
matrices (dict[str, tuple[numpy.ndarray, numpy.ndarray]])
skipped (dict[str, str])
seconds (float)
- matrices: dict[str, tuple[ndarray, ndarray]]¶
- skipped: dict[str, str]¶
- seconds: float = 0.0¶
- property primary: tuple[ndarray, ndarray]¶
(A, B)of the first Hessian that ran.
- class accelmo.tracking.uncertainty.StageProgress(total, on_update=None, interval=PROGRESS_SECONDS)[source]¶
Bases:
objectCounts finished batches of the second-order pass, logging elapsed time and an ETA.
on_update(done, total, elapsed, eta)is called at most everyintervalseconds and at the end, for the run log;etaisNoneuntil the first batch is done.- Parameters:
total (int)
on_update (Callable[[int, int, float, float | None], None] | None)
interval (float)
- advance(_message=None)[source]¶
One more batch done.
- Return type:
None- Parameters:
_message (UncertaintyProgress | None)
- accelmo.tracking.uncertainty.drain_uncertainty(pool, n_knobs, hessians, second_order_batches=None, progress=None)[source]¶
Stop
poolin memory-bounded chunks; return each Hessian’s normal matrixAand noiseB.Feed each pair to
sandwich_uncertainties(). Reading ids are file-scoped, so once every worker of a file has reported, that file’s merged readings become itsBcontribution and are dropped. Workers are drained in file order, so besides the chunk being received at most one partly merged file is held. Nohessiansstops the workers without computing anything.- Return type:
dict[str,tuple[ndarray,ndarray]]- Parameters:
pool (WorkerPool[TrackingWorkerConfig])
n_knobs (int)
hessians (tuple[str, ...])
second_order_batches (int | None)
progress (StageProgress | None)