Skip to content

fix: correctly pass parameters to sample from alternative#190

Merged
jonas-eschle merged 4 commits intomainfrom
fix/hypothesis_toys
Nov 24, 2025
Merged

fix: correctly pass parameters to sample from alternative#190
jonas-eschle merged 4 commits intomainfrom
fix/hypothesis_toys

Conversation

@jonas-eschle
Copy link
Member

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.39%. Comparing base (9f8cbb9) to head (1c401ce).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #190   +/-   ##
=======================================
  Coverage   92.38%   92.39%           
=======================================
  Files          26       26           
  Lines        1274     1275    +1     
=======================================
+ Hits         1177     1178    +1     
  Misses         97       97           
Flag Coverage Δ
unittests 92.39% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@jonas-eschle jonas-eschle requested a review from Copilot November 24, 2025 16:20
@jonas-eschle jonas-eschle merged commit 89ea7a7 into main Nov 24, 2025
18 checks passed
@jonas-eschle jonas-eschle deleted the fix/hypothesis_toys branch November 24, 2025 16:23
Copy link

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 PR fixes a critical bug in toy generation where parameters were not being correctly passed to zfit samplers. The root cause was that zfit samplers ignore the current parameter state set via context managers and require parameters to be passed directly via the param_values argument. The fix also includes updates for NumPy compatibility and adds comprehensive regression tests for simultaneous fits.

  • Fixes parameter passing to samplers by replacing context manager with direct param_values argument
  • Adds parameter filtering for simultaneous fit scenarios where different samplers use different parameters
  • Updates NumPy API usage from deprecated tostring() to tobytes() for hash computation
  • Switches test assertions from assert_array_equal to assert_allclose for floating point comparisons

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/hepstats/utils/fit/sampling.py Core fix: replaces set_values() context manager with direct param_values passing and adds parameter filtering for simultaneous fits
src/hepstats/hypotests/parameters.py Updates deprecated NumPy method from tostring() to tobytes() in hash function
tests/hypotests/test_calculators.py Adds regression test to verify toys are generated at specified POI values, not data's best fit
test_simultaneous_fit.py Comprehensive test suite for simultaneous fits with various parameter sharing scenarios
tests/modeling/test_bayesianblocks.py Changes assertions from assert_array_equal to assert_allclose for floating point tolerance

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

s.resample() # do not pass parameters as arguments as it will fail in simultaneous fits
for s in samplers:
# Filter params to only those relevant to this sampler (for simultaneous fits)
sampler_param_names = set(s.params.keys())
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The sampler_param_names set is computed inside the ntoys loop (line 60) but only depends on the sampler s, not the iteration variable i. This means the same computation is repeated unnecessarily for each toy. Consider computing this once per sampler before the loop to improve performance, especially when generating many toys.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants