Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pruning with logical "and" instead of "or" #2374

Open
1 task done
alexander-held opened this issue Oct 31, 2023 · 2 comments
Open
1 task done

Pruning with logical "and" instead of "or" #2374

alexander-held opened this issue Oct 31, 2023 · 2 comments
Labels
feat/enhancement New feature or request needs-triage Needs a maintainer to categorize and assign

Comments

@alexander-held
Copy link
Member

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 scikit-hep/cabinetry#445).

Additional Information

n/a

Code of Conduct

  • I agree to follow the Code of Conduct
@alexander-held alexander-held added feat/enhancement New feature or request needs-triage Needs a maintainer to categorize and assign labels Oct 31, 2023
@kratsg
Copy link
Contributor

kratsg commented Oct 31, 2023

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

@alexander-held
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat/enhancement New feature or request needs-triage Needs a maintainer to categorize and assign
Projects
None yet
Development

No branches or pull requests

2 participants