agedi.api.diffusion¶
Diffusion model creation and loading.
Functions¶
|
Create a diffusion model for script-based training and sampling. |
|
Load a trained diffusion model from an AGeDi log directory. |
Module Contents¶
- agedi.api.diffusion.create_diffusion(model: str = 'PaiNN', cutoff: float = 6.0, feature_size: int = 64, n_blocks: int = 4, n_rbf: int = 30, noisers: Sequence[str | Noiser] = ('CellPositions',), sde: str | SDE = 've', conditioning: str = 'none', conditioning_type: str = 'scalar', confinement: Tuple[float, float] | None = None, force_field: bool = False, lr: float = 0.0001, lr_factor: float = 0.95, lr_patience: int = 100, weight_decay: float = 0.0, eps: float = 1e-05, guidance_weight: float = -1.0, device: str | torch.device | None = None, type_map: List[int] | None = None) agedi.Agedi¶
Create a diffusion model for script-based training and sampling.
- Parameters:
model (str, optional) – GNN backbone architecture. The name is looked up in the model registry; use
register_model()to add custom backends. The built-in default is"PaiNN"(SchNetPack PaiNN).cutoff (float, optional) – Neighbour-list cutoff radius in Å. Defaults to
6.0.feature_size (int, optional) – Embedding / feature dimension. Defaults to
64.n_blocks (int, optional) – Number of interaction blocks. Defaults to
4.n_rbf (int, optional) – Number of radial basis functions. Defaults to
30.noisers (Sequence[str or Noiser], optional) –
Noiser identifiers or instances to include. Defaults to
("CellPositions",). Recognised string identifiers (CamelCase preferred; snake_case aliases also accepted for backwards compatibility):"Positions"/"positions"–Positions(StandardNormal prior + Normal, for gas-phase clusters)."CellPositions"/"cell_positions"–CellPositions(UniformCell prior + Normal, for periodic bulk/surface systems)."ConfinedCellPositions"/"confined_cell_positions"–ConfinedCellPositions(UniformCellConfined prior + TruncatedNormal, for Z-confined systems)."Types"/"types"–Types.
sde (str or SDE, optional) – SDE for position noisers. Short aliases:
"ve"(default),"vp". Pass an instantiatedSDEfor full control.conditioning (str, optional) – Property to condition on, or
"none"for time-only conditioning. Defaults to"none".conditioning_type (str, optional) – Type of the conditioning module:
"scalar"or"integer". Defaults to"scalar".confinement (Tuple[float, float], optional) – Z-direction confinement bounds
(z_min, z_max)in Å.force_field (bool, optional) – When
True, attach adiffusion.regressor_model. The heads shares the same representation and translator as the score model so that atomic embeddings are learned jointly. It is trained whenever the training batch contains per-atom forces and total energies (i.e. the ASE training structures have DFT (or other) energy and forces). The trained forces head enables force-field guided sampling viaForcefieldGuidanceConfig. Defaults toFalse.lr (float, optional) – Learning rate. Defaults to
1e-4.lr_factor (float, optional) – LR-scheduler reduction factor. Defaults to
0.95.lr_patience (int, optional) – LR-scheduler patience (epochs). Defaults to
100.weight_decay (float, optional) – Optimizer weight-decay. Defaults to
0.0.eps (float, optional) – Minimum diffusion time. Defaults to
1e-5.guidance_weight (float, optional) – Classifier-free guidance weight. Defaults to
-1.0(disabled).device (str or torch.device, optional) – Target compute device. When
NoneCUDA is used if available, otherwise CPU.type_map (List[int], optional) – Compact type map for the
Typesnoiser.type_map[0]must be0(absorbing state) andtype_map[i]is the atomic number for compact indexi. When provided, theTypesnoiser and theTypesScorehead use a reduced vocabulary of sizelen(type_map)instead of the default 100. Auto-populated bytrain_from_atoms()when a"Types"noiser is requested.
- Returns:
A freshly initialised
Agedimodel.- Return type:
- agedi.api.diffusion.load_diffusion(path: str | pathlib.Path, checkpoint: str | pathlib.Path | None = None, device: str | torch.device | None = None) Agedi¶
Load a trained diffusion model from an AGeDi log directory.
The model architecture is fully reconstructed from the Hydra-compatible
diffusionconfig stored inhparams.yaml, so no additional parameters are needed.- Parameters:
path – Path to the AGeDi log / model directory (or directly to the
hparams.yamlfile).checkpoint – Path to a specific checkpoint file. When
Nonethe latest checkpoint (checkpoints/last_model.ckpt) is loaded automatically.device – Device to load the model onto. When
NoneCUDA is used if available, otherwise CPU.