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

Integrating systematics handling into nanoevents #529

Merged
merged 14 commits into from
Apr 1, 2022
Merged

Conversation

lgray
Copy link
Collaborator

@lgray lgray commented May 13, 2021

Sketching out ideas for rich/extensible/efficient systematics handling in nanoevents.

note / warning: This is not meant to suggest a buy-in framework for systematics, but rather to engineer a naming convention for extensions by which systematics can be added to an analysis. This naming convention is then assumed by statistics tools to create variations and ensembles expecting common data. What is here right now is attempting to get to the point where a schema can be defined (doing this beforehand is self defeating). So while it may look like I'm writing a deeply opt-in framework, what I am opting-in to is agreeing to an interface that we should put systematics in a field in an physics object or event called "systematics". I am not trying to extend nanoevents such that everyone has to use it forever to calculate systematics. I am trying to alter nanoevents to suit the naming convention we are solving for.

New methods class: Systematic. If an object has systematics associated to it then it should inherit from this.

Also adds systematics subdir to nanoaod.methods, there is a simple "Up/Down" systematics class there right now.

Right now NanoEvents, and then the NanoAOD object classes.

It may make more sense to tie it directly to NanoCollection so that everything gets it.

There is one special keyword so far weight which tells the systematics to append weight_SystematicName to the class instead of altering the value of a feature in the object. It's clunky right now but it gets the job done correctly.

I'll try to keep systematics.ipynb working while I hack on this.

Guiding ideas:

  • This is to index and evaluate systematics in a numpythonic way
  • "fancy indexing for systematics"
  • specification for an array form that you can build any systematics evaluation / ensemble building machinery on top of.

@lgray lgray marked this pull request as draft May 13, 2021 20:49
@lgray lgray marked this pull request as ready for review February 24, 2022 17:59
@lgray
Copy link
Collaborator Author

lgray commented Feb 24, 2022

To finish and merge:

  • improve speed of eventwise weights (right now it needs to read a lot for ... reasons?)
  • documentation

@lgray
Copy link
Collaborator Author

lgray commented Mar 7, 2022

@nsmith- can you take a look?

@lgray lgray requested a review from nsmith- March 7, 2022 22:12
@lgray lgray changed the title [WIP] Integrating systematics handling into nanoevents Integrating systematics handling into nanoevents Mar 7, 2022
@lgray
Copy link
Collaborator Author

lgray commented Mar 10, 2022

@nsmith- ping?

@lgray
Copy link
Collaborator Author

lgray commented Mar 11, 2022

@andrzejnovak too

@andrzejnovak
Copy link
Collaborator

Neat! Two UX questions. Should there be a specific one way syst option rather than filling up or down with nominal for example? Could add_systematics also take directly 2XN array or is it only function such that it can be lazy?

@lgray
Copy link
Collaborator Author

lgray commented Mar 11, 2022

@andrzejnovak

  1. So UpDownSystematic is meant to be an example and it's possible to implement any set of variations as a systematic when starting from the Systematic base class. I guess the real answer to this is I should include more example classes!
  2. You could accomplish that by passing a lambda that returns the arrays, but yeah it's all built around lazy functions as it is implemented right now.

@lgray
Copy link
Collaborator Author

lgray commented Mar 23, 2022

@nsmith- ping

Copy link
Member

@nsmith- nsmith- left a comment

Choose a reason for hiding this comment

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

I think it looks good, modulo users creating reference cycles in the user-supplied variation function.
I'm a bit confused how the UI looks w.r.t. looping over the weight systematic variations. I expected some function that multiplies all the nominal weights together, but it looks like here we only track up/down.

coffea/nanoevents/methods/base.py Show resolved Hide resolved
coffea/nanoevents/methods/base.py Outdated Show resolved Hide resolved
)

self["__systematics__", f"__{name}__"] = awkward.virtual(
varying_function,
Copy link
Member

Choose a reason for hiding this comment

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

I'm worried it will be very hard for user-provided functions to not reference the array this virtual array is being attached to, and hence memory leaks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Even though it's not a complete awkward schema, should we put the systematics instead in a dictionary or functor that's returned to the user instead?

Usually the pattern as it is right now almost always asks that you're referencing/altering an array that's in the object you're adding a systematic to.
The corrections or variations themselves are likely not a part of the record array though.

the what specification in add_systematic is usually some value in the record array. The input variations are not.

Copy link
Member

Choose a reason for hiding this comment

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

should we put the systematics instead in a dictionary or functor that's returned to the user instead

Can you sketch what this would look like for a user? I didn't quite follow

coffea/util.py Show resolved Hide resolved
@lgray lgray merged commit 198dd99 into master Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants