question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RuntimeError while using the fit_desoto function, caused by optimize.root (SciPy)

See original GitHub issue

Hello everyone,

while using the fit_desoto function to estimate parameters for further solar module calculations, I received the following error:

RuntimeError: Parameter estimation failed: The iteration is not making good progress, as measured by the improvement from the last five Jacobian evaluations.

The error comes from the optimize.root function from the SciPy library, which is used within the fit_desoto function.

Even if I use only 1s for the initial values of the fit_desoto function, I get this error.

The code for the function call in the main programm:

self.mp_desoto_fit = pvlib.ivtools.sdm.fit_desoto(v_mp=module['Vmpo'], i_mp=module['Impo'], v_oc=module['Voco'], i_sc=module['Isco'], alpha_sc=module['Aisc'], beta_voc=module['Bvoco'], cells_in_series=module['Cells_in_Series'], EgRef=1.121, dEgdT=-0.0002677, temp_ref=25, irrad_ref=1000, root_kwargs={'options': {'col_deriv': 0, 'xtol': 1.49012e-05, 'maxfev': 0, 'band': None, 'eps': None, 'factor': 100, 'diag': None}}) The root_kwargs in the function call of the fit_desoto function influence the solver of the root function, but different properties for the solver don’t fix the problem.

To Reproduce the error You can easily reproduce the error by simply using the fit_desoto function. It doesn’t make a difference if you use concrete values of a photovoltaic cell or just 1s. All values after cells in series (8) are default values.

mp_desoto_fit_num = pvlib.ivtools.sdm.fit_desoto(4.568, 3.3, 5.36, 3.5, 0.0010, -0.0158, 8, EgRef=1.121, dEgdT=-0.0002677, temp_ref=25, irrad_ref=1000, root_kwargs={})

or

mp_desoto_fit_ones = pvlib.ivtools.sdm.fit_desoto(1, 1, 1, 1, 1, 1, 1, EgRef=1.121, dEgdT=-0.0002677, temp_ref=25, irrad_ref=1000, root_kwargs={})

When using those code examples the error message changes to:

RuntimeError: Parameter estimation failed: The iteration is not making good progress, as measured by the improvement from the last ten iterations.

Do you have any ideas on this issue?

What I already tried:

  • Checked all types of initial values for the fit_desoto function (temperature coefficients are handed over in [A/K]).

  • Choosed different options for the root function solver with the method ‘hybr’

  • Code debugged and checked the variables inside the root_function. No NaN values or similar arise while the function is calculating

Suggestions perhaps the problem could be solved by choosing a different method for the root function via the function call of fit_desoto. The kwargs of the fit_desoto function itself can only change the options of the solver, but not which method is used. The default method is “hybr” which is only one of several.

Thanks in advance!


Versions: numpy 1.20.2 pandas 1.2.4 pvlib 0.8.1 scipy 1.6.3 python 3.9.0

I am using Spyder and/or PyCharm

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
adriessecommented, May 14, 2021

I think the first problem in fit_desoto is that it raises an error and swallows the optimize_result. That makes it much harder to investigate. At most it should produce a warning.

1reaction
mikofskicommented, May 14, 2021

At most it should produce a warning.

similar dialogue over at scipy on similar issue, https://github.com/scipy/scipy/issues/8904#issuecomment-395143111, is it runtime error or warning?

I think the reason to issue a warning versus an error is so that the final result is returned. If you raise an error then you’ll know the solver terminated early, but not why. Note, when the warning is raised, the solver terminates and returns the last guess, it does not continue to iterate.

They opted for display=True & full_output=True to return warning and the reasons why, vs. False which raises error. AFAICT scipy.optimize.root(method='hybr') uses the MINPACK HYBR or HYBRJ solver depending on if the Jacobian is provided or not, and always returns an OptimizedResult with full output regardless of whether it converged or not. It’s up to the user to look at the condition of the result, which is what fit_desoto does here:

https://github.com/pvlib/pvlib-python/blob/5bdad64434ef4e432b893313e0858a02b02480b6/pvlib/ivtools/sdm.py#L228-L232

so if we change this, then we can get the output of the OptimizedResults

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while using the fit_desoto function, caused by optimize ...
while using the fit_desoto function to estimate parameters for further solar module calculations, I received the following error: RuntimeError: ...
Read more >
scipy.optimize.root — SciPy v1.9.3 Manual
A vector function to find a root of. ... It is called on every iteration as callback(x, f) where x is the current...
Read more >
Optimization and root finding (scipy.optimize)
SciPy optimize provides functions for minimizing (or maximizing) objective ... Find a root of a function in a bracketing interval using Brent's method....
Read more >
scipy.optimize.brentq — SciPy v1.9.3 Manual
Find a root of a function in a bracketing interval using Brent's method. Uses the classic Brent's method to find a zero of...
Read more >
scipy.optimize.bisect — SciPy v1.9.3 Manual
Find root of a function within an interval using bisection. Basic bisection routine to find a zero of the function f between the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found