sequince.steps.mutation.metrics.base#

Metric interfaces and collection lifecycle.

Classes#

MutationMetric

Static metric configuration with explicit, fixed-structure pytree state.

MutationMetrics

Static metric collection with pure operations on MutationStepState.

Module Contents#

class sequince.steps.mutation.metrics.base.MutationMetric[source]#

Bases: Protocol

Static metric configuration with explicit, fixed-structure pytree state.

update must be pure: (old state, transition) -> new state. Never mutate Python attributes or input arrays. Arrays, tuples, dictionaries and registered pytree dataclasses are all valid states. Shapes and dtypes must remain fixed under JIT. accepted is a per-particle boolean mask.

An optional prepare(state, particles, context) method prepares existing state for the next mutation segment, preserving accumulated measurements. It must return state without mutating its input; absent means no-op.

Every update accepts the keyword-only transition argument. Metrics needing displacement and kernel auxiliary declare needs_transition = True; otherwise mutations may omit this work and pass None. The flag is optional and defaults to False. Auxiliary data remains opaque to the collection.

property name: str#
Return type:

str

initialize(particles, log_weights, context)[source]#
Parameters:
Return type:

Any

update(state, particles, accepted, context, *, transition=None)[source]#
Parameters:
Return type:

Any

result(state, context)[source]#
Parameters:
Return type:

Any

class sequince.steps.mutation.metrics.base.MutationMetrics(metrics=())[source]#

Static metric collection with pure operations on MutationStepState.

Initialize once per block, update once per population transition, and compute results only at the complete block boundary. Preparing the next segment preserves accumulated measurements. The collection holds configuration only; runtime state is always returned explicitly.

Parameters:

metrics (collections.abc.Sequence[MutationMetric])

needs_transition: bool#
initialize(particles, log_weights, context)[source]#

Initialize metric state and zero acceptance counters for a new block.

Parameters:
Return type:

sequince.steps.mutation.metrics.state.MutationStepState

prepare(metric_state, particles, context)[source]#

Prepare existing metric state for the next segment, retaining totals.

Parameters:
Return type:

sequince.steps.mutation.metrics.state.MutationStepState

update(metric_state, particles, accepted, context, *, transition=None)[source]#

Record one population transition without changing the input state.

Parameters:
Return type:

sequince.steps.mutation.metrics.state.MutationStepState

result(metric_state, context)[source]#

Collect final results at the outermost block boundary.

Parameters:
Return type:

sequince.steps.mutation.metrics.state.MutationMetricsOutput | None