Base Refinement#

class BaseRefinement(sample_every, condition_to_update=None)[source]#

Bases: Callback, RefinementInterface

Base class for all refinement strategies, implementing common functionality.

A refinement strategy is responsible for dynamically updating the training dataset during optimization, typically by resampling points in the domain based on model behavior (e.g., error-driven refinement).

All specific refinement strategies should inherit from this class and implement its abstract methods.

This class is not meant to be instantiated directly.

Initialization of the BaseRefinement class.

Parameters:
  • sample_every (int) – The number of epochs between successive refinement steps.

  • condition_to_update (str | list[str] | tuple[str]) – The condition(s) to be updated during refinement. If None, all conditions associated with a domain are updated. Default is None.

Raises:
  • AssertionError – If sample_every is not a positive integer.

  • ValueError – If condition_to_update, when provided, is not a string or an iterable of strings.

on_train_start(trainer, solver)[source]#

This method is called once before training begins and is typically used to initialize datasets, sampling conditions, or internal state.

Parameters:
  • trainer (Trainer) – The trainer managing the training loop.

  • solver (BaseSolver) – The solver associated with the trainer.

Raises:
  • RuntimeError – If the solver is not physics-informed (i.e., does not implement PINNInterface).

  • RuntimeError – If any of the specified conditions do not exist in the problem.

  • RuntimeError – If any of the specified conditions do not have a ‘domain’ attribute for sampling.

on_train_epoch_end(trainer, solver)[source]#

Apply refinement at the end of a training epoch.

This method is invoked after each epoch and can update the dataset based on the current state of the model.

Parameters:
  • trainer (Trainer) – The trainer managing the training loop.

  • solver (BaseSolver) – The solver associated with the trainer.

property dataset#

The training datasets managed by the refinement strategy.

The dataset is stored as a dictionary whose keys are condition names and whose values are the corresponding dataset subsets. The content of this dictionary can be updated dynamically during refinement.

Returns:

The mapping between condition names and dataset subsets.

Return type:

dict

property initial_population_size#

Initial size of the sampled dataset for each condition before any refinement is applied.

Returns:

A mapping between each condition name and its initial number of sampled points.

Return type:

dict[str, int]