-
Notifications
You must be signed in to change notification settings - Fork 76
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
Changes for dask-awkward one-pass optimize #1225
Draft
martindurant
wants to merge
11
commits into
scikit-hep:main
Choose a base branch
from
martindurant:one-pass-dask-optimize
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.
+17
−77
Draft
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
31fbc00
Changes for dask-awkward one-pass optimize
martindurant 47ccdaf
style: pre-commit fixes
pre-commit-ci[bot] cd6690b
fix behaviour
martindurant 5b1238b
Merge branch 'one-pass-dask-optimize' of https://github.com/martindur…
martindurant 841d433
Merge branch 'main' into one-pass-dask-optimize
martindurant d3d3c4b
simplistic nano pattern for columns
martindurant 51cbbac
style: pre-commit fixes
pre-commit-ci[bot] 3146d94
remove unnecessary
martindurant 4c01156
style: pre-commit fixes
pre-commit-ci[bot] 51c45c5
removed too much
martindurant e9e2d71
Merge branch 'one-pass-dask-optimize' of https://github.com/martindur…
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ | |
from uproot.behaviors.TBranch import HasBranches, TBranch, _regularize_step_size | ||
|
||
if TYPE_CHECKING: | ||
from awkward._nplikes.typetracer import TypeTracerReport | ||
from awkward.forms import Form | ||
from awkward.highlevel import Array as AwkArray | ||
|
||
|
@@ -889,7 +888,9 @@ def keys_for_buffer_keys(self, buffer_keys: frozenset[str]) -> frozenset[str]: | |
keys: set[str] = set() | ||
for buffer_key in buffer_keys: | ||
# Identify form key | ||
form_key, attribute = buffer_key.rsplit("-", maxsplit=1) | ||
form_key, attribute = buffer_key.replace("@.", "<root>.").rsplit( | ||
"-", maxsplit=1 | ||
) | ||
# Identify key from form_key | ||
keys.add(self._form_key_to_key[form_key]) | ||
return frozenset(keys) | ||
|
@@ -954,6 +955,7 @@ def __call__(self, form: Form) -> tuple[Form, TrivialFormMappingInfo]: | |
class UprootReadMixin: | ||
base_form: Form | ||
expected_form: Form | ||
behavior = {} | ||
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. I'm not sure how behaviours should be handled, so this probably needs updating |
||
form_mapping_info: ImplementsFormMappingInfo | ||
common_keys: frozenset[str] | ||
interp_options: dict[str, Any] | ||
|
@@ -1026,83 +1028,15 @@ def read_tree( | |
assert tree.source # we must be reading something here | ||
return out, tree.source.performance_counters | ||
|
||
def mock(self) -> AwkArray: | ||
awkward = uproot.extras.awkward() | ||
return awkward.typetracer.typetracer_from_form( | ||
self.expected_form, | ||
highlevel=True, | ||
behavior=self.form_mapping_info.behavior, | ||
) | ||
|
||
def mock_empty(self, backend) -> AwkArray: | ||
awkward = uproot.extras.awkward() | ||
return awkward.to_backend( | ||
self.expected_form.length_zero_array(highlevel=False), | ||
backend=backend, | ||
highlevel=True, | ||
behavior=self.form_mapping_info.behavior, | ||
) | ||
|
||
def prepare_for_projection(self) -> tuple[AwkArray, TypeTracerReport, dict]: | ||
awkward = uproot.extras.awkward() | ||
dask_awkward = uproot.extras.dask_awkward() | ||
|
||
# A form mapping will (may) remap the base form into a new form | ||
# The remapped form can be queried for structural information | ||
|
||
# Build typetracer and associated report object | ||
meta, report = awkward.typetracer.typetracer_with_report( | ||
self.expected_form, | ||
highlevel=True, | ||
behavior=self.form_mapping_info.behavior, | ||
buffer_key=self.form_mapping_info.buffer_key, | ||
) | ||
|
||
return ( | ||
meta, | ||
report, | ||
{ | ||
"trace": dask_awkward.lib.utils.trace_form_structure( | ||
self.expected_form, | ||
buffer_key=self.form_mapping_info.buffer_key, | ||
), | ||
"form_info": self.form_mapping_info, | ||
}, | ||
) | ||
|
||
def project(self: T, *, report: TypeTracerReport, state: dict) -> T: | ||
keys = self.necessary_columns(report=report, state=state) | ||
return self.project_keys(keys) | ||
|
||
def necessary_columns( | ||
self, *, report: TypeTracerReport, state: dict | ||
) -> frozenset[str]: | ||
## Read from stash | ||
# Form hierarchy information | ||
form_key_to_parent_form_key: dict = state["trace"][ | ||
"form_key_to_parent_form_key" | ||
] | ||
# Buffer hierarchy information | ||
form_key_to_buffer_keys: dict = state["trace"]["form_key_to_buffer_keys"] | ||
# Restructured form information | ||
form_info = state["form_info"] | ||
|
||
# Require the data of metadata buffers above shape-only requests | ||
dask_awkward = uproot.extras.dask_awkward() | ||
data_buffers = { | ||
*report.data_touched, | ||
*dask_awkward.lib.utils.buffer_keys_required_to_compute_shapes( | ||
form_info.parse_buffer_key, | ||
report.shape_touched, | ||
form_key_to_parent_form_key, | ||
form_key_to_buffer_keys, | ||
), | ||
} | ||
@property | ||
def form(self): | ||
return self.expected_form | ||
|
||
# Determine which TTree keys need to be read | ||
return form_info.keys_for_buffer_keys(data_buffers) & frozenset( | ||
def project(self, columns) -> T: | ||
keys = self.form_mapping_info.keys_for_buffer_keys(columns) & frozenset( | ||
self.common_keys | ||
) | ||
return self.project_keys(keys) | ||
|
||
def project_keys(self: T, keys: frozenset[str]) -> T: | ||
raise NotImplementedError | ||
|
Oops, something went wrong.
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.
Would this fail for any of the styles of buffer name? We could use
[0]
or*attribute
to guard against this (we don't actually use the attribute).In fact, this whole loop could be a single comprehension.
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.
It's unclear what characters are not allowed in a TBranch name, which gets passed over to the form_keys. It would be hard to use a
:
in a TBranch name, since that gets interpreted by ROOT (in some constructors, not all). On the other hand,.
is very common and can't be a delimiter.I tried to see what would break it:
Here's something we can count on: a ROOT TBranch name is not going to have a null byte (Python
"\x00"
) in the middle of the string, whereas this is legal and would be properly carried around in Python. It seems pretty drastic, though.