Skip to content

Remove spline interpolation for pivot approximations#73

Open
lukashergt wants to merge 4 commits into
masterfrom
remove_spline_interpolation_for_pivot_approximations
Open

Remove spline interpolation for pivot approximations#73
lukashergt wants to merge 4 commits into
masterfrom
remove_spline_interpolation_for_pivot_approximations

Conversation

@lukashergt
Copy link
Copy Markdown
Owner

@lukashergt lukashergt commented Dec 9, 2025

First we remove the spline interpolation of the slow-roll PPS approximation for the LLMS and ARBDS approximations, which do not require interpolation, since they are simply expanded around the pivot scale.

Second, this might lead us to a way of using these types of approximations in situations where the integration fails.

Checklist:

  • I have performed a self-review of my own code.
  • My code is PEP8 compliant (flake8 --max-line-length 99 primpy tests).
  • My code contains compliant docstrings (pydocstyle --convention=numpy primpy).
  • New and existing unit tests pass locally with my changes (python -m pytest).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have appropriately incremented the semantic version number in both README.rst and primpy/__version__.py.

…, which are pure expansions around the pivot scale, so they do not require interpolation; additionally provide the respective estimates of `n_s` and `n_run` etc. of these approximations
@lukashergt lukashergt self-assigned this Dec 9, 2025
@lukashergt lukashergt added the enhancement New feature or request label Dec 9, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.08%. Comparing base (eacd348) to head (14bba1f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #73      +/-   ##
==========================================
- Coverage   99.09%   99.08%   -0.01%     
==========================================
  Files          19       19              
  Lines        2439     2415      -24     
==========================================
- Hits         2417     2393      -24     
  Misses         22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request removes spline interpolation from the LLMS and ARBDS slow-roll approximation methods for primordial power spectra. The key changes are:

  • Direct evaluation: Replaced spline interpolation with direct lambda function evaluation since these approximations are polynomial expansions around the pivot scale
  • New attributes: Added method-specific attributes (A_s_LLMS, n_s_LLMS, r_LLMS, etc., and similar for ARBDS3) for the spectral parameters
  • Test coverage: Extended tests to verify the new attributes and compare between different approximation methods
  • Version bump: Incremented from 2.18.1 to 2.18.2

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
primpy/inflation.py Removed spline interpolation from LLMS and ARBDS methods; changed function signatures to remove **interp1d_kwargs; added direct lambda functions for power spectra; added new spectral parameter attributes
tests/test_inflation.py Added assertions to test new LLMS and ARBDS3 spectral attributes; added cross-comparison tests between different approximation methods
primpy/version.py Version incremented from 2.18.1 to 2.18.2
README.rst Documentation version updated to match code version

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread primpy/inflation.py
Comment on lines +1412 to +1414
# n_s = lambda k: (1 + bs1
# + bs2 * np.log(k/K_STAR)
# + bs3/2 * np.log(k/K_STAR)**2
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

This commented code appears to be incomplete or leftover from development. It has an incomplete lambda definition without a closing parenthesis and no clear purpose. Consider removing it if it's not needed, or completing it if it serves a documentation purpose.

Suggested change
# n_s = lambda k: (1 + bs1
# + bs2 * np.log(k/K_STAR)
# + bs3/2 * np.log(k/K_STAR)**2

Copilot uses AI. Check for mistakes.
Comment thread primpy/inflation.py
sol.logk2logP_t = logk2logP_t_3

def derive_approx_power_LLMS(**interp1d_kwargs):
def derive_approx_power_LLMS():
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The function signature was changed to remove **interp1d_kwargs parameter, but the caller at line 874 in derive_approx_power() still passes **interp1d_kwargs. This will cause a TypeError: derive_approx_power_LLMS() got an unexpected keyword argument when method='LLMS' is used.

The same issue exists at lines 1470 and 1524 where **interp_kwargs is passed.

Suggested change
def derive_approx_power_LLMS():
def derive_approx_power_LLMS(**interp1d_kwargs):

Copilot uses AI. Check for mistakes.
Comment thread primpy/inflation.py
sol.logk2logP_t = logk2logP_t_STE

def derive_approx_power_ARBDS(order=3, **interp1d_kwargs):
def derive_approx_power_ARBDS(order=3):
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

The function signature was changed to remove **interp1d_kwargs parameter, but the caller at line 878 in derive_approx_power() still passes **interp1d_kwargs. This will cause a TypeError: derive_approx_power_ARBDS() got an unexpected keyword argument when method='ARBDS' is used.

The same issue exists at lines 1478 and 1532 where **interp_kwargs is passed.

Copilot uses AI. Check for mistakes.
Comment thread primpy/inflation.py
Comment on lines +1354 to +1357
sol.P_s_approx_ARBDS2 = lambda k: Ps0 * (as0
+ as1 * np.log(k/K_STAR)
+ as2 * np.log(k/K_STAR)**2)
sol.P_t_approx_ARBDS2 = lambda k: Pt0 * (at0
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

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

Variable shadowing issue: The variables as0, at0, as1, at1, as2, and at2 defined here for order 2 will be overwritten by the order 3 definitions at lines 1362-1367. Since Python lambdas capture variables by reference (late binding), the lambdas sol.P_s_approx_ARBDS2 and sol.P_t_approx_ARBDS2 defined at lines 1354-1359 will incorrectly use the order 3 values when called, not the order 2 values.

This will cause incorrect results when using order=2. To fix this, either use default arguments in the lambda to capture the current values (e.g., lambda k, as0=as0, as1=as1, as2=as2: ...) or use different variable names for each order.

Suggested change
sol.P_s_approx_ARBDS2 = lambda k: Ps0 * (as0
+ as1 * np.log(k/K_STAR)
+ as2 * np.log(k/K_STAR)**2)
sol.P_t_approx_ARBDS2 = lambda k: Pt0 * (at0
sol.P_s_approx_ARBDS2 = lambda k, as0=as0, as1=as1, as2=as2: Ps0 * (as0
+ as1 * np.log(k/K_STAR)
+ as2 * np.log(k/K_STAR)**2)
sol.P_t_approx_ARBDS2 = lambda k, at0=at0, at1=at1, at2=at2: Pt0 * (at0

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants