mlcolvar.cvs.BaseCV¶
- class mlcolvar.cvs.BaseCV(in_features, out_features, preprocessing: Module = None, postprocessing: Module = None, *args, **kwargs)[source]¶
Bases:
objectBase collective variable class.
To inherit from this class, the class must define a BLOCKS class attribute.
- __init__(in_features, out_features, preprocessing: Module = None, postprocessing: Module = None, *args, **kwargs)[source]¶
Base CV class options.
- Parameters:
in_features (int) – Number of inputs of the CV model
out_features (int) – Number of outputs of the CV model, should be the number of CVs
preprocessing (torch.nn.Module, optional) – Preprocessing module, default None
postprocessing (torch.nn.Module, optional) – Postprocessing module, default None
Methods
__init__(in_features, out_features[, ...])Base CV class options.
Initialize the optimizer based on self._optimizer_name and self.optimizer_kwargs.
forward(x)Evaluation of the CV
forward_cv(x)Execute sequentially all the blocks in self.BLOCKS unless they are not initialized.
Initialize the blocks as attributes of the CV class.
initialize_transforms(datamodule)parse_options([options])Sanitize options and create defaults ({}) if not in options.
setup([stage])test_step(test_batch, batch_idx)Equal to training step if not overridden.
validation_step(val_batch, batch_idx)Equal to training step if not overridden.
- configure_optimizers()[source]¶
Initialize the optimizer based on self._optimizer_name and self.optimizer_kwargs. It also adds the learning rate scheduler if self.lr_scheduler_kwargs is not empty. The scheduler is given as a dictionary with the key ‘scheduler’ containing the scheduler class and the rest of the keys are config options for the scheduler.
- Returns:
torch.optim – Torch optimizer
dict, optional – Learning rate scheduler configuration (if any)
- forward(x: Tensor) Tensor[source]¶
Evaluation of the CV
Apply preprocessing if any
Execute sequentially all the blocks in self.BLOCKS unless they are not initialized
Apply postprocessing if any
- Parameters:
x (torch.Tensor) – Input of the forward operation of the model
- Returns:
Output of the forward operation of the model
- Return type:
torch.Tensor
- forward_cv(x: Tensor) Tensor[source]¶
Execute sequentially all the blocks in self.BLOCKS unless they are not initialized.
No pre/post processing will be executed here. This is supposed to be called during training/validation and to be overloaded if necessary.
- Parameters:
x (torch.Tensor) – Input of the forward operation of the model
- Returns:
Output of the forward operation of the model
- Return type:
torch.Tensor
- property n_cvs¶
Number of CVs.
- property optimizer_name: str¶
Optimizer name. Options can be set using optimizer_kwargs. Actual optimizer will be return during training from configure_optimizer function.
- parse_options(options: dict = None)[source]¶
Sanitize options and create defaults ({}) if not in options. Furthermore, it sets the optimizer kwargs, if given.
- Parameters:
options (dict[str, Any], optional) – Options for the building blocks of the model, by default None.
Attributes
example_input_arrayNumber of CVs.
Optimizer name.