Save and load a model#

Once you’ve trained a model, you can save it disk and load it back later for the purpose of retraining, evaluation, etc.

Save a model#

The save() method of a model can be used to save it. Suppose you’ve trained the Stillinger-Weber (SW) potential discussed in Train a Stillinger-Weber potential, you can save the model by:

path = "./kliff_model.pkl"
model.save(path)

which creates a pickled file named kliff_model.pkl in the current working directory. All the information related to the model are saved to the file, including the final values of the parameters, the constraints on the parameters (such as the bounds on parameters set via set_one_opt_param() or set_opt_params()), and others.

Load a model#

A model can be loaded using load() after the instantiation. For the same SW potential discussed in Train a Stillinger-Weber potential, it can be loaded by:

model = KIMModel(model_name="Three_Body_Stillinger_Weber_Si__MO_405512056662_004")
path = "./kliff_model.pkl"
model.load(path)

If you want to retrain the loaded model, you can attach it to a calculator and then proceed as what discussed in Train a Stillinger-Weber potential and Train a neural network potential.