eval_uncertainty() not working on loaded ModelResult

29 views
Skip to first unread message

Edric Choi

unread,
Aug 11, 2023, 3:46:26 PM8/11/23
to lmfit-py
Hi,

I'm getting the error: AttributeError("'ModelResult' object has no attribute 'components'") when I attempt to run eval_uncertainty() on a ModelResult object that's been loaded. Any clue if this is a bug in the way load_modelresult works? See below for code to recreate this error.

Thanks!
Edric

model = LinearModel()
result = model.fit(k_hydr_df['ln(k_hydr/T)'], params, x = k_hydr_df['1/T'], weights = k_hydr_df['weights'])
save_modelresult(result, "fit_hydrolysis/eyring/k_hydr.sav")
print(result.eval_uncertainty(x = k_hydr_df['1/T'])) # THIS WORKS

khydr_model = load_modelresult("fit_hydrolysis/eyring/k_hydr.sav")
print(khydr_model.eval_uncertainty(x = k_hydr_df['1/T'])) # THIS THROWS ATTRIBUTE ERROR


Matt Newville

unread,
Aug 11, 2023, 6:07:08 PM8/11/23
to lmfi...@googlegroups.com
Hi Edric, 

Oh, I can reproduce that.  To be clear, the exception I get is

  File "..../lmfit/model.py", line 1598, in eval_uncertainty
    for comp in self.components:

AttributeError: 'ModelResult' object has no attribute 'components'

And yes, that line should be 

    for comp in self.model.components:

It's sort of surprising that only gets exposed after loading a saved Model Result, but it is a bug.   We should add that fix, and a test.  

If you are interested and willing, you could raise this as an Issue on github, and even make a PR.





--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/87a05a08-8322-48f6-9344-b1c690fb1610n%40googlegroups.com.


Edric Choi

unread,
Aug 11, 2023, 9:46:43 PM8/11/23
to lmfit-py
Hi Matt,

Thanks for confirming this! I just raised an issue on github. Hope it gets resolved soon!

Edric

Reply all
Reply to author
Forward
0 new messages