Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Manually set uncertainties for fixed parameters to 0 #1919

Merged
merged 12 commits into from
Aug 9, 2022

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Jul 17, 2022

Description

Resolves #1918

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
* Manually set the uncertainties for fixed parameters to zero after minimization,
and remove setting the uncertainty/step_sizes during minimization, to avoid warnings
from iminuit. For iminuit v2.12.2+ "assigning zero to errors is invalid, but in the
past this was not caught." This approach harmonizes with cabinetry for fixed
parameters for iminuit v2.12.2+.
   - c.f. https://github.com/scikit-hep/iminuit/issues/762
   - c.f. https://github.com/scikit-hep/cabinetry/pull/346
   - c.f. https://iminuit.readthedocs.io/en/stable/changelog.html#july-15-2022
     > fix a bug in error heuristic when parameters have negative values and prevent
     > assigning negative values to errors
* Remove tests/test_optim.py test_step_sizes_fixed_parameters_minuit as the
uncertainties/step sizes values are no longer set during minimization and so are no
longer in pyhf's control.

@matthewfeickert matthewfeickert added the build Changes that affect the build system or external dependencies label Jul 17, 2022
@matthewfeickert matthewfeickert self-assigned this Jul 17, 2022
@matthewfeickert matthewfeickert changed the title Build/exclude iminuit 2 12 2 build: Disallow iminuit v2.12.2 given test_optim_uncerts regression Jul 17, 2022
@matthewfeickert matthewfeickert changed the title build: Disallow iminuit v2.12.2 given test_optim_uncerts regression build: Disallow iminuit v2.13.0 given test_optim_uncerts regression Jul 17, 2022
@codecov
Copy link

codecov bot commented Jul 17, 2022

Codecov Report

Merging #1919 (db7a7d7) into master (8e242c9) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1919      +/-   ##
==========================================
- Coverage   98.17%   98.17%   -0.01%     
==========================================
  Files          68       68              
  Lines        4331     4330       -1     
  Branches      730      729       -1     
==========================================
- Hits         4252     4251       -1     
  Misses         46       46              
  Partials       33       33              
Flag Coverage Δ
contrib 26.37% <75.00%> (+0.02%) ⬆️
doctest 60.66% <75.00%> (+0.03%) ⬆️
unittests-3.10 96.05% <100.00%> (-0.01%) ⬇️
unittests-3.7 96.03% <100.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
src/pyhf/optimize/opt_minuit.py 100.00% <ø> (ø)
src/pyhf/optimize/mixins.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@matthewfeickert matthewfeickert changed the title build: Disallow iminuit v2.13.0 given test_optim_uncerts regression fix: Add filterwarnings ignore for iminuit non-positive errors UserWarning Jul 17, 2022
@matthewfeickert matthewfeickert added tests pytest fix A bug fix and removed build Changes that affect the build system or external dependencies labels Jul 17, 2022
@matthewfeickert matthewfeickert changed the title fix: Add filterwarnings ignore for iminuit non-positive errors UserWarning build: Disallow iminuit v2.12.2 given uncertainty changes Jul 17, 2022
@matthewfeickert matthewfeickert added the build Changes that affect the build system or external dependencies label Jul 17, 2022
@matthewfeickert matthewfeickert changed the title build: Disallow iminuit v2.12.2 given uncertainty changes build: Disallow iminuit v2.13.0 given uncertainty changes Jul 17, 2022
@matthewfeickert
Copy link
Member Author

@kratsg @lukasheinrich I'm going to leave this in draft until I have enough time to look at this and scikit-hep/iminuit#762 and determine if the change in uncertainties is desired and create some minimal examples that demonstrate the differences.

@matthewfeickert matthewfeickert force-pushed the build/exclude-iminuit-2-12-2 branch 2 times, most recently from a9ca9ec to 795b697 Compare July 26, 2022 07:42
@matthewfeickert matthewfeickert changed the title build: Disallow iminuit v2.13.0 given uncertainty changes build: Update lower bound on iminuit to v2.12.2 Jul 27, 2022
@matthewfeickert matthewfeickert marked this pull request as ready for review July 27, 2022 05:48
Copy link
Member

@alexander-held alexander-held left a comment

Choose a reason for hiding this comment

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

Based on scikit-hep/iminuit#762 (comment),

step_sizes = [(b[1] - b[0]) / float(self.steps) for b in init_bounds]
could also in principle be removed I think (does not need to happen here, but came up in the same context, and presumably the effect is negligible).

I am not yet sure how to handle this in cabinetry but I am leaning towards going through the fit results and manually setting errors for fixed parameters to 0.0 again. I will put my motivation for that into scikit-hep/iminuit#762. It would be best to harmonize the behavior of pyhf and cabinetry though so I'm also interested to hear your thoughts on this so we can ideally agree on the approach.

@matthewfeickert matthewfeickert marked this pull request as draft August 8, 2022 20:12
@matthewfeickert matthewfeickert changed the title build: Update lower bound on iminuit to v2.12.2 fix: Manually set uncertainties for fixed parameters to 0 Aug 8, 2022
@matthewfeickert matthewfeickert removed the build Changes that affect the build system or external dependencies label Aug 8, 2022
@matthewfeickert matthewfeickert force-pushed the build/exclude-iminuit-2-12-2 branch from 1f7eb77 to f1e3bd3 Compare August 8, 2022 23:10
@matthewfeickert matthewfeickert added the build Changes that affect the build system or external dependencies label Aug 8, 2022
@matthewfeickert
Copy link
Member Author

Note to self in case needed in the future: Previous commit message summary was

UserWarning: Assigned errors must be positive. Non-positive values are replaced by a heuristic.

This was introduced in iminuit v2.12.2 as the result of a step size guess heuristic being applied to fixed parameters. This results in the error of fixed parameters changing during MIGRAD.

@matthewfeickert matthewfeickert marked this pull request as ready for review August 8, 2022 23:26
…rning

* Add a ignore to filterwarnings to avoid iminuit UserWarning:

> UserWarning: Assigned errors must be positive. Non-positive values are replaced by a heuristic.
* This was introduced in iminuit v2.12.2 as the result of a step size guess heuristic being applied to
fixed parameters. This results in the error of fixed parameters changing during MIGRAD.
   - c.f. iminuit Issue 762
…tprocess

Use tensorlib to work with all backends

Use np.where to reduce expensive casting as minuit is numpy-like
@matthewfeickert matthewfeickert force-pushed the build/exclude-iminuit-2-12-2 branch from 5344f79 to e3a01fd Compare August 9, 2022 04:19
Copy link
Member

@alexander-held alexander-held left a comment

Choose a reason for hiding this comment

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

I think the current implementation allows for leaving the iminuit version requirement unchanged. The change in 2.12.2 affects parameters with an assigned step size of zero. Since pyhf no longer sets a step size of zero to any parameters (and instead corrects the post-fit parameter uncertainties for fixed parameters now), iminuit versions before and after 2.12.2 should behave the same in combination with these changes to pyhf.

The one thing that might break, but for which I do not see a good solution, is user code that directly uses the Minuit instance, reads out .errors on that and gets a different behavior starting with 2.12.2. I don't think pyhf can (or should) do anything about that though.

@matthewfeickert
Copy link
Member Author

I think the current implementation allows for leaving the iminuit version requirement unchanged. The change in 2.12.2 affects parameters with an assigned step size of zero. Since pyhf no longer sets a step size of zero to any parameters (and instead corrects the post-fit parameter uncertainties for fixed parameters now), iminuit versions before and after 2.12.2 should behave the same in combination with these changes to pyhf.

The one thing that might break, but for which I do not see a good solution, is user code that directly uses the Minuit instance, reads out .errors on that and gets a different behavior starting with 2.12.2. I don't think pyhf can (or should) do anything about that though.

Yeah the only reason I included the version bump was to ensure that there could only be one behavior if the user tried to access Minuit.errors, but I think I agree that I'm trying to be too protective of the user in this instance and if they are running into this that we should just direct them to Issue scikit-hep/iminuit#762.

As pyhf no longer controls step size, then don't attempt to test for it
@alexander-held
Copy link
Member

Yeah the only reason I included the version bump was to ensure that there could only be one behavior if the user tried to access Minuit.errors

The behavior should still be the same with old and new versions, i.e. non-zero .errors for fixed parameters (since you're no longer setting the zero value before the fit). A change appears though for someone installing e.g. pyhf 0.6.3 with old and new versions of iminuit (I think that change cannot be prevented from the side of pyhf though).

@matthewfeickert
Copy link
Member Author

A change appears though for someone installing e.g. pyhf 0.6.3 with old and new versions of iminuit (I think that change cannot be prevented from the side of pyhf though).

Exactly. Though this [not being able to force users to install newer versions software] is what you, Henry, Hans, and Thomas have all reminded me about many times and that I have to let users make their own decisions.

@kratsg kratsg merged commit 355982a into master Aug 9, 2022
@kratsg kratsg deleted the build/exclude-iminuit-2-12-2 branch August 9, 2022 20:32
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
build Changes that affect the build system or external dependencies fix A bug fix tests pytest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CI failing for iminuit v2.12.2
4 participants