pyhf icon indicating copy to clipboard operation
pyhf copied to clipboard

fix: jax backend tolist for tracers in logging

Open pfackeldey opened this issue 9 months ago • 1 comments

Description

This PR closes https://github.com/scikit-hep/pyhf/issues/1422

This failure is encountered during tracing time. JAX can not convert a tracer during .tolist (because it has no data to put in a list) which is why it fails with a different error. This PR checks if we're currently in tracing time and instead returns the tracer (or rather its abstract value for a little nicer representation).

The new error looks as expected like this now:

>>> import pyhf
>>> pyhf.set_backend("jax")
>>> pyhf.simplemodels.uncorrelated_background([10], [15], [5])
>>> pyhf.infer.mle.fit([12.5], m)
>>> ... InvalidPdfData: "eval failed as data has len 1 but 2 was expected"

The logging will print:

"Eval failed for data ShapedArray(float64[1]) pars: ShapedArray(float64[2])"

This is the most information available during tracing time (shape and dtype), there's not much more to give to the user.

Checklist Before Requesting Reviewer

  • [x] Tests are passing
  • [x] "WIP" removed from the title of the pull request
  • [x] 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

pfackeldey avatar Mar 21 '25 21:03 pfackeldey

this likely needs #2566 in

kratsg avatar Mar 21 '25 21:03 kratsg

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 98.23%. Comparing base (10488f0) to head (f875bbf). :warning: Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2580   +/-   ##
=======================================
  Coverage   98.23%   98.23%           
=======================================
  Files          65       65           
  Lines        4193     4198    +5     
  Branches      591      592    +1     
=======================================
+ Hits         4119     4124    +5     
  Misses         45       45           
  Partials       29       29           
Flag Coverage Δ
contrib 97.97% <100.00%> (+<0.01%) :arrow_up:
doctest 98.09% <100.00%> (+<0.01%) :arrow_up:
unittests-3.10 96.28% <100.00%> (+<0.01%) :arrow_up:
unittests-3.11 96.28% <100.00%> (+<0.01%) :arrow_up:
unittests-3.12 96.28% <100.00%> (+<0.01%) :arrow_up:
unittests-3.8 96.28% <100.00%> (+<0.01%) :arrow_up:
unittests-3.9 96.33% <100.00%> (+<0.01%) :arrow_up:

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

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Oct 14 '25 20:10 codecov[bot]

I've addressed your comments @matthewfeickert, hope this test is what you were looking for.

pfackeldey avatar Oct 15 '25 08:10 pfackeldey

Peter, Can you also add the

Summarize commit messages into a comprehensive review of the PR

part in the PR body? (Sorry, missed that till now.)

matthewfeickert avatar Oct 15 '25 10:10 matthewfeickert

Thanks @pfackeldey! This will go into pyhf v0.8.0.

matthewfeickert avatar Oct 15 '25 12:10 matthewfeickert

Also thanks for your first (PR) contribution to pyhf! :smile:

matthewfeickert avatar Oct 15 '25 12:10 matthewfeickert