Skip to content

Use hmf's Yung24 fitting function directly in HMF test#740

Open
steven-murray wants to merge 3 commits into
mainfrom
fix/yung24-hmf-test
Open

Use hmf's Yung24 fitting function directly in HMF test#740
steven-murray wants to merge 3 commits into
mainfrom
fix/yung24-hmf-test

Conversation

@steven-murray

@steven-murray steven-murray commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

  • hmf v3.6.2 added the Yung+24 halo mass function fit (previously only available on our end via hand-copied coefficients). This replaces the duplicated YUNG24_PHYSICAL_PARAMS dict and inlined polynomial formula in test_new_hmf_matches_reference with a direct call to hmf.mass_function.fitting_functions.Yung24, matching the approach already used for REED07.
  • Bumps the hmf dependency to >=3.6.2 in setup.py, since that's the first version with the Yung24 fit.

Fixes #710

Test plan

  • pytest tests/test_cfuncs.py -k test_new_hmf_matches_reference passes for both REED07 and YUNG24 branches (EH/BBKS power spectra).
  • Full pytest tests/test_cfuncs.py passes (84 passed, 4 pre-existing xfails).
  • ruff check/pre-commit hooks pass.

🤖 Generated with Claude Code

Summary by Sourcery

Replace hand-coded Yung24 halo mass function implementation in tests with direct use of hmf's Yung24 fitting function and bump the hmf dependency version accordingly.

Enhancements:

  • Use hmf.mass_function.fitting_functions.Yung24 directly in the halo mass function reference test instead of duplicated polynomial parameters.

Build:

  • Increase required hmf version to >=3.6.2 in setup.py to ensure availability of the Yung24 fitting function.

hmf v3.6.2 added the Yung+24 mass function fit, so the hand-copied
polynomial coefficients and formula in test_new_hmf_matches_reference
can be replaced with a direct call to hmf's own Yung24 class, avoiding
duplicated fit parameters. Bumps the hmf dependency accordingly.

Fixes #710

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@steven-murray steven-murray added the type: testing Testing improvements label Jul 7, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors the YUNG24 branch of the HMF reference test to use hmf’s built-in Yung24 fitting function instead of a hand-maintained polynomial implementation, and bumps the hmf dependency to the first version that provides that fitter.

Sequence diagram for using hmf Yung24 fitter in HMF test

sequenceDiagram
    participant Test as test_new_hmf_matches_reference
    participant HMF as hmf
    participant Y24 as Yung24

    Test->>HMF: mass_function.fitting_functions.Yung24
    activate HMF
    HMF->>Y24: __call__(mass, redshift, cosmology)
    activate Y24
    Y24-->>HMF: halo_mass_function
    deactivate Y24
    HMF-->>Test: reference_hmf
    deactivate HMF
Loading

File-Level Changes

Change Details Files
Replace hand-coded YUNG24 fit implementation in tests with direct use of hmf.mass_function.fitting_functions.Yung24.
  • Remove local YUNG24_PHYSICAL_PARAMS coefficient dictionary and associated redshift-dependent polynomial evaluation.
  • Import Yung24 from hmf.mass_function.fitting_functions and instantiate it in the YUNG24 test branch using nu2, z, delta_c, and physical units.
  • Use yung24.fsigma to compute the expected dn/dM and compare against the MassFunction output, preserving the existing dlnsdlnm / masses structure and tolerances.
tests/test_cfuncs.py
Bump hmf dependency minimum version to ensure availability of the Yung24 fitter.
  • Increase hmf minimum version from 3.6.0 to 3.6.2 in setup.py install_requires.
  • Update duplicated hmf requirement in setup.py’s extra requirements to match the new minimum version.
setup.py

Assessment against linked issues

Issue Objective Addressed Explanation
#710 Update the Yung+24 halo mass function test to use hmf's built-in Yung24 fitting function instead of a local/hand-copied implementation.
#710 Ensure the package depends on an hmf version that includes the Yung24 fitting function.

Possibly linked issues

  • #(unassigned): PR replaces custom Yung+24 implementation in tests with hmf.mass_function.fitting_functions.Yung24 and updates hmf version.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The hmf>=3.6.2 requirement is duplicated in two separate lists in setup.py; consider defining it once (e.g., a variable or shared requirement list) to avoid divergence if it needs to be updated again.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `hmf>=3.6.2` requirement is duplicated in two separate lists in `setup.py`; consider defining it once (e.g., a variable or shared requirement list) to avoid divergence if it needs to be updated again.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Addresses Sourcery review feedback on PR #740.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@steven-murray

Copy link
Copy Markdown
Member Author

Addressed the duplicated hmf>=3.6.2 requirement — factored it into a single HMF_REQ constant used by both test_req and install_requires in setup.py (e33e4fc).

🤖 Addressed by Claude Code

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

@steven-murray

Copy link
Copy Markdown
Member Author

Re the Codecov "JUnit XML file not found" warning: this is a downstream symptom, not something introduced by this PR. The "Run Unit Tests" CI step is failing, which causes "Run Integration Tests" (where junit.xml is generated) to be skipped.

I compared the failing tests on this branch against the tip of main (3c61b22) and the failure set is identical — same 34 tests, same astropy.units.errors.UnitConversionError ('m / s' vs dimensionless). This is a pre-existing, repo-wide CI breakage unrelated to the files this PR touches (setup.py, tests/test_cfuncs.py); none of the failures are in the Yung24/hmf test changes here. Leaving it out of scope for this PR — it looks like a separate astropy-related regression across several unrelated test files (test_h5.py, test_classy_interface.py, test_global_initialization.py, test_rsds.py, etc.).

🤖 Addressed by Claude Code

Comment thread tests/test_cfuncs.py Outdated

@jordanflitter jordanflitter left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @steven-murray, I made a minor comment.

The tests are failing because of astropy v8. I fixed that in #737 by modifying line 288 in classy_interfrace.py, see https://github.com/21cmfast/21cmFAST/pull/737/changes#diff-010c965001daef1fe0c45b5b8e24e3c87b2c1168c638a8846c97948d9a0e9765.

Also, shouldn't this branch be rebased on top of release-v4.3? I think it should.

I approved it anyways :)

Both fits are now available directly via hmf's MassFunction (matched
transfer function, growth model, and cosmology), so the separate
PS-growth-calibration codepath for YUNG24 is no longer needed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: testing Testing improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Yung+24 test to use hmf directly

2 participants