diff --git a/CHANGELOG.md b/CHANGELOG.md index 554039050a..a5cb664c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Features +- Added functionality to initialize a model using the solution from another model ([#1278](https://github.com/pybamm-team/PyBaMM/pull/1278)) - Added submodels for active material ([#1262](https://github.com/pybamm-team/PyBaMM/pull/1262)) - Added composite surface form electrolyte models: `CompositeDifferential` and `CompositeAlgebraic` ([#1207](https://github.com/pybamm-team/PyBaMM/issues/1207)) @@ -11,6 +12,7 @@ ## Bug fixes +- Fixed `Simulation` and `model.new_copy` to fix a bug where changes to the model were overwritten ([#1278](https://github.com/pybamm-team/PyBaMM/pull/1278)) ## Breaking changes - Operations such as `1*x` and `0+x` now directly return `x`. This can be bypassed by explicitly creating the binary operators, e.g. `pybamm.Multiplication(1, x)` ([#1252](https://github.com/pybamm-team/PyBaMM/pull/1252)) diff --git a/pybamm/expression_tree/operations/replace_symbols.py b/pybamm/expression_tree/operations/replace_symbols.py index 1b54addbd3..34f60aa573 100644 --- a/pybamm/expression_tree/operations/replace_symbols.py +++ b/pybamm/expression_tree/operations/replace_symbols.py @@ -138,7 +138,7 @@ def process_boundary_conditions(self, model): if err.args[0] in side: pass # do raise error otherwise (e.g. can't process symbol) - else: + else: # pragma: no cover raise KeyError(err) return new_boundary_conditions @@ -170,11 +170,6 @@ def process_symbol(self, symbol): def _process_symbol(self, symbol): """ See :meth:`Simplification.process_symbol()`. """ - if not any( - x.id in self._symbol_replacement_map_ids.keys() for x in symbol.pre_order() - ): - return symbol.new_copy() - if symbol.id in self._symbol_replacement_map_ids.keys(): return self._symbol_replacement_map_ids[symbol.id] @@ -202,10 +197,8 @@ def _process_symbol(self, symbol): return symbol._concatenation_new_copy(new_children) else: - if not any( - x.id in self._symbol_replacement_map_ids.keys() - for x in symbol.pre_order() - ): - return symbol.new_copy() - else: - raise NotImplementedError + # Only other option is that the symbol is a leaf (doesn't have children) + # In this case, since we have already ruled out that the symbol is one of + # the symbols that needs to be replaced, we can just return a new copy of + # the symbol + return symbol.new_copy()