Skip to content

use _lambertw_pvlib etc.#2732

Merged
kandersolar merged 8 commits intopvlib:mainfrom
cwhanse:use_lambertw
Apr 16, 2026
Merged

use _lambertw_pvlib etc.#2732
kandersolar merged 8 commits intopvlib:mainfrom
cwhanse:use_lambertw

Conversation

@cwhanse
Copy link
Copy Markdown
Member

@cwhanse cwhanse commented Apr 8, 2026

  • Closes #xxxx
  • I am familiar with the contributing guidelines
  • I attest that all AI-generated material has been vetted for accuracy and is in compliance with the pvlib license
  • Tests added
  • Updates entries in docs/sphinx/source/reference for API changes.
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

Replace calls to scipy.special.lambertw with ivtools.utils._lambertw_pvlib

@kandersolar kandersolar added this to the v0.15.1 milestone Apr 8, 2026
@kandersolar
Copy link
Copy Markdown
Member

sdm/_fit_deosoto_pvsyst_sandia.py and sdm/desoto.py use scipy.special.lambertw. Worth replacing there as well?

Comment thread pvlib/singlediode.py Outdated
Comment thread pvlib/singlediode.py Outdated
@kandersolar
Copy link
Copy Markdown
Member

Some brief, noisy, non-comprehensive testing shows significant speed-ups. Here's the ratio of runtimes of PR and v0.13.1, for simulations of ~1e6:

singlediode    0.309317
i_from_v       1.068197
v_from_i       0.237070

@kandersolar
Copy link
Copy Markdown
Member

Seems like this warning is commonly (always?) emitted now:

pvlib-python\pvlib\ivtools\utils.py:563: RuntimeWarning: invalid value encountered in subtract
  w = logx - np.log(logx)  # initial guess, w = log(x) - log(log(x))

Here's a reproducer:

import pvlib
cec = pvlib.pvsystem.retrieve_sam('cecmod')
sdm_params = cec['Canadian_Solar_Inc__CS1U_400MS']
sdm_params = sdm_params[['alpha_sc', 'a_ref', 'I_L_ref', 'I_o_ref', 'R_sh_ref', 'R_s', 'Adjust']]
sde_params = pvlib.pvsystem.calcparams_cec(1000, 25, **sdm_params)
iv = pvlib.pvsystem.singlediode(*sde_params)

@cwhanse
Copy link
Copy Markdown
Member Author

cwhanse commented Apr 9, 2026

Seems like this warning is commonly (always?) emitted now:

pvlib-python\pvlib\ivtools\utils.py:563: RuntimeWarning: invalid value encountered in subtract
  w = logx - np.log(logx)  # initial guess, w = log(x) - log(log(x))

This is happening because overflow arguments are passed into _lambertw_pvlib here:

        # Record indices where lambertw input overflowed
        idx_inf = np.isinf(argW)

        lambertwterm = _lambertw_pvlib(argW)

@echedey-ls
Copy link
Copy Markdown
Member

sdm/_fit_deosoto_pvsyst_sandia.py and sdm/desoto.py use scipy.special.lambertw. Worth replacing there as well?

Is pvlib/pvarray.py also eligible for updating? See

# Eq 9-10
del0 = (1 - beta_voc * t0) / (50.1 - alpha_sc * t0)
w0 = np.real(lambertw(np.exp(1/del0 + 1)))

Copy link
Copy Markdown
Member

@kandersolar kandersolar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kandersolar kandersolar merged commit 44cb79f into pvlib:main Apr 16, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants