11import logging
22import warnings
3- from typing import Dict , List , Literal , Optional , Union
3+ from typing import Any , Dict , List , Literal , Optional , Union
44
55import metatensor .torch as mts
66import torch
2222 sparsify_atomic_basis_target ,
2323)
2424from metatrain .utils .dtype import dtype_to_str
25+ from metatrain .utils .hypers import raise_if_hypers_mismatch
2526from metatrain .utils .metadata import merge_metadata
2627
2728from . import checkpoints
@@ -204,7 +205,9 @@ def train_model(
204205 checkpoint_dir = "" ,
205206 )
206207
207- def restart (self , dataset_info : DatasetInfo ) -> "CompositionModel" :
208+ def restart (
209+ self , dataset_info : DatasetInfo , model_hypers : Optional [dict [str , Any ]] = None
210+ ) -> "CompositionModel" :
208211 """
209212 Update the model to continue training, possibly with new targets.
210213
@@ -214,8 +217,13 @@ def restart(self, dataset_info: DatasetInfo) -> "CompositionModel":
214217
215218 :param dataset_info: Information about the new dataset, including the
216219 targets that will be used for training.
220+ :param model_hypers: New hyperparameters for the model. They must match
221+ the existing hyperparameters, otherwise an error is raised.
217222 :return: The updated model.
218223 """
224+ if model_hypers is not None :
225+ raise_if_hypers_mismatch (self .hypers , model_hypers )
226+
219227 raw_targets = {}
220228 for target_name in dataset_info .targets :
221229 target_info = dataset_info .targets [target_name ]
0 commit comments