xnn.gnn.models.megnet.MEGNet#
- class xnn.gnn.models.megnet.MEGNet(n_features=16, n_interactions=3, n_rbf=100, cutoff=4.0, rbf_max=None, gamma=0.5, state_dim=2, n_state_types=None, state_names=None, encoder_sizes=(64, 32), conv_sizes=(64, 64, 32), readout_sizes=(32, 16), set2set_steps=2, set2set_layers=1, activation='ssp', dropout=0.0, n_outputs=1, classification=False, n_elements=95, property_scale=1.0, property_shift=0.0, weight_init='torch')[source]#
Bases:
ExactFloat64Constants,InteratomicPotential,FastPathModuleMEGNet property model with a global state; multi-fidelity with
n_state_types.See the module docstring for the equations and the defaults.
- Parameters:
n_features (int, optional) – Width of the element embeddings, by default 16.
n_interactions (int, optional) – Number of MEGNet blocks, by default 3.
n_rbf (int, optional) – Number of Gaussians expanding the bond lengths, by default 100.
cutoff (float, optional) – Bond cutoff in Angstrom, by default 4.0 (the multi-fidelity paper: 5.0).
rbf_max (float or None, optional) – Position of the last Gaussian;
None(default) iscutoff + 1.gamma (float, optional) – Exponent of the Gaussians,
exp(-gamma (r - mu)^2), by default 0.5 (the paper: 4.0).state_dim (int, optional) – Width of the state: the number of state features, or of the state embedding with
n_state_types. By default 2.n_state_types (int or None, optional) – Number of integer state labels (fidelities).
None(default) reads float state features.state_names (sequence of str or None, optional) – Names of the state labels in order (e.g.
["PBE", "GLLB-SC", "HSE", "SCAN"]), forstate_label().encoder_sizes (sequence of int, optional) – Dense layers before the first block, and at the start of every later block, by default
(64, 32).conv_sizes (sequence of int, optional) – Layers of the update networks
phi_e,phi_v,phi_u, by default(64, 64, 32). The last size equals the last encoder size.readout_sizes (sequence of int, optional) – Hidden layers of the output network, by default
(32, 16).set2set_steps (int, optional) – Attention steps of the Set2Set readouts, by default 2.
set2set_layers (int, optional) – LSTM layers of the Set2Set readouts, by default 1.
activation (str, optional) – Activation of every dense layer, by default
"ssp".dropout (float, optional) – Dropout after every block and before the output network, by default 0.
n_outputs (int, optional) – Number of properties per structure, by default 1.
classification (bool, optional) – Pass the output through a sigmoid (a metal / nonmetal classifier), by default
False.n_elements (int, optional) – Rows of the element embedding, indexed by atomic number, by default 95 (row 0 unused, as in the paper).
property_scale (float, optional) – Standardization of the output, by default 1 and 0.
property_shift (float, optional) – Standardization of the output, by default 1 and 0.
weight_init (str, optional) – Initialization of the dense layers (a key of
WEIGHT_INITS), by default"torch".
- fast_supported(device, dtype)[source]#
The encoders’ fast stage reads the Gaussian basis and plain dense layers.
- set_use_fast(use_fast)[source]#
Choose the implementation of the encoders, blocks and readouts.
- Parameters:
use_fast (bool or str) –
"auto"(the default): the compiled stages ofxnn.gnn.fast.megneton a GPU above the size crossover measured for evaluation (AUTO_POLICY) or training (AUTO_POLICY_TRAINING);True: always (as written on a CPU);False: the reference. The stages agree with the reference to about 1e-6 relative in float32 and 1e-14 in float64, with the same first and second derivatives.- Returns:
self.- Return type:
- state_label(name)[source]#
The integer state label of a named state (a fidelity such as
"HSE").- Raises:
ValueError – If the model has no state names or does not know
name.- Parameters:
name (str)
- Return type:
- set_property_scale_shift(scale, shift)[source]#
Set the output standardization
scale * y + shift(e.g. the training-set std and mean).
- forward(data)[source]#
Predict the property of every structure.
- Parameters:
data (AtomicGraph) – The batch;
data.stateholds the state labels or features (None: label 0 or zero features).- Returns:
"properties", shape(B,)(or(B, n_outputs)), and"structure_features", the readout(B, 5 F)the output network maps (the latent features of the multi-fidelity paper).- Return type:
- classmethod from_foundation(name='megnet-mp-2018.6.1-eform', dtype=None, cache_dir=None, quiet=False)[source]#
Load a pretrained MatGL MEGNet model (formation energy or multi-fidelity band gap).
See
xnn.gnn.models.megnet_foundation.- Parameters:
name (str, optional) –
"megnet-mp-2018.6.1-eform"(default, eV/atom) or"megnet-mp-2019.4.1-bandgap-mfi"(eV; fidelities PBE, GLLB-SC, HSE and SCAN).dtype (torch.dtype or str, optional) – Final dtype;
Nonekeeps the checkpoint’s float32.cache_dir (str or pathlib.Path, optional) – Model cache directory.
quiet (bool, optional) – Hide the download progress bars. Default
False.
- Returns:
The converted model, in evaluation mode.
- Return type:
- classmethod from_config(cfg)[source]#
Build a
MEGNetfrom a configuration object.Core fields:
cfg.n_features(element embedding width),cfg.n_interactions(blocks),cfg.n_rbfandcfg.cutoff. Everything else is read fromcfg.extra(rbf_max,gamma,state_dim,n_state_types,state_names,encoder_sizes,conv_sizes,readout_sizes,set2set_steps,set2set_layers,activation,dropout,n_outputs,classification,n_elements,property_scale,property_shift,weight_init); MatGL’s spellings are translated byxnn.common.config.translate.- Parameters:
cfg (xnn.common.config.schema.ModelConfig) – The core model config.
- Returns:
Instantiated model.
- Return type: