示例#1
0
"""
Compute the root-mean-square error (RMSE) of a model prediction and reference values in
the dataset.
"""

from kliff.analyzers import EnergyForcesRMSE
from kliff.calculators import Calculator
from kliff.dataset import Dataset
from kliff.models import KIMModel
from kliff.utils import download_dataset

model = KIMModel(model_name="SW_StillingerWeber_1985_Si__MO_405512056662_005")

# load the trained model back
# model.load("kliff_model.yaml")

dataset_path = download_dataset(dataset_name="Si_training_set_4_configs")
tset = Dataset(dataset_path)
configs = tset.get_configs()

calc = Calculator(model)
calc.create(configs)

analyzer = EnergyForcesRMSE(calc)
analyzer.run(verbose=2, sort="energy")
示例#2
0
N2 = 10
model_c = NeuralNetwork(descriptor)
model_c.add_layers(
    # first hidden layer
    nn.Linear(descriptor.get_size(), N1),
    nn.Tanh(),
    # second hidden layer
    nn.Linear(N1, N2),
    nn.Tanh(),
    # output layer
    nn.Linear(N2, 1),
)
model_c.set_save_metadata(prefix="./kliff_saved_model_c", start=5, frequency=2)

# training set
dataset_path = download_dataset(dataset_name="SiC_training_set")
tset = Dataset(dataset_path)
configs = tset.get_configs()

# calculator
calc = CalculatorTorchSeparateSpecies({"Si": model_si, "C": model_c})
_ = calc.create(configs, reuse=False)

# loss
loss = Loss(calc, residual_data={"forces_weight": 0.3})
result = loss.minimize(method="Adam", num_epochs=10, batch_size=4, lr=0.001)

##########################################################################################
# We can save the trained model to disk, and later can load it back if we want. We can
# also write the trained model to a KIM model such that it can be used in other simulation
# codes such as LAMMPS via the KIM API.