Skip to content

Conversation

@matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Apr 18, 2024

Description

Resolves #2466

As toms748_scan uses caching of results it requires that the results are hashable objects, which arrays are not. So to keep using this approach convert to floats as needed.

Add testing for all backends for the upper limits inference tests.

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
* In pyhf.infer.intervals.upper_limits.toms748_scan a caching approach to a dict
  is used. This requires that the objects cached are hashable, but generic
  ndarrays are not. To avoid this problem, cast single value tensors to floats
  as needed.
* Use pyhf.tensorlib.transpose to support TensorFlow, as the `.T` operator is not
  supported.
* Add testing of all backends to the toms748_scan and upper_limit tests in 
  tests/test_infer.py.
   - Add notes to change tests after TensorFlow support is dropped.

@matthewfeickert matthewfeickert added tests pytest fix A bug fix need-to-backport tmp label until can be backported to patch release branch labels Apr 18, 2024
@matthewfeickert matthewfeickert self-assigned this Apr 18, 2024
)

assert observed_limit == pytest.approx(observed_limit_default)
# FIXME: Remove float cast after TensorFlow support removed
Copy link
Member Author

Choose a reason for hiding this comment

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

@kratsg Running the TensorFlow tests is very slow and adds minutes to this run. As we're going to be dropping TensorFlow in the future, I think that we could probably just skip TensorFlow in these tests. Thoughts?

@matthewfeickert matthewfeickert requested a review from kratsg April 18, 2024 06:53
@matthewfeickert
Copy link
Member Author

CI is currently failing for Apple silicon macOS.

@codecov
Copy link

codecov bot commented Apr 18, 2024

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.21%. Comparing base (64ab264) to head (e815612).
⚠️ Report is 61 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2467   +/-   ##
=======================================
  Coverage   98.21%   98.21%           
=======================================
  Files          69       69           
  Lines        4543     4546    +3     
  Branches      804      805    +1     
=======================================
+ Hits         4462     4465    +3     
  Misses         48       48           
  Partials       33       33           
Flag Coverage Δ
contrib 97.80% <100.00%> (+<0.01%) ⬆️
doctest 98.08% <100.00%> (+<0.01%) ⬆️
unittests-3.10 ?
unittests-3.11 ?
unittests-3.12 96.23% <100.00%> (+<0.01%) ⬆️
unittests-3.8 96.26% <100.00%> (+<0.01%) ⬆️
unittests-3.9 ?

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.

return __all__


def _interp(x, xp, fp):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def _interp(x, xp, fp):
def _interp(x, xp: list[float], fp):

def _interp(x, xp, fp):
tb, _ = get_backend()
return tb.astensor(np.interp(x, xp.tolist(), fp.tolist()))
# xp has already been turned into a list at this point
Copy link
Contributor

Choose a reason for hiding this comment

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

can drop this comment with a typehint above as suggested

@matthewfeickert matthewfeickert deleted the fix/make-toms748_scan-compatible-with-all-backends branch October 13, 2025 09:08
@github-project-automation github-project-automation bot moved this from In progress to Done in pyhf v0.8.0 Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A bug fix need-to-backport tmp label until can be backported to patch release branch tests pytest

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

toms748_scan doesn't work with JAX backend

3 participants