[HS3] Bugfixes to HS3 histfactoy_dist handling#22283
Conversation
Test Results 20 files 20 suites 3d 2h 59m 38s ⏱️ Results for commit 7d204dc. ♻️ This comment has been updated with latest results. |
|
Thank you for the PR! The reason why I didn't merge this yet is because I have a doubt with the treatment of the RooConstVar. It's a delicate topic, because it's not clear what the semantic difference of a RooConstVar and a constant RooRealVar should be. So far, the policy has been:
What you are suggesting now is to change the policy only for the RooGaussian to always export RooConstVar by value, which seems a bit ad-hoc to me. What is the motivation to change the policy just for this class? Maybe we should change the policy in general, to keep things consistent? |
|
I think the Issue in that resulted in this particular change was that a named RooConstVar was exported and re-imported as a const RooRealVar, because of the default streamer behavior. Only RooConstVars where the name and value are numbers are exported as literals. import ROOT
# Build two Gaussian PDFs, one with a constant sigma and one with a literal sigma value
x = ROOT.RooRealVar("x", "x", 0, 10)
sigma = ROOT.RooConstVar("sigma", "sigma", 1)
mean = ROOT.RooRealVar("mean", "mean", 5, 0, 10)
mean.setConstant(True)
gauss = ROOT.RooGaussian("gauss", "gauss", x, mean, sigma)
gauss_literal = ROOT.RooGaussian("gauss_literal", "gauss_literal", x, mean, 1.0)
# Create a workspace and import the PDFs
ws = ROOT.RooWorkspace("ws")
ws.Import(gauss)
ws.Import(gauss_literal)
# Export the workspace to JSON and import it back into a new workspace
tool = ROOT.RooJSONFactoryWSTool(ws)
tool.exportJSON("test.json")
ws2 = ROOT.RooWorkspace("ws2")
tool2 = ROOT.RooJSONFactoryWSTool(ws2)
tool2.importJSON("test.json")
ws2.Print()
ws2.var("sigma").Print()Some earlier Workspaces named their "_sigma" RooConstVar parameters in constraint terms which lead to reimporting them as RooRealVars. This raised some warnings with the xRooFit importer. |
|
Ah, I see! Well, also from the perspective of round-tripping, I think what is now in the PR is not what we want, because the original name of the RooConstVar gets lost on the JSON export. What about storing in the "misc" which variable names are |
|
I can add a new attribute called What do you think @cburgard ? |
a1cf5d6 to
ae92c2e
Compare
|
I have Updated the the branch to store the Information on RooConstVars in the misc part of the HS3 files but as you can see in the diff, there are some comments that suggest HS3 doesn't want to implement RooConstVars. |
|
Since I was tagged here I'll share my take on things. That being said, I don't feel I'm neccessarily the most competent person to comment here. RooConstVar is a strange beast from a statistics perspective, as there is not really a definition of what it should be. It is a constant value, that should basically never change - but so is a RooAbsReal with the "const" property set. The only real difference, then, is the amount of work someone needs to do to change the value, which doesn't really translate well to other frameworks. Looking at HS3, the best mapping of existing constructs I can find is that a RooAbsReal (const or no const) is a variable that has a domain and a value in the default_values parameter point, whereas a RooConstVar is just a numeric literal. That mapping works well whenever there is a "true" RooConstVar, that is, one that has no information about it other than its value. The main reason why they exist, from my understanding, is that RooConstVar does not show up in the dependency graph, which helps keep some computations more lightweight - that's a very ROOT-like feature that does not translate well to other frameworks, though.
Both 1 and 2 could potentially be augmented by putting information into misc, but I would want to use that capability as sparingly as possible. Of these two, (1) seems more appealing to me if we do not find a solution for (3), as with a loss of misc, getting the name of an object wrong that supports no operation other then getVal seems less catastrophic than changing the dependency graph by introducing new fully-featured leafs to the computational graph that did not exist before. Let's talk 3, then. For now, we have used the logic of "named vs. unnamed" to decide which one we want to do: literal or variable. That was an easy choice, because that is exactly the condition under which we are able to supply a name on the hs3 side. This had the downside of having no way to distinguish between proper variables and former ConstVars on the side of the import.
I hope that makes sense. |
|
Thanks @cburgard for chiming in! This is a good suggestion to use the domains for that. But I'm also worried that then we're running into ambiguities with RooRealVars that have unlimited range, in which case we might want to skip the "domains" entry for brevity. By the way, the benefit of So taking a step back, I'm wondering where it's even useful to have named So this is the other way out I see:
What do you think about that? Also tagging @will-cern. because he might use the meta info from RooConstVar names in xRooFit. |
|
Just to throw a term in here that we came up before for these ConstVars ... at some point we started calling them "prespecified parameters". They are things that have a value but can never "float". I am happy with the idea that these types of parameters are "variables" in HS3 that do not have a domain (no range), assuming that an infinite domain (+/- inf) is distinct from having no domain. RooConstVars don't have "binnings" (the roofit equivalent of what I am reading here to be a 'domain'). Does that all tally with what others are thinking? |
|
Yes, I agree with @will-cern here. |
|
Okay thanks, for the discussion! If a RooRealVar with unlimited range is distinct from a variable with no domain in HS3 then I have no further doubt with the solution that Carsten suggested. @Phmonski can you implement the suggested tagging of named RooConstVar by absence of a domain in this PR? |
|
Ill gladly implement this suggestion. Just for my understanding
On Import:
|
Yes exactly. |
|
@cburgard does this match your expectation? |
This Pull request:
Patch to HS3 histfacory import and export:
data.errors.isConstant(True). Changed the behavior to export RooConstVars as literals.Changes or fixes:
Checklist:
@cburgard @will-cern