Skip to content

feat: create a warning when fitted parameter is at the bounds#2526

Open
kratsg wants to merge 6 commits into
mainfrom
feat/warningParBoundsHits
Open

feat: create a warning when fitted parameter is at the bounds#2526
kratsg wants to merge 6 commits into
mainfrom
feat/warningParBoundsHits

Conversation

@kratsg
Copy link
Copy Markdown
Contributor

@kratsg kratsg commented Jun 26, 2024

Pull Request Description

Resolves #2525.

When nuisance parameters hit their bounds during fitting (e.g. in a large-model toy run), there was previously no indication that this had happened, making it difficult to diagnose suspect fit results. This PR adds a WARNING log message from _internal_postprocess whenever a fitted parameter lands exactly on a bound, reporting the parameter index, the fitted value, and the bound range.

The implementation iterates over the free parameters in fitresult.x alongside their bounds (both already stripped of fixed parameters by shim() before optimization). Three architectural concerns (batching, fixed-parameter skipping, and backend compatibility) were investigated (using CLAUDE) and confirmed to be non-issues given the current design; a clarifying comment documents why the alignment is guaranteed.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Add a WARNING log message in _internal_postprocess when a fitted
  parameter lands exactly on a bound. Reports the parameter index, 
  fitted value, and bound range.
* Add regression tests for lower bound, upper bound, and interior
  cases via _internal_postprocess directly with a synthetic
  OptimizeResult, making the check independent of optimizer
  floating-point behaviour.

@matthewfeickert matthewfeickert force-pushed the feat/warningParBoundsHits branch from 071c32a to 33c3a54 Compare April 7, 2026 07:57
@kratsg kratsg force-pushed the feat/warningParBoundsHits branch from 350b577 to 61bd40a Compare April 11, 2026 05:22
@kratsg kratsg marked this pull request as ready for review April 11, 2026 05:35
@kratsg kratsg self-assigned this Apr 11, 2026
@kratsg kratsg added feat/enhancement New feature or request user request Request coming form a pyhf user labels Apr 11, 2026
@github-project-automation github-project-automation Bot moved this to In progress in pyhf v0.8.0 Apr 11, 2026
@kratsg kratsg requested a review from matthewfeickert April 11, 2026 05:36
@kratsg kratsg force-pushed the feat/warningParBoundsHits branch from 51317ec to 790c148 Compare April 11, 2026 06:23
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.28%. Comparing base (24b1013) to head (30b9727).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2526   +/-   ##
=======================================
  Coverage   98.28%   98.28%           
=======================================
  Files          65       65           
  Lines        4305     4308    +3     
  Branches      465      467    +2     
=======================================
+ Hits         4231     4234    +3     
  Misses         46       46           
  Partials       28       28           
Flag Coverage Δ
contrib 98.16% <100.00%> (+<0.01%) ⬆️
doctest 98.28% <100.00%> (+<0.01%) ⬆️
unittests-3.10 96.47% <100.00%> (+<0.01%) ⬆️
unittests-3.11 96.47% <100.00%> (+<0.01%) ⬆️
unittests-3.12 96.47% <100.00%> (+<0.01%) ⬆️
unittests-3.13 96.47% <100.00%> (+<0.01%) ⬆️
unittests-3.9 96.54% <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.

kratsg and others added 6 commits April 11, 2026 15:49
Clean up the rough draft: unpack (lower, upper) from each bound for
clarity, fix to use % style logging rather than f-string, and improve
the warning message to include the fitted value and both bound values.
Add regression tests for lower bound, upper bound, and interior cases
using _internal_postprocess directly with a synthetic OptimizeResult
so the check is independent of optimizer floating-point behaviour.

Closes #2525

Co-Authored-By: Giordon Stark <kratsg@gmail.com>
…ound check

The three TODOs around the at-bounds warning loop are all safe to
resolve: batching is not yet implemented (fitresult.x is always 1D),
fixed parameters are already excluded because shim() strips them from
both fitresult.x and par_bounds before optimization, and the in-tuple
comparison is safe across all backends since fitresult.x is always a
numpy array from scipy/iminuit. Replace the TODOs with an explanatory
comment documenting why the alignment is guaranteed.

Co-Authored-By: Giordon Stark <kratsg@gmail.com>
@kratsg kratsg force-pushed the feat/warningParBoundsHits branch from 59108a3 to 30b9727 Compare April 11, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat/enhancement New feature or request user request Request coming form a pyhf user

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

Warn when parameter hits bounds

1 participant