Skip to content

RuntimeWarning: invalid value encountered in divide when using singlediode() #2671

@jwhitaker-gridcog

Description

@jwhitaker-gridcog

Describe the bug
Since version 0.14, calling singediode() sometimes results in

/home/jarrad/src/.../.venv/lib/python3.12/site-packages/scipy/optimize/_chandrupatla.py:437: RuntimeWarning: invalid value encountered in divide
  C = A / (A + B)

To Reproduce

import pvlib
import numpy as np

pvlib.pvsystem.singlediode(0., 1e-12, 0.5, np.inf, 1.8)

Expected behavior
No warning.

Screenshots

Versions:

  • pvlib.__version__: 0.4.0
  • pandas.__version__: 2.3.
  • python: 3.12
  • numpy.__version__: 2.3.5
  • scipy.__version__: 1.17.0

Additional context

Poking a little bit, it looks like your call to scipy find_minimum may not obey the constraints they require. Scipy doco states (https://docs.scipy.org/doc/scipy-1.17.0/reference/generated/scipy.optimize.elementwise.find_minimum.html)

init:
The abscissae of a standard scalar minimization bracket. A bracket is valid if arrays x1, x2, x3 = init satisfy x1 < x2 < x3 and func(x1) >= func(x2) <= func(x3), where one of the inequalities is strict. Arrays must be broadcastable with one another and the arrays of args.

Looking at the PR where this was implemented, it looks like care was taken to obey the second invariant, but the first might have gotten missed. When you set init = (-1, 0.8*v_oc, v_oc), if v_oc == 0 then x2 < x3 gets broken. I haven't proven that this is the cause of the warning, but I am suspicious...

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions