sequince.callbacks#

Attributes#

Classes#

SMCCallback

Base class for composable SMC callbacks.

PlotCallback

Base class for SMC callbacks that generate plots.

TracePlot

Callback to plot 1-d particle locations every SMC iteration.

IntermediateParticlesPlot

Plot the intermediate particles at each SMC iteration.

StatePlot

Callback to plot user-specified state metadata every SMC iteration.

AdaptiveMutationPlot

Plot completed mutation budgets, acceptance, and accepted moves.

MutationChainPlot

Callback to plot the chains from the mutation step of the SMC algorithm.

TransformedMutationChainPlot

Plot mutation chains in the active particle-transform coordinates.

ParticleTransformPlot

Callback to plot the active particle transform at each SMC iteration.

Module Contents#

sequince.callbacks.logger#
class sequince.callbacks.SMCCallback(every=1)[source]#

Base class for composable SMC callbacks.

Parameters:

every (int) – Run the callback every every iterations. Default is 1 (run every iteration).

every = 1#
abstractmethod apply(state, context, results)[source]#
Parameters:
Return type:

sequince.steps.base.StepContext | None

class sequince.callbacks.PlotCallback(outdir=None, filename='plot.png', plot_kwargs=None, every=1)[source]#

Bases: SMCCallback

Base class for SMC callbacks that generate plots.

Parameters:
  • outdir (str | None) – Directory to save the plots. If None (default) saves to the current working directory.

  • filename (str) – Filename for the plot.

  • plot_kwargs (dict[str, Any] | None) – Additional keyword arguments to pass to the plotting method.

  • every (int) – Run the callback every every iterations. Default is 1 (run every iteration).

outdir#
filename#
full_path#
plot_kwargs#
class sequince.callbacks.TracePlot(parameter_inds=None, parameter_labels=None, outdir=None, filename='trace.png', plot_kwargs=None, every=1)[source]#

Bases: PlotCallback

Callback to plot 1-d particle locations every SMC iteration.

Parameters:
  • parameter_inds (list[int] | None) – List of parameter indices to plot. If None (default) plot all parameters.

  • outdir (str | None) – Directory to save the trace plots. If None (default) saves to the current working directory.

  • filename (str) – Filename for the trace plot. Default is "trace.png".

  • plot_kwargs (dict[str, Any] | None) – Additional keyword arguments to pass to the SMCResults.plot_trace method.

  • every (int) – Run the callback every every iterations. Default is 1 (run every iteration).

  • parameter_labels (list[str] | None)

parameter_inds = None#
parameter_labels = None#
apply(state, context, results)[source]#
Parameters:
Return type:

None

class sequince.callbacks.IntermediateParticlesPlot(outdir=None, base_filename='particles', parameter_inds=None, parameter_labels=None, plot_kwargs=None, every=1)[source]#

Bases: PlotCallback

Plot the intermediate particles at each SMC iteration.

Plots a corner-style plot of the particles at each SMC iteration.

Parameters:
  • outdir (str | None) – Directory to save the intermediate particle plots. If None (default) saves to the current working directory.

  • base_filename (str) – Base filename for the intermediate particle plots. The iteration number will be appended to the base filename. Default is "particles".

  • plot_kwargs (dict[str, Any] | None) – Additional keyword arguments to pass to the plot_corner function.

  • every (int) – Run the callback every every iterations. Default is 1 (run every iteration).

  • parameter_inds (list[int] | None)

  • parameter_labels (list[str] | None)

base_filename = 'particles'#
parameter_labels = None#
parameter_inds = None#
apply(state, context, results)[source]#
Parameters:
Return type:

None

class sequince.callbacks.StatePlot(metadata_keys, outdir=None, filename='state.png', plot_kwargs=None, every=1)[source]#

Bases: PlotCallback

Callback to plot user-specified state metadata every SMC iteration.

Parameters:
  • metadata_keys (list[str]) – List of metadata keys to plot. At least one key must be specified.

  • outdir (str | None) – Directory to save the state plots. If None (default) saves to the current working directory.

  • filename (str) – Filename for the state plot. Default is "state.png".

  • plot_kwargs (dict[str, Any] | None) – Additional keyword arguments to pass to the SMCResults.plot_metadata_history method.

  • every (int) – Run the callback every every iterations. Default is 1 (run every iteration).

metadata_keys#
apply(state, context, results)[source]#
Parameters:
Return type:

None

class sequince.callbacks.AdaptiveMutationPlot(outdir=None, *, step_index=2, target_steps=None, filename='adaptive_mutation_history.png', every=1)[source]#

Bases: PlotCallback

Plot completed mutation budgets, acceptance, and accepted moves.

step_index selects the mutation output within each iteration (default 2, after weighting and resampling). Mapping and dataclass outputs containing metrics are supported, including conditional wrappers. Missing metrics leave gaps; no attempted moves leave acceptance undefined. target_steps optionally marks the target accepted moves per particle. The callback does not depend on a particular adaptation policy and also supports fixed budgets.

every, outdir, and filename follow PlotCallback conventions.

Parameters:
step_index: int = 2#
target_steps: float | None = None#
apply(state, context, results)[source]#
Parameters:
Return type:

None

class sequince.callbacks.MutationChainPlot(outdir=None, base_filename='chain', parameter_inds=None, parameter_labels=None, plot_kwargs=None, step_index=None, output_key='chain', every=1)[source]#

Bases: PlotCallback

Callback to plot the chains from the mutation step of the SMC algorithm.

Parameters:
  • outdir (str | None) – Directory to save the mutation chains plots. If None (default) saves to the current working directory.

  • base_filename (str) – Base filename for the mutation chains plots. The iteration number will be appended to the base filename. Default is "chain".

  • plot_kwargs (dict[str, Any] | None) – Additional keyword arguments to pass to the plot_chain function.

  • step_index (int | None) – Index of the mutation step in the current iteration’s outputs. If None (default), search all outputs from the current iteration. Nested outputs produced by control steps are searched recursively.

  • output_key (str) – Key containing the chain in the selected step output.

  • every (int) – Run the callback every every iterations. Default is 1 (run every iteration).

  • parameter_inds (list[int] | None)

  • parameter_labels (list[str] | None)

base_filename = 'chain'#
parameter_labels = None#
parameter_inds = None#
step_index = None#
output_key = 'chain'#
apply(state, context, results)[source]#
Parameters:
Return type:

None

class sequince.callbacks.TransformedMutationChainPlot(outdir=None, base_filename='transformed_chain', parameter_inds=None, parameter_labels=None, plot_kwargs=None, step_index=None, output_key='chain', metadata_key=PARTICLE_TRANSFORM_KEY, every=1)[source]#

Bases: MutationChainPlot

Plot mutation chains in the active particle-transform coordinates.

Parameters:
  • metadata_key (str) – Key in the context metadata containing the fitted particle transform.

  • outdir (str | None)

  • base_filename (str)

  • parameter_inds (list[int] | None)

  • parameter_labels (list[str] | None)

  • plot_kwargs (dict[str, Any] | None)

  • step_index (int | None)

  • output_key (str)

  • every (int)

metadata_key = 'particle_transform'#
class sequince.callbacks.ParticleTransformPlot(outdir=None, base_filename='particle_transform', metadata_key=PARTICLE_TRANSFORM_KEY, plot_kwargs=None, parameter_inds=None, parameter_labels=None, every=1)[source]#

Bases: PlotCallback

Callback to plot the active particle transform at each SMC iteration.

Parameters:
  • outdir (str | None) – Directory to save the active particle transform plots. If None (default) saves to the current working directory.

  • base_filename (str) – Base filename for the active particle transform plots. The iteration number is appended to the base filename. Default is :code:"particle_transform".

  • metadata_key (str) – Key in the state metadata where the active particle transform is stored. Default is :code:"particle_transform".

  • plot_kwargs (dict[str, Any] | None) – Additional keyword arguments to pass to the plot_transform function.

  • every (int) – Run the callback every every iterations. Default is 1 (run every iteration).

  • parameter_inds (list[int] | None)

  • parameter_labels (list[str] | None)

base_filename = 'particle_transform'#
metadata_key = 'particle_transform'#
parameter_inds = None#
parameter_labels = None#
apply(state, context, results)[source]#
Parameters:
Return type:

None