Skip to content

Commit

Permalink
do not pass model function into Parameters usersyms
Browse files Browse the repository at this point in the history
  • Loading branch information
cassberk committed Dec 21, 2023
1 parent b12fdb2 commit 120e0ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lmfit/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ def loads(self, s, funcdefs=None, **kws):
funcdefs : dict, optional
Dictionary of custom function names and definitions.
**kws : optional
Keyword arguments that are passed to `json.dumps`.
Keyword arguments that are passed to `json.loads`.
Returns
-------
Expand All @@ -1885,6 +1885,9 @@ def loads(self, s, funcdefs=None, **kws):
self.model = _buildmodel(decode4js(modres['model']), funcdefs=funcdefs)

# params
if funcdefs:
# Remove model function so as not pass it into the _asteval.symtable
funcdefs.pop(self.model.func.__name__, None)
for target in ('params', 'init_params'):
state = {'unique_symbols': modres['unique_symbols'], 'params': []}
for parstate in modres['params']:
Expand Down
2 changes: 2 additions & 0 deletions tests/test_model_saveload.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,10 @@ def expr_func(x):
result2 = ModelResult(model, Parameters())
result2.loads(result1.dumps(), funcdefs={'mfunc': mfunc, 'expr_func': expr_func})

assert result1.userfcn == result2.userfcn
assert result1.params == result2.params
assert result1.init_params == result2.init_params
assert set(result1.params._asteval.symtable) == set(result2.params._asteval.symtable)


def test_saveload_modelresult_eval_uncertainty():
Expand Down

0 comments on commit 120e0ff

Please sign in to comment.