Skip to content

add numba version of schumaker spline - #2968

Open
cwhanse wants to merge 13 commits into
pvlib:mainfrom
cwhanse:schumaker
Open

cwhanse wants to merge 13 commits into
pvlib:mainfrom
cwhanse:schumaker

Conversation

@cwhanse

@cwhanse cwhanse commented Nov 29, 2026 •

Copy link
Copy Markdown
Member
  • Closes Speed up ivtools.utils._schumaker_qspline #2966
  • 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.

Adds a numba-capable version of _schumaker_qspline.

  • Extend the existing function to accommodate both 1D and 2D inputs.
  • Add a new kwarg use_numba.
  • A new output is needed (nknots) when using 2D inputs. The returned splines may have a different number of components for each row of data. Since the outputs are 2D and 3D arrays, they are padded with nan on the right. nknots tells you how many columns are valid data in each row. The adjustment to pvlib.ivtools.sde accommodates the new output. Output with 1D inputs includes the new output to avoid having the API depending on the input shape.

@cwhanse cwhanse added this to the v0.16.2 milestone Nov 30, 2026
@cwhanse cwhanse changed the title add numba version of schumaker and tests add numba version of schumaker spline Nov 30, 2026
@cwhanse

cwhanse commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Coverage shortfall is because codecov (as configured here) can't monitor lines inside a function that is just-in-time compiled for numba

@cwhanse

cwhanse commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Rough speed-up estimates. TL:DR after JIT penalty is paid, the numba speed-up is roughly 25x.

Two tests:

  • Fit 8760 splines each with 100 pts, provided as 2D input. This test represents a year of IV curve measurements.
  • Fit 87600 splines each with 100 pts, provided as 2D input (one year of measurements for 10 devices)

My target use case is to compute a year of IV curves for an array with both series and parallel mismatch. The algorithm fits a spline to each string's IV curve and uses the spline to combine strings to get the parallel IV curve. This use case probably involves 100k-ish spline fits for a year of modeling.

Table notes:

  • Numba uses the new 2d function
  • Numpy uses the new numpy-only function in this PR that handles 2D inputs for compatibility
  • pvlib is a loop that calls the current pvlib function with 1D inputs

Numbers are elapsed seconds.

Comparing the 1st and 2nd IDE executions shows the penalty for JIT compilation.

Numba

Implementation 8,760: 1st IDE 8,760: 2nd IDE 8,760: CLI 87,600: 1st IDE 87,600: 2nd IDE 87,600: CLI
Numba 1.7687 0.0451 0.2011 1.9875 0.3569 0.5086
Numpy 1.3331 1.3328 1.3930 14.0726 13.9278 13.7424
pvlib 1.2832 1.2922 1.4038 13.5344 13.5878 12.8079

@cwhanse
cwhanse marked this pull request as ready for review November 30, 2026 17:23
# run tests generated by original Matlab implementation
@requires_numba
@pytest.mark.parametrize('x,y,expected', [
(np.array([0., 1., 2., 3., 4., 1., 2., 3., 4., 5.]),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The first entry is removed since the new functions require the independent variable to be strictly increasing. The old function sorted.

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.

Speed up ivtools.utils._schumaker_qspline

1 participant