-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: One-pass column optimization #491
Draft
martindurant
wants to merge
29
commits into
dask-contrib:main
Choose a base branch
from
martindurant:one-pass
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b18b3af
start
martindurant 3cdc778
Remove unused
martindurant c57693c
Pass reports around
martindurant 0c367df
remember to commit
martindurant 9c654b1
first working (for parquet)
martindurant e6c5ce3
Merge branch 'main' into one-pass
martindurant f56f77a
stop
martindurant 75b4416
most pass
martindurant a5c319d
fix most
martindurant 243fbc1
probably better
martindurant 6eebf87
Reinstate necessary_columns (needs doc)
martindurant 8bbe409
Merge branch 'main' into one-pass
martindurant 43b2e43
pass buffer names around, not columns
martindurant e5828fb
Clear cache between tests
martindurant df0cf2f
Merge branch 'main' into one-pass
martindurant b593f87
Another one squashed
martindurant e410b61
Squash errors that only show when uproot.dask and hist.dask are insta…
martindurant cd537e2
fix uproot
martindurant baf6f46
fix report
martindurant e29e929
if meta fails
martindurant f61fdd7
rev
martindurant 2c3abd0
concat enforce condition
martindurant 04abbc8
temp
martindurant d876f00
squached some
martindurant 8e1d507
add note
martindurant d1922ab
Merge branch 'main' into one-pass
martindurant fc9589b
Fix concat form comparison
martindurant 961dd0c
one more squashed
martindurant c8b254b
fix IO report
martindurant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,10 +111,30 @@ def optimize_columns(dsk: HighLevelGraph, keys: Sequence[Key]) -> HighLevelGraph | |
all_reps.update(getattr(dsk.layers[ln].meta, "_report", ())) | ||
name = tokenize("output", lays) | ||
[_.commit(name) for _ in all_reps] | ||
all_layers = tuple(dsk.layers) + (name,) | ||
|
||
for k, lay, cols in _optimize_columns(dsk.layers, all_layers): | ||
new_lay = lay.project(cols) | ||
dsk2[k] = new_lay | ||
|
||
return HighLevelGraph(dsk2, dsk.dependencies) | ||
|
||
|
||
def _buf_to_col(s): | ||
return ( | ||
s[2:] | ||
.replace(".content", "") | ||
.replace("-offsets", "") | ||
.replace("-data", "") | ||
.replace("-index", "") | ||
.replace("-mask", "") | ||
) | ||
|
||
|
||
def _optimize_columns(dsk, all_layers): | ||
|
||
# this loop is necessary_columns | ||
all_layers = tuple(dsk.layers) + (name,) | ||
for k, lay in dsk.layers.items(): | ||
for k, lay in dsk.copy().items(): | ||
if not isinstance(lay, AwkwardInputLayer) or not hasattr( | ||
lay.io_func, "_column_report" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just like with |
||
): | ||
|
@@ -125,29 +145,38 @@ def optimize_columns(dsk: HighLevelGraph, keys: Sequence[Key]) -> HighLevelGraph | |
for ln in all_layers: | ||
# this loop not required after next ak release | ||
try: | ||
cols |= set(rep.data_touched_in((ln,))) | ||
for col in rep.shape_touched_in((ln,)): | ||
if col in cols or any(_.startswith(col) for _ in cols): | ||
# loopy loop? | ||
cols |= {_buf_to_col(s) for s in rep.data_touched_in((ln,))} | ||
for col in (_buf_to_col(s) for s in rep.shape_touched_in((ln,))): | ||
if col in cols: | ||
continue | ||
if any(_.startswith(col) for _ in cols): | ||
continue | ||
col2 = ( | ||
col[2:] | ||
.replace(".content", "") | ||
.replace("-offsets", "") | ||
.replace("-data", "") | ||
.replace("-index", "") | ||
.replace("-mask", "") | ||
) | ||
ll = list(_ for _ in all_cols if _.startswith(col2)) | ||
ll = list(_ for _ in all_cols if _.startswith(col)) | ||
if ll: | ||
cols.add("@." + ll[0]) | ||
cols.add(ll[0]) | ||
|
||
except KeyError: | ||
pass | ||
new_lay = lay.project([c.replace("@.", "") for c in cols]) | ||
dsk2[k] = new_lay | ||
yield k, lay, cols | ||
|
||
return HighLevelGraph(dsk2, dsk.dependencies) | ||
|
||
def necessary_columns(*args): | ||
dsk = {} | ||
all_reps = set() | ||
all_layers = set() | ||
for arg in args: | ||
dsk.update(arg.dask.layers) | ||
all_layers.add(arg.name) | ||
touch_data(arg._meta) | ||
all_reps.update(getattr(arg.dask.layers[arg.name].meta, "_report", ())) | ||
name = tokenize("output", args) | ||
[_.commit(name) for _ in all_reps] | ||
all_layers = tuple(all_layers) + (name,) | ||
|
||
out = {} | ||
for k, _, cols in _optimize_columns(dsk, all_layers): | ||
out[k] = cols | ||
return out | ||
|
||
|
||
def rewrite_layer_chains(dsk: HighLevelGraph, keys: Sequence[Key]) -> HighLevelGraph: | ||
|
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.
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 don't have time right now to look at the full PR here, but is this assumption about buffer name mappings enforced anywhere? Right now the design is such that input sources can use a non-canonical buffer naming scheme.
For coffea I think we made this possible so that Coffea could directly pass in their own buffer names with semantic meaning.
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 have access to the call to
ak.from_buffers
here? That function takes a callable that constructs the buffer names from theform_key
s and these roles.The roles are fixed words like this, and Coffea only has the power to change the
form_key
, not the role. This is almost the complete set of such names; only-tags
(for UnionArray) is missing.