pyNNsMD package

Subpackages

Submodules

pyNNsMD.NNsMD module

class pyNNsMD.NNsMD.NeuralNetEnsemble(directory: str, number_models: int = 2, logger=None)[source]

Bases: object

Main class NeuralNetPes that keeps multiple keras models and manages training and prediction.

Main class for neural network (NN) container to provide multiple NN instances.

Enables uncertainty estimate as well as training and prediction of arbitrary tf.keras models for potentials plus gradients and couplings. The python class is supposed to allow parallel training.

The individual model types are further stored to file in the directory specified in initialization.

The information and models are passed via file to training scripts.

from pyNNsMD.NNsMD import NeuralNetEnsemble
nn = NeuralNetEnsemble("TestEnergy/", 2)
__init__(directory: str, number_models: int = 2, logger=None)[source]

Initialize empty NeuralNetEnsemble instance.

Parameters
  • directory (str) – Directory where models, hyperparameter, logging and fit results are stored.

  • number_models (int, optional) – Number of Neural network instances to create for error estimate. The default is 2.

  • logger – Logger for this class.

call(x, **kwargs)[source]
create(models: list, scalers: list)[source]

Initialize and build a list of keras models. Missing hyperparameter are filled from default.

Parameters
  • models (list) – List of models or dictionary with model hyperparameter. In each dictionary, information of module and model class must be provided.

  • scalers (list) – List of scalers or dictionary with scaler hyperparameter. In each dictionary, information of module and model class must be provided.

Returns

self

data(atoms: Optional[list] = None, geometries: Optional[list] = None, forces: Optional[list] = None, energies: Optional[list] = None, couplings: Optional[list] = None)[source]
data_path(file_path)[source]
fit(training_scripts: list, gpu_dist: Optional[list] = None, proc_async=True, fit_mode='training')[source]

Fit NN to data. Model weights and hyperparameter must always be saved to file before fit.

The fit routine calls training scripts on the data_folder in parallel. The type of execution is found in src.fit with the training src.training_ scripts.

Parameters
  • training_scripts (list) – List of training scripts for each model.

  • gpu_dist (list, optional) – List of GPUs for each NN. Default is [].

  • proc_async (bool, optional) – Try to run parallel. Default is True.

  • fit_mode (str, optional) – Whether to do ‘training’ or ‘retraining’ the existing model in hyperparameter category. Default is ‘training’. In principle every reasonable category can be created in hyperparameters.

Returns

Fitting Error.

Return type

list

load(load_model: bool = False, load_scaler: bool = False)[source]

Load model from file that are stored in class folder.

The tensorflow.keras.model is not loaded itself but created new from hyperparameter.

Parameters
  • load_model (bool) – Whether to load model without remaking the model. Default is False.

  • load_scaler (bool) – Whether to load model without remaking the scaler. Default is False.

Raises

FileNotFoundError – If Directory not found.

Returns

self.

predict(x, **kwargs)[source]
save(save_weights: bool = True, save_model: bool = True, save_scaler: bool = True)[source]

Save models, scaler and hyperparameter into class folder.

Parameters
  • save_weights (bool) – Whether to save weights separately. Default is True.

  • save_model (bool) – Whether to save model as keras model. Default is True.

  • save_scaler (bool) – Whether to save scaler as scaler (not supported). Default is True.

Returns

self

train_test_indices(train: list, test: list)[source]
train_test_split(dataset_size, n_splits: int = 5, shuffle: bool = True, random_state: Optional[int] = None)[source]

Generate split and save indices to model instances.

training(training_hyper: list, fit_mode: str = 'training')[source]

Module contents