Skip to content

Commit

Permalink
update_processes and clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Joeperdefloep committed Mar 25, 2021
1 parent c8b0edd commit 38d4131
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions xsimlab/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1206,16 +1206,25 @@ 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
----------
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
-------
Expand All @@ -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
Expand Down

0 comments on commit 38d4131

Please sign in to comment.