From 2a69147ed4ffdd3b7e3402a185bc6d7faca7d686 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Thu, 28 Sep 2023 15:43:55 +0200 Subject: [PATCH] remove slot reference in parameter.get_state; fixes #125 --- src/nmreval/fit/parameter.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/nmreval/fit/parameter.py b/src/nmreval/fit/parameter.py index c68b8d0..2aaeb0b 100644 --- a/src/nmreval/fit/parameter.py +++ b/src/nmreval/fit/parameter.py @@ -307,11 +307,25 @@ class Parameter: self.error = value * self.scale def get_state(self) -> dict: - return {slot: getattr(self, slot) for slot in self.__slots__} + state_dict = { + 'name': self.name, + 'value': self._value, + 'error': self.error, + 'init_val': self.init_val, + 'var': self.var, + 'lb': self.lb, + 'ub': self.ub, + 'scale': self.scale, + 'function': self.function, + '_expr': self._expr, + '_expr_disp': self._expr_disp, + 'is_global': self.is_global, + } + return state_dict @staticmethod def set_state(state: dict) -> Parameter: - par = Parameter(state.pop('value')) + par = Parameter(state.get('name'), state.pop('value')) for k, v in state.items(): setattr(par, k, v)