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

Anticipate form.length_zero_array() highlevel deprecation #801

Merged
merged 4 commits into from
Apr 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 22 additions & 7 deletions coffea/jetmet_tools/CorrectedJetsFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def rand_gauss(item):
if backend == "cpu":
seeds = numpy.array(item)[[0, -1]].view("i4")
elif backend == "typetracer":
olitem = item.layout.form.length_one_array()
olitem = item.layout.form.length_one_array(highlevel=False)
seeds = numpy.array(olitem)[[0, -1]].view("i4")
else:
raise ValueError("rand_gauss received an unsupported awkward backend!")
Expand All @@ -69,13 +69,17 @@ def getfunction(layout, depth, **kwargs):
behavior=item.behavior,
)
elif backend == "typetracer":
zlitem = item.layout.form.length_zero_array()
zlitem = awkward.Array(
item.layout.form.length_zero_array(highlevel=False), behavior=item.behavior
)
out = awkward.transform(
getfunction,
zlitem,
behavior=zlitem.behavior,
)
out = dask_awkward.typetracer_from_form(out.layout.form)
out = awkward.Array(
out.layout.to_typetracer(forget_length=True), behavior=out.behavior
)

assert out is not None
return out
Expand Down Expand Up @@ -118,8 +122,14 @@ def jer_smear(
backend = awkward.backend(smearfact, jetPt)

if backend == "typetracer":
smearfact = smearfact.layout.form.length_zero_array()
jetPt = smearfact.layout.form.length_zero_array()
smearfact = awkward.Array(
smearfact.layout.form.length_zero_array(highlevel=False),
behavior=smearfact.behavior,
)
jetPt = awkward.Array(
jetPt.layout.form.length_zero_array(highlevel=False),
behavior=jetPt.behavior,
)

def getfunction(layout, depth, **kwargs):
if isinstance(layout, awkward.contents.NumpyArray) or not isinstance(
Expand All @@ -131,8 +141,13 @@ def getfunction(layout, depth, **kwargs):
smearfact = awkward.transform(getfunction, jetPt, behavior=jetPt.behavior)

if backend == "typetracer":
jetPt = dask_awkward.typetracer_from_form(jetPt.layout.form)
smearfact = dask_awkward.typetracer_from_form(smearfact.layout.form)
jetPt = awkward.Array(
jetPt.layout.to_typetracer(forget_length=True), behavior=jetPt.behavior
)
smearfact = awkward.Array(
smearfact.layout.to_typetracer(forget_length=True),
behavior=smearfact.behavior,
)

return smearfact

Expand Down
17 changes: 11 additions & 6 deletions coffea/jetmet_tools/FactorizedJetCorrector.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,18 @@ def getCorrection(self, **kwargs):
if type(first_kwarg) is dask_awkward.Array:
levels = "/".join(self._levels)
func = _getCorrectionFn(self, **kwargs)
meta = dask_awkward.typetracer_from_form(
func(
*tuple(
arg._meta.layout.form.length_zero_array()
for arg in kwargs.values()
zl_out = func(
*tuple(
awkward.Array(
arg._meta.layout.form.length_zero_array(highlevel=False),
behavior=arg.behavior,
)
).layout.form
for arg in kwargs.values()
)
)
meta = awkward.Array(
zl_out.layout.to_typetracer(forget_length=True),
behavior=zl_out.behavior,
)

return dask_awkward.map_partitions(
Expand Down
18 changes: 15 additions & 3 deletions coffea/lookup_tools/lookup_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def getfunction(
zlargs = []
for arg in args:
arg._touch_data(recursive=True)
zlargs.append(arg.form.length_zero_array())
zlargs.append(
awkward.Array(
arg.form.length_zero_array(highlevel=False),
)
)
result = thelookup_wref()._evaluate(
*(list(__pre_args__) + [awkward.to_numpy(zlarg) for zlarg in zlargs]),
**kwargs,
Expand Down Expand Up @@ -88,9 +92,17 @@ def __call__(self, *args, **kwargs):
**kwargs,
)

zlargs = [arg._meta.layout.form.length_zero_array() for arg in actual_args]
zlargs = [
awkward.Array(
arg._meta.layout.form.length_zero_array(highlevel=False),
behavior=arg.behavior,
)
for arg in actual_args
]
zlout = tomap(*zlargs)
meta = dask_awkward.typetracer_from_form(zlout.layout.form)
meta = awkward.Array(
zlout.layout.to_typetracer(forget_length=True), behavior=zlout.behavior
)

if dask_label is not None:
return dask_awkward.map_partitions(
Expand Down
4 changes: 3 additions & 1 deletion coffea/nanoevents/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def __init__(

def __call__(self, form):
# expecting a flat data source in so this is OK
lza = form.length_zero_array()
lza = awkward.Array(
form.length_zero_array(highlevel=False), behavior=self.behavior
)
column_source = {key: lza[key] for key in awkward.fields(lza)}

lform = PreloadedSourceMapping._extract_base_form(column_source)
Expand Down