sequince.callbacks
==================

.. py:module:: sequince.callbacks


Attributes
----------

.. autoapisummary::

   sequince.callbacks.logger


Classes
-------

.. autoapisummary::

   sequince.callbacks.SMCCallback
   sequince.callbacks.PlotCallback
   sequince.callbacks.TracePlot
   sequince.callbacks.IntermediateParticlesPlot
   sequince.callbacks.StatePlot
   sequince.callbacks.AdaptiveMutationPlot
   sequince.callbacks.MutationChainPlot
   sequince.callbacks.TransformedMutationChainPlot
   sequince.callbacks.ParticleTransformPlot


Module Contents
---------------

.. py:data:: logger

.. py:class:: SMCCallback(every = 1)

   Base class for composable SMC callbacks.

   :param every: Run the callback every `every` iterations. Default is 1 (run every
                 iteration).


   .. py:attribute:: every
      :value: 1



   .. py:method:: apply(state, context, results)
      :abstractmethod:



.. py:class:: PlotCallback(outdir = None, filename = 'plot.png', plot_kwargs = None, every = 1)

   Bases: :py:obj:`SMCCallback`


   Base class for SMC callbacks that generate plots.

   :param outdir: Directory to save the plots.  If ``None`` (default) saves to the current
                  working directory.
   :param filename: Filename for the plot.
   :param plot_kwargs: Additional keyword arguments to pass to the plotting method.
   :param every: Run the callback every `every` iterations. Default is 1 (run every
                 iteration).


   .. py:attribute:: outdir


   .. py:attribute:: filename


   .. py:attribute:: full_path


   .. py:attribute:: plot_kwargs


.. py:class:: TracePlot(parameter_inds = None, parameter_labels = None, outdir = None, filename = 'trace.png', plot_kwargs = None, every = 1)

   Bases: :py:obj:`PlotCallback`


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

   :param parameter_inds: List of parameter indices to plot.  If ``None`` (default) plot all parameters.
   :param outdir: Directory to save the trace plots.  If ``None`` (default) saves to the current
                  working directory.
   :param filename: Filename for the trace plot.  Default is ``"trace.png"``.
   :param plot_kwargs: Additional keyword arguments to pass to the `SMCResults.plot_trace` method.
   :param every: Run the callback every `every` iterations. Default is 1 (run every
                 iteration).


   .. py:attribute:: parameter_inds
      :value: None



   .. py:attribute:: parameter_labels
      :value: None



   .. py:method:: apply(state, context, results)


.. py:class:: IntermediateParticlesPlot(outdir = None, base_filename = 'particles', parameter_inds = None, parameter_labels = None, plot_kwargs = None, every = 1)

   Bases: :py:obj:`PlotCallback`


   Plot the intermediate particles at each SMC iteration.

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

   :param outdir: Directory to save the intermediate particle plots.  If ``None``
                  (default) saves to the current working directory.
   :param base_filename: Base filename for the intermediate particle plots.  The iteration number
                         will be appended to the base filename.  Default is ``"particles"``.
   :param plot_kwargs: Additional keyword arguments to pass to the `plot_corner` function.
   :param every: Run the callback every `every` iterations. Default is 1 (run every
                 iteration).


   .. py:attribute:: base_filename
      :value: 'particles'



   .. py:attribute:: parameter_labels
      :value: None



   .. py:attribute:: parameter_inds
      :value: None



   .. py:method:: apply(state, context, results)


.. py:class:: StatePlot(metadata_keys, outdir = None, filename = 'state.png', plot_kwargs = None, every = 1)

   Bases: :py:obj:`PlotCallback`


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

   :param metadata_keys: List of metadata keys to plot. At least one key must be specified.
   :param outdir: Directory to save the state plots.  If ``None`` (default) saves to the current
                  working directory.
   :param filename: Filename for the state plot.  Default is ``"state.png"``.
   :param plot_kwargs: Additional keyword arguments to pass to the `SMCResults.plot_metadata_history` method.
   :param every: Run the callback every `every` iterations. Default is 1 (run every
                 iteration).


   .. py:attribute:: metadata_keys


   .. py:method:: apply(state, context, results)


.. py:class:: AdaptiveMutationPlot(outdir = None, *, step_index = 2, target_steps = None, filename = 'adaptive_mutation_history.png', every = 1)

   Bases: :py:obj:`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.


   .. py:attribute:: step_index
      :type:  int
      :value: 2



   .. py:attribute:: target_steps
      :type:  float | None
      :value: None



   .. py:method:: apply(state, context, results)


.. py:class:: MutationChainPlot(outdir = None, base_filename = 'chain', parameter_inds = None, parameter_labels = None, plot_kwargs = None, step_index = None, output_key = 'chain', every = 1)

   Bases: :py:obj:`PlotCallback`


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

   :param outdir: Directory to save the mutation chains plots.  If ``None`` (default) saves
                  to the current working directory.
   :param base_filename: Base filename for the mutation chains plots.  The iteration number will
                         be appended to the base filename.  Default is ``"chain"``.
   :param plot_kwargs: Additional keyword arguments to pass to the `plot_chain` function.
   :param step_index: 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.
   :param output_key: Key containing the chain in the selected step output.
   :param every: Run the callback every `every` iterations. Default is 1 (run every
                 iteration).


   .. py:attribute:: base_filename
      :value: 'chain'



   .. py:attribute:: parameter_labels
      :value: None



   .. py:attribute:: parameter_inds
      :value: None



   .. py:attribute:: step_index
      :value: None



   .. py:attribute:: output_key
      :value: 'chain'



   .. py:method:: apply(state, context, results)


.. py:class:: 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)

   Bases: :py:obj:`MutationChainPlot`


   Plot mutation chains in the active particle-transform coordinates.

   :param metadata_key: Key in the context metadata containing the fitted particle transform.


   .. py:attribute:: metadata_key
      :value: 'particle_transform'



.. py:class:: ParticleTransformPlot(outdir = None, base_filename = 'particle_transform', metadata_key = PARTICLE_TRANSFORM_KEY, plot_kwargs = None, parameter_inds = None, parameter_labels = None, every = 1)

   Bases: :py:obj:`PlotCallback`


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

   :param outdir: Directory to save the active particle transform plots.  If ``None``
                  (default) saves to the current working directory.
   :param base_filename: Base filename for the active particle transform plots. The iteration
                         number is appended to the base filename. Default is
                         :code:``"particle_transform"``.
   :param metadata_key: Key in the state metadata where the active particle transform is stored.
                        Default is :code:``"particle_transform"``.
   :param plot_kwargs: Additional keyword arguments to pass to the `plot_transform` function.
   :param every: Run the callback every `every` iterations. Default is 1 (run every
                 iteration).


   .. py:attribute:: base_filename
      :value: 'particle_transform'



   .. py:attribute:: metadata_key
      :value: 'particle_transform'



   .. py:attribute:: parameter_inds
      :value: None



   .. py:attribute:: parameter_labels
      :value: None



   .. py:method:: apply(state, context, results)


