diff --git a/pybop/models/base_model.py b/pybop/models/base_model.py index 019c94c1f..dc3d83b43 100644 --- a/pybop/models/base_model.py +++ b/pybop/models/base_model.py @@ -204,6 +204,16 @@ def set_params(self, rebuild=False): self._parameter_set.process_geometry(self.geometry) self.pybamm_model = self._model_with_set_params + def clear(self): + """ + Clear any built PyBaMM model. + """ + self._model_with_set_params = None + self._built_model = None + self._built_initial_soc = None + self._mesh = None + self._disc = None + def rebuild( self, dataset: Dataset = None, @@ -712,25 +722,15 @@ def approximate_capacity(self, inputs: Inputs): def built_model(self): return self._built_model - @built_model.setter - def built_model(self, built_model): - self._built_model = built_model if built_model is not None else None - @property def built_initial_soc(self): return self._built_initial_soc - @built_initial_soc.setter - def built_initial_soc(self, built_initial_soc): - self._built_initial_soc = ( - built_initial_soc if built_initial_soc is not None else None - ) - @property def parameter_set(self): return self._parameter_set - @parameter_set.setter + @parameter_set.setter # remove in #425 def parameter_set(self, parameter_set): self._parameter_set = parameter_set.copy() if parameter_set is not None else {} @@ -738,12 +738,6 @@ def parameter_set(self, parameter_set): def model_with_set_params(self): return self._model_with_set_params - @model_with_set_params.setter - def model_with_set_params(self, model_with_set_params): - self._model_with_set_params = ( - model_with_set_params.copy() if model_with_set_params is not None else None - ) - @property def geometry(self): return self._geometry @@ -756,26 +750,14 @@ def submesh_types(self): def mesh(self): return self._mesh - @mesh.setter - def mesh(self, mesh): - self._mesh = mesh if mesh is not None else None - @property def disc(self): return self._disc - @disc.setter - def disc(self, disc): - self._disc = disc if disc is not None else None - @property def var_pts(self): return self._var_pts - @var_pts.setter - def var_pts(self, var_pts: Optional[dict[str, int]]): - self._var_pts = var_pts.copy() if var_pts is not None else None - @property def spatial_methods(self): return self._spatial_methods @@ -783,7 +765,3 @@ def spatial_methods(self): @property def solver(self): return self._solver - - @solver.setter - def solver(self, solver): - self._solver = solver.copy() if solver is not None else None diff --git a/pybop/models/empirical/base_ecm.py b/pybop/models/empirical/base_ecm.py index 87f3d4fe3..afd956425 100644 --- a/pybop/models/empirical/base_ecm.py +++ b/pybop/models/empirical/base_ecm.py @@ -77,7 +77,7 @@ def __init__( self._spatial_methods = ( spatial_methods or self.pybamm_model.default_spatial_methods ) - self.solver = solver or self.pybamm_model.default_solver + self._solver = solver or self.pybamm_model.default_solver # Internal attributes for the built model are initialized but not set self._model_with_set_params = None diff --git a/pybop/problems/fitting_problem.py b/pybop/problems/fitting_problem.py index ac91513f4..bd9d1d6b4 100644 --- a/pybop/problems/fitting_problem.py +++ b/pybop/problems/fitting_problem.py @@ -67,11 +67,7 @@ def __init__( # Build the model from scratch if self._model.built_model is not None: - self._model.model_with_set_params = None - self._model.built_model = None - self._model.built_initial_soc = None - self._model.mesh = None - self._model.disc = None + self._model.clear() self._model.build( dataset=self._dataset, parameters=self.parameters,