Skip to content

PERF: reduce overhead in WVM wavelet computation - #2919

Open
dexhunter wants to merge 1 commit into
pvlib:mainfrom
dexhunter:perf/wavelet-rolling
Open

dexhunter wants to merge 1 commit into
pvlib:mainfrom
dexhunter:perf/wavelet-rolling

Conversation

@dexhunter

Copy link
Copy Markdown

_compute_wavelet builds a one-column DataFrame, fills missing values at every scale, and computes coefficients across padded regions that are discarded before returning. This change uses a Series for the same pandas rolling mean, fills only when the rolling result contains NaNs, and retains only the original time window for coefficient calculation. Slicing replaces the roll-and-crop operations, and adjacent-scale differences are calculated together.

On benchmarks.scaling.Scaling.time_wvm, time fell from 2.36 ms to 1.45 ms per call, about 39% less time (1.63× faster). The benchmark uses 1,000 samples at one-minute intervals, four sites, and cloud speed 5. Measurements used Python 3.12.13, NumPy 2.5.4, pandas 3.0.6, and SciPy 1.18.1 on isolated benchmark slots, with numerical-library thread counts set to one. These are local measurements, not a performance claim for every input size or dependency version.

The repository benchmark was invoked directly with Python's standard timeit runner because asv-lite was unavailable: best of seven repeats, 100 calls per repeat, with the same seeded setup in each checkout. From the checkout root, the measured invocation was:

python -m timeit -n 100 -r 7 -u msec \
  -s 'import numpy as np; np.random.seed(90210); from benchmarks.benchmarks.scaling import Scaling; bench = Scaling(); bench.setup()' \
  'bench.time_wvm()'

A separate frozen evaluator compared complete outputs exactly against the baseline, using fresh seeds and nine interleaved pairs of 40 repetitions. Three final candidate/baseline ratios were 0.613246, 0.609230, and 0.596677. This workload also includes three invalid-input probes, so those ratios are reported separately from the direct repository benchmark.

Validation:

  • python -m pytest tests/test_scaling.py -q: 18 passed.
  • 723 differential cases passed, covering NumPy and pandas inputs, multiple lengths and sampling intervals, missing values, infinities, signed zeros, numeric dtypes, strided arrays, timezone indexes, and exception classes/messages.
  • git diff --check passed.

Weco evaluated 20 distinct passing candidates. Step 1 was selected for maintainability: it uses public pandas APIs and preserves the existing rolling arithmetic and interval inference. Faster candidates depended on a private pandas kernel and duplicated fallback implementations.

AI assistance: Weco 0.3.40 with claude-opus-5-5 generated the optimization candidates; Codex reviewed the selected change, ran verification, and drafted this description. The generated material was reviewed for accuracy and compatibility with pvlib's BSD-3-Clause license. No new dependency or third-party implementation was added.

Weco share link: https://dashboard.weco.ai/share/xYRej-54aUL5RN2-yGcjfd1c8ZDyZAlo

  • 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

  • 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.

@github-actions

Copy link
Copy Markdown

Hey @dexhunter! 🎉

Thanks for opening your first pull request! We appreciate your
contribution. Please ensure you have reviewed and understood the
contributing guidelines.

If AI is used for any portion of this PR, you must vet the content
for technical accuracy.

Finally, be sure the PR description includes the PR
checklist,
and complete the items you are able to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant