alan-turing-institute / autoemulate

emulate simulations easily
MIT License
15 stars 1 forks source link

Proper model register #189

Open bryanlimy opened 4 months ago

bryanlimy commented 4 months ago

Currently, MODEL_REGISTER is a dictionary of emulators where all the emulators would be initialized when we call _get_models.

MODEL_REGISTRY = {
    "SecondOrderPolynomial": SecondOrderPolynomial(),
    "RBF": RBF(),
    "RandomForest": RandomForest(),
    "GradientBoosting": GradientBoosting(),
    "GaussianProcessSk": GaussianProcessSk(),
    "SupportVectorMachines": SupportVectorMachines(),
    "XGBoost": XGBoost(),
    "NeuralNetSk": NeuralNetSk(),
    "NeuralNetTorch": NeuralNetTorch(module="mlp"),
    # "GaussianProcess": GaussianProcess,

Since MODEL_REGISTER is a dictionary, it caches the initialized module and would return initialized module instead of returning a new instance of the module when we call get_models again. This would lead to unexpected errors (i.e. shape mismatch).

As a hotfix https://github.com/alan-turing-institute/autoemulate/pull/180/commits/3db7e7e509e29b6072607a204e6f1d115e20a6f0, we added deepcopy in _get_models upon initialization, but a proper model register that return an instance of a module is needed.