mlcolvar.core.loss.CommittorLoss

class mlcolvar.core.loss.CommittorLoss(atomic_masses: Tensor, alpha: float, cell: float = None, gamma: float = 10000.0, delta_f: float = 0.0, separate_boundary_dataset: bool = True, descriptors_derivatives: SmartDerivatives | Tensor = None, log_var: bool = False, z_regularization: float = 0.0, z_threshold: float = None, n_dim: int = 3)[source]

Bases: Module

Compute a loss function based on Kolmogorov’s variational principle for the determination of the committor function

__init__(atomic_masses: Tensor, alpha: float, cell: float = None, gamma: float = 10000.0, delta_f: float = 0.0, separate_boundary_dataset: bool = True, descriptors_derivatives: SmartDerivatives | Tensor = None, log_var: bool = False, z_regularization: float = 0.0, z_threshold: float = None, n_dim: int = 3)[source]

Compute Kolmogorov’s variational principle loss and impose boundary conditions on the metastable states

Parameters:
  • atomic_masses (torch.Tensor) – Atomic masses of the atoms in the system

  • alpha (float) – Hyperparamer that scales the boundary conditions contribution to loss, i.e. alpha*(loss_bound_A + loss_bound_B)

  • cell (float, optional) – CUBIC cell size length, used to scale the positions from reduce coordinates to real coordinates, by default None

  • gamma (float, optional) – Hyperparamer that scales the whole loss to avoid too small numbers, i.e. gamma*(loss_var + loss_bound), by default 10000

  • delta_f (float, optional) – Delta free energy between A (label 0) and B (label 1), units is kBT, by default 0. State B is supposed to be higher in energy.

  • separate_boundary_dataset (bool, optional) – Switch to exculde boundary condition labeled data from the variational loss, by default True

  • descriptors_derivatives (Union[SmartDerivatives, torch.Tensor], optional) – Derivatives of descriptors wrt atomic positions (if used) to speed up calculation of gradients, by default None. Can be either:

    • A SmartDerivatives object to save both memory and time, see also mlcolvar.core.loss.committor_loss.SmartDerivatives

    • A torch.Tensor with the derivatives to save time, memory-wise could be less efficient

  • ref_idx (torch.Tensor, optional) – Reference indeces for the unshuffled dataset for properly handling batching/splitting/shuffling when descriptors derivatives are provided, by default None. Ref_idx can be generated automatically using SmartDerivatives or by setting create_ref_idx=True when initializing a DictDataset. See also mlcolvar.core.loss.utils.smart_derivatives.SmartDerivatives

  • log_var (bool, optional) – Switch to minimize the log of the variational functional, by default False.

  • z_regularization (float, optional) – Scales a regularization on the learned z space preventing it from exceeding the threshold given with ‘z_threshold’. The magnitude of the regularization is scaled by the given number, by default 0.0

  • z_threshold (float, optional) – Sets a maximum threshold for the z value during the training, by default None. The magnitude of the regularization term is scaled via the z_regularization key.

  • n_dim (int) – Number of dimensions, by default 3.

Methods

__init__(atomic_masses, alpha[, cell, ...])

Compute Kolmogorov's variational principle loss and impose boundary conditions on the metastable states

forward(x, z, q, labels, w[, ref_idx, ...])

Committor loss forward pass

forward(x: Tensor, z: Tensor, q: Tensor, labels: Tensor, w: Tensor, ref_idx: Tensor = None, create_graph: bool = True) Tuple[Tensor, Tensor, Tensor, Tensor][source]

Committor loss forward pass

Parameters:
  • x (torch.Tensor) – Model input, i.e., either positions or descriptors if using descriptors_derivatives

  • z (torch.Tensor) – Model unactivated output, i.e., z value

  • q (torch.Tensor) – Model final output, i.e., committor value

  • labels (torch.Tensor) – Input labels

  • w (torch.Tensor) – Input weights

  • ref_idx (torch.Tensor, optional) – Reference indeces for the unshuffled dataset for properly handling batching/splitting/shuffling when descriptors derivatives are provided, by default None. Ref_idx can be generated automatically using SmartDerivatives or by setting create_ref_idx=True when initializing a DictDataset. See also mlcolvar.core.loss.utils.smart_derivatives.SmartDerivatives

  • create_graph (bool, optional) – Whether to create the graph during the computation for backpropagation, by default True

Returns:

Total loss and its components, i.e., variational, boundary A, and boundary B

Return type:

Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]

Attributes

T_destination

call_super_init

dump_patches

training