Skip to content

Conversation

pfackeldey
Copy link
Contributor

@pfackeldey pfackeldey commented Mar 21, 2025

Description

Resolves #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")
>>> m = 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

  • 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

Commit message summary:

* JAX can not convert a tracer during .tolist (because it has no data to put in a list).
  This fix checks if JAX is currently in tracing time and instead returns the tracer
  (or rather its abstract value for a little nicer representation). This preserves the
  same error message as for the NumPy backend in case there's a shape mismatch in data.
* Add Peter Fackeldey to contributors list.

@kratsg
Copy link
Contributor

kratsg commented Mar 21, 2025

this likely needs #2566 in

@matthewfeickert matthewfeickert force-pushed the pfackeldey/fix_jax_tolist_logging_for_tracers branch from a2f3bc8 to 44ef21e Compare October 14, 2025 20:08
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (10488f0) to head (f875bbf).
⚠️ 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%) ⬆️
doctest 98.09% <100.00%> (+<0.01%) ⬆️
unittests-3.10 96.28% <100.00%> (+<0.01%) ⬆️
unittests-3.11 96.28% <100.00%> (+<0.01%) ⬆️
unittests-3.12 96.28% <100.00%> (+<0.01%) ⬆️
unittests-3.8 96.28% <100.00%> (+<0.01%) ⬆️
unittests-3.9 96.33% <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.

Copy link
Member

@matthewfeickert matthewfeickert left a comment

Choose a reason for hiding this comment

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

As the coverage dips with this addition, can we also get a very small test added for it?

@pfackeldey
Copy link
Contributor Author

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

@matthewfeickert
Copy link
Member

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

@github-project-automation github-project-automation bot moved this from In progress to Reviewer approved in pyhf v0.8.0 Oct 15, 2025
@matthewfeickert
Copy link
Member

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

@matthewfeickert matthewfeickert enabled auto-merge (squash) October 15, 2025 12:40
@matthewfeickert
Copy link
Member

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

@matthewfeickert matthewfeickert merged commit d021d4c into scikit-hep:main Oct 15, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer approved to Done in pyhf v0.8.0 Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix A bug fix

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Raise better error message for pyhf.exceptions.InvalidPdfData for JAX backend

3 participants