pyhf icon indicating copy to clipboard operation
pyhf copied to clipboard

Pruning with logical "and" instead of "or"

Open alexander-held opened this issue 1 year ago • 2 comments

Summary

As far as I can see, the current pyhf.Workspace.prune approach is to prune anything that matches any of its arguments. This means e.g. that

prune(modifier_types=["normsys"], modifiers=["Modeling"])

will remove all normsys modifiers and anything with a NP called "Modeling".

I currently see no convenient way to prune when requiring multiple conditions to be satisfied simultaneously, i.e. a logical "and" between the kwargs. As an example, I would want something like

prune(modifier_types=["normsys"], samples =["ttbar"], mode="logical_and")

to prune all normsys modifiers acting on the "ttbar" sample (better API ideas welcome).

I would be happy to find out if there is already a way to achieve this, otherwise I think it would be a useful addition (I just ran into it while thinking about https://github.com/scikit-hep/cabinetry/discussions/445).

Additional Information

n/a

Code of Conduct

  • [X] I agree to follow the Code of Conduct

alexander-held avatar Oct 31 '23 14:10 alexander-held

#994 is along similar lines here. If I was to make this a bit more flexible, I'd rely on something more like XPath support so you can do .samples[name="ttbar"].modifiers[kind="normsys"] or similar. But to first order, could rewrite some of the logic to allow for a flag like this. Although for something more complex, you can always fallback to jq.

kratsg avatar Oct 31 '23 19:10 kratsg

Indeed this can also be solved externally without too much effort (and for some specific cases that might be the best way). I think an "and" combination would provide flexibility that would be useful to provide centrally in pyhf. The "or" could equally achieved by chaining multiple prune together, while "and" cannot.

alexander-held avatar Oct 31 '23 19:10 alexander-held