-
Notifications
You must be signed in to change notification settings - Fork 54
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
Persist execution context in storage target #359
Persist execution context in storage target #359
Conversation
The latest test failures are from
Preprocessors are a very useful feature, as (will be) hashes, so my preference would be to try to find a way to achieve option 1 if possible. I will take a brief pause on this PR to look into this, but if this seems infeasible, as a backup plan we could move forward with option 2 (not setting hashes for recipes with preprocessors). It seems to me that option 3 could lead to some very confusing situations which we'd prefer to avoid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking great! Just one nit pick about the testing syntax.
Let's use inspect for this. import inspect
def foo(a, b):
a += 1
return a + b
inspect.getsource(foo) I think that is a fine solution for now. It's a little bit brittle because it is sensitive to changes in formatting of the function. However, it should be sufficient to detect when a defined function has not changed at all. I was not able to get def foo(a, b):
a += 1
return a + b
def bar(a, b):
a += 2
return a + b
# this assertion fails
assert foo.__code__.co_code != bar.__code__.co_code |
Thanks for the review, Ryan. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I never merged this! I just see one small issue, then LGTM.
def drop_execution_context_attrs(ds: xr.Dataset) -> xr.Dataset: | ||
"""Drop pangeo-forge execution context attrs from a dataset.""" | ||
|
||
ds_copy = ds.copy(deep=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need a deep copy here? That will use a lot more memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure! It's "just" the tests so happy to use regular copy and see how it goes.
TBH, I've now run into enough weird behavior of copied dictionaries that are not deep copies (due to shared references with the original, I guess), that I just reflexively make all dictionary copies deep now. 😅
This is a WIP to address @rabernat's suggestion in #37 (comment) that we persist execution context information in the storage target, which is the first part of a solution for #37 and pangeo-forge/user-stories#5.
Here's a rough idea of how this might look:
BaseRecipe.get_execution_context
compiles a dict of metadata we want to capturefinalize_target
for XarrayZarrRecipe, a different stage for HDFReferenceRecipe, etc.). As will the exact location in the target (.zmetadata
for XarrayZarrRecipe, somewhere else for other storage formats, etc.).