Skip to content

Commit

Permalink
bug fix and backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Aypac committed Apr 20, 2018
1 parent 967df59 commit d10a4b4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions pycqed/analysis_v2/base_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ def save_fit_results(self):
# Delete the old group and create a new group (overwrite).
del analysis_group[fr_key]
fr_group = analysis_group.create_group(fr_key)

write_dict_to_hdf5(self._convert_dict_rec(self.fit_res), entry_point=fr_group)
write_dict_to_hdf5(self.fit_res, entry_point=fr_group)

@staticmethod
def _convert_dict_rec(obj):
Expand All @@ -533,22 +532,28 @@ def _convert_dict_rec(obj):
for k in obj:
obj[k] = BaseDataAnalysis._convert_dict_rec(obj[k])
except TypeError:
if type(obj) is lmfit.model.ModelResult:
obj = _flatten_lmfit_modelresult(obj)
if isinstance(obj, lmfit.model.ModelResult):
obj = BaseDataAnalysis._flatten_lmfit_modelresult(obj)
else:
obj = str(obj)
return obj

@staticmethod
def _flatten_lmfit_modelresult(model):
assert type(model) is lmfit.model.ModelResult
dic = {}
dic = model.best_values or {} # to keep compatibility with the old implementation

used_fields = ['success', 'message', 'best_values', 'params']
if sum([1 for k in model.best_values if k in used_fields]) > 0:
raise Warning('None of the params of the fit should be named any of this: ' + str(used_fields))

dic['success'] = model.success
dic['message'] = model.message
dic['best_values'] = model.best_values
dic['params'] = {}
for param_name in res.params:
for param_name in model.params:
dic['params'][param_name] = {}
param = res.params[param_name]
param = model.params[param_name]
for k in param.__dict__:
if not k.startswith('_'):
dic['params'][param_name][k] = getattr(param, k)
Expand Down

0 comments on commit d10a4b4

Please sign in to comment.