remove slot reference in parameter.get_state; fixes #125

This commit is contained in:
Dominik Demuth 2023-09-28 15:43:55 +02:00
parent 902a35b71a
commit 2a69147ed4

View File

@ -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)