Skip to content

[RF] Test RooFit Hessians with Clad - #21622

Draft
guitargeek wants to merge 5 commits into
root-project:masterfrom
guitargeek:roofit_clad_hessians
Draft

[RF] Test RooFit Hessians with Clad#21622
guitargeek wants to merge 5 commits into
root-project:masterfrom
guitargeek:roofit_clad_hessians

Conversation

@guitargeek

Copy link
Copy Markdown
Contributor

No description provided.

@guitargeek guitargeek self-assigned this Mar 16, 2026
@github-actions

github-actions Bot commented Mar 17, 2026

Copy link
Copy Markdown

Test Results

    23 files      23 suites   4d 15h 46m 8s ⏱️
 3 832 tests  3 822 ✅ 0 💤  10 ❌
71 525 runs  71 381 ✅ 0 💤 144 ❌

For more details on these failures, see this check.

Results for commit 5f67ec4.

♻️ This comment has been updated with latest results.

@guitargeek
guitargeek force-pushed the roofit_clad_hessians branch from e54bf52 to 2a2b0cc Compare March 17, 2026 09:52
@guitargeek guitargeek added the clean build Ask CI to do non-incremental build on PR label Mar 29, 2026
@guitargeek
guitargeek force-pushed the roofit_clad_hessians branch 2 times, most recently from 6368d0c to 11eab4c Compare March 29, 2026 18:19
@guitargeek guitargeek removed the clean build Ask CI to do non-incremental build on PR label Apr 20, 2026
@guitargeek
guitargeek force-pushed the roofit_clad_hessians branch 2 times, most recently from 92c3589 to a79ccd5 Compare April 26, 2026 13:45
@guitargeek
guitargeek force-pushed the roofit_clad_hessians branch from a79ccd5 to db537ff Compare June 17, 2026 06:56
@guitargeek
guitargeek force-pushed the roofit_clad_hessians branch from db537ff to 35d56ad Compare July 5, 2026 18:38
@guitargeek guitargeek added the clean build Ask CI to do non-incremental build on PR label Jul 27, 2026
@guitargeek
guitargeek force-pushed the roofit_clad_hessians branch 3 times, most recently from de105a0 to 352b69d Compare August 11, 2026 15:19
binNumber uses std::lower_bound, which clad can't differentiate. That was
already handled for reverse mode by a dummy binNumber_pullback, but Hessians
also run the forward pass over binNumber, and without a pushforward clad
descends into std::lower_bound and warns about differentiating
__builtin_constant_p and about unsupported typedef declarations, before
failing outright.

Declare the forward-mode counterpart, zero-valued for the same reason as the
pullback: binNumber returns an integer, so it has no derivative.

Since MathFuncs.h is compiled normally as well as parsed by cling, while
clad::ValueAndPushforward only exists inside the interpreter, the type is
forward-declared and the return type is kept dependent so that it is only
completed when clad instantiates the template.
Clad generates a single std::pow pullback per session, so a function that
mixes an integral and a floating-point exponent makes clad::hessian() fail
with an int*/double* mismatch on the exponent adjoint:

  error: cannot initialize a parameter of type 'double *' with an rvalue
         of type 'int *'
  note: passing argument to parameter '_d_exponent' here

That broke the Hessian of every likelihood containing a RooBernstein.
Casting the sign exponent to double is enough to keep both pow calls on
the same instantiation, and it does not change the result: the exponent
is integer-valued either way.
The code generated for a RooLognormal with useStandardParametrization() called
RooFit::Detail::MathFuncs::logNormalEvaluateStandard, which does not exist --
the function is called logNormalStandard. Any codegen or AD fit of such a pdf
failed to compile with "no member named 'logNormalEvaluateStandard'".

This went unnoticed because the LognormalStandard case in testRooFuncWrapper
builds its pdf with

    Lognormal::model(x[...], mu[...], k[...], true)

and the factory quietly dropped that last argument, so the test was really a
duplicate of the Lognormal one. RooFactoryWSTool::asINT(), which is also the
conversion used for bool constructor arguments, is atoi(), and atoi("true") is
zero. Teach it about the spelled-out literals, which affects every factory
string that writes a bool that way, and makes the existing test exercise what
it says it does.

Verified that the generated code now agrees exactly with the reference backend,
for the nominal likelihood value and over a scan of the shape parameters.
@guitargeek
guitargeek force-pushed the roofit_clad_hessians branch from 352b69d to 5f67ec4 Compare August 11, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clean build Ask CI to do non-incremental build on PR in:RooFit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant