From 38d41315bf5c6d83bb0cf450c476dd23a7b2ead8 Mon Sep 17 00:00:00 2001 From: Joeperdefloep Date: Thu, 25 Mar 2021 17:43:56 +0100 Subject: [PATCH] update_processes and clone --- xsimlab/model.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/xsimlab/model.py b/xsimlab/model.py index f0120ad..102948a 100644 --- a/xsimlab/model.py +++ b/xsimlab/model.py @@ -1206,9 +1206,13 @@ def clone(self): """ processes_cls = {k: type(obj) for k, obj in self._processes.items()} - return type(self)(processes_cls) + return type(self)( + processes_cls, self._custom_dependencies, self._strict_order_check + ) - def update_processes(self, processes): + def update_processes( + self, processes, custom_dependencies={}, strict_order_check=None + ): """Add or replace processe(s) in this model. Parameters @@ -1216,6 +1220,11 @@ def update_processes(self, processes): processes : dict Dictionnary with process names as keys and process classes as values. + custom_dependencies : dict + Dictionary with addtional custom dependencies + strict_order_check : bool + Whether to strictly check for ordering in the new model, by default + retains the setting. Returns ------- @@ -1225,9 +1234,21 @@ def update_processes(self, processes): """ processes_cls = {k: type(obj) for k, obj in self._processes.items()} processes_cls.update(processes) - return type(self)(processes_cls) - def drop_processes(self, keys): + new_c_deps = {p: deps for p, deps in self._custom_dependencies.items()} + for p, deps in custom_dependencies.items(): + deps = {deps} if isinstance(deps, str) else set(deps) + if p in new_c_deps: + new_c_deps[p].update(deps) + else: + new_c_deps[p] = deps + + if strict_order_check is None: + strict_order_check = self._strict_order_check + + return type(self)(processes_cls, new_c_deps, strict_order_check) + + def drop_processes(self, keys, strict_order_check=None): """Drop processe(s) from this model. Parameters