Fix conflicting attrs during concat#561
Draft
gtrevisan wants to merge 2 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses xarray concatenation failures caused by conflicting dataset attributes (notably workflow metadata like a per-process timestamp) in multi-process workflows, which becomes more prominent under spawn/forkserver process start methods.
Changes:
- Import
get_metadataintodisruption_py/settings/output_setting.py. - Change
xr.concat(..., combine_attrs=...)from"no_conflicts"to"drop_conflicts"inDatasetOutputSetting.concat(). - Re-apply workflow metadata to the final concatenated dataset via
ds.attrs.update(get_metadata()).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+328
to
+329
| ds = xr.concat(self.results.values(), dim="idx", combine_attrs="drop_conflicts") | ||
| ds.attrs.update(get_metadata()) |
Comment on lines
+328
to
+329
| ds = xr.concat(self.results.values(), dim="idx", combine_attrs="drop_conflicts") | ||
| ds.attrs.update(get_metadata()) |
Comment on lines
97
to
100
| for ds_list in [dict_out.values(), [dt.to_dataset() for dt in dt_out.values()]]: | ||
| xr.testing.assert_identical( | ||
| xr.testing.assert_equal( | ||
| ds_out, xr.concat(ds_list, dim="idx").sortby(["shot", "time"]) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I realized that the upcoming
py3.14spawn/forkserver issues will affect my LRU-cachedget_metadatamethod.with the new python versiona slightly different time will be returned for each process and therefore xarray will flag attribute conflicts.the LRU cache was supposed to prevent this, as the metadata should be resolved (and its cache should be primed) as a first thing by the logger:
disruption-py/disruption_py/settings/log_settings.py
Line 157 in 0063f4b
as a dirty fix, we can drop conflicts while concatenating and reapply them on the final product, here:
disruption-py/disruption_py/settings/output_setting.py
Line 328 in 0063f4b
@samc24 feel free to dig around whether there is a better way to solve this!
or LMK if you cannot replicate it -- any multiproc multishot workflow should do, including the testing ones.
eg: