Repository navigation
Open
Labels
Description
What happened:
Error raised during graph.validate() for a graph which was valid in 2021.9.1.
This graph creates a dataframe per chunk of an array, then merges the dataframes along one axis of the array. A final per-chunk analysis is then run, where a merged dataframe is used in the analysis of each chunk that was used to make it.
What you expected to happen:
The constructed graph should validate.
Minimal Complete Verifiable Example:
import functools
import operator
import dask
import dask.array as da
import dask.dataframe as dd
import numpy as np
META = dd.utils.make_meta([("foo", int)])
def test_sequential():
image = da.zeros((2, 1), chunks=(1, -1))
indices = list(np.ndindex(*image.numblocks))
slices = da.core.slices_from_chunks(image.chunks)
chunks = list(map(functools.partial(operator.getitem, image), slices))
# Create one dataframe per chunk.
ddf_all = np.empty(image.numblocks, dtype=object)
for idx_chunk, chunk in zip(indices, chunks):
ddf_delayed = dask.delayed(lambda: None)(chunk)
ddf_all[idx_chunk] = dd.from_delayed(ddf_delayed, meta=META)
# Merge dataframes along first axis.
ddf_array = np.empty(image.numblocks[2:], dtype=object)
for idx_spatial in np.ndindex(*ddf_array.shape):
idx_all = (...,) + idx_spatial
ddf = dd.concat(ddf_all[idx_all].flatten().tolist())
ddf_array[idx_spatial] = ddf
# Run a per-chunk calculation using the merged dataframes,
# where a single merged dataframe is passed back to the all chunks that
# went into making it.
signal = []
for idx_chunk, chunk in zip(indices, chunks):
ddf = ddf_array[idx_chunk[2:]]
ddf_signal_chunk = dask.delayed(lambda: None)(chunk, ddf)
signal.append(ddf_signal_chunk)
ddf_signal = dd.from_delayed(signal, meta=META)
ddf_signal.__dask_graph__().validate() # FAILSOutput:
E ValueError: incorrect dependencies['finalize-287aac88-1505-4627-8949-4d20bf676833']: {'getitem-5a7a378a35301a5d6727950e7814a5c2'} expected {'concat-732322a8bf255193f89c61560c08bcdb'}
Environment:
- Dask version: 2021.10.0
- Python version: 3.8.10
- Operating System: Ubuntu 20.1
- Install method (conda, pip, source): pip
Activity
jrbourbeau commentedon Oct 25, 2021
Thanks @chrisroat -- I'm able to confirm the exception you're seeing. Running your example through Dask's
githistory, #8174 is where your example started to fail. cc @gjoseph92 for visibilityjakirkham commentedon Oct 25, 2021
cc @rjzamora (for awareness)
chrisroat commentedon Oct 25, 2021
Ah, bummer! I was a big fan of the PR.
jakirkham commentedon Oct 25, 2021
This change sticks out to me ( #8174 (comment) )
chrisroat commentedon Nov 3, 2021
Here is a more simplified version of the above (thank you new BlockView!), where doing a
dd.concaton somedd.from_delayeddataframes is broken, as compared to directly usingdd.from_delayedon a list of delayed objects.jrbourbeau commentedon Nov 4, 2021
Thank you for the simplified example @chrisroat. Out of curiosity, does this regression result in your computation failing? Or is it just the
validate()method that fails? I ask because if I replaceddf_final.__dask_graph__().validate()withddf_final.compute()in the second example I get the following errorwith both the latest
mainbranch as well as the 2021.09.1 releasechrisroat commentedon Nov 4, 2021
Your error is because the computations are bogus lambda function. The example provided is simply creating the graph. My tests fail during
assert_eqwhich validates the graph prior to even running compute.What I am experimenting with is whether the
make_ddf_worksis a valid substitute. It seems to create a valid graph and passes the unit tests. I'm trying out our regression tests to be sure the computation is still valid.chrisroat commentedon Nov 4, 2021
So the regression tests are passing, which makes me feel confident the computation isn't screwed up.
Is it expected that
dd.from_delayedon a list of delayed objects should result in a single dataframe, effectively doing add.concat?gjoseph92 commentedon Nov 5, 2021
Based on the docs, I think so:
Is that not what you were expecting?
chrisroat commentedon Nov 5, 2021
My expectations aside, your read of the documents makes it clear what is correct. :) Though technically, I'd be curious what happens if each delayed object is itself multiple partitions.
For that part of the example, I had just been doing the from_delayed individually, and then doing a concat. It's nice to do it with fewer lines of code! It is interesting that the same graph isn't generated both ways.
gjoseph92 commentedon Nov 5, 2021
What do you mean? Like if your delayed object referenced a list of pandas DataFrames, like
delayed([pd.DataFrame(...), pd.DataFrame(...)])? In that case, it would just be invalid.If you think about how
DataFrame.to_delayed()essentially "explodes" the dask DataFrame into a list ofdelayeds, where each partition is its own delayed object,from_delayedis the inverse: you give one delayed object per partition, and they're reassembled into a DataFrame.I'm not surprised they're different.
concathas all sorts of other things to do: joining columns, checking dtypes, etc. It's for combining logically separate DataFrames into one. It's adding actualpd.conattasks to the graph.from_delayedis saying "together, these delayed objects comprise one logical DataFrame; I want you to represent them as such. Trust me, they already have the same columns and dytpe and everything.". It's really just graph-manipulation; no extra tasks (just aliases) get added to the graph.Nonetheless,
from_delayed->concatshould still produce a valid graph.chrisroat commentedon Nov 9, 2021
Thanks for the better understanding of
from_delayed/to_delayed.Ah, I see. I would think the metadata would be enough to skip adding tasks that weren't necessary (in this case, all
metaare identical in columns/types).Agreed. I will skip using
concatmyself, both because of this possible bug and because I don't need the extra logic.gjoseph92 commentedon Nov 9, 2021
Ah, if only that were the case! That's worth opening an issue for. I wish we more efficiently supported that workflow of explode chunks -> do things to chunks -> combine back into DataFrame/Array.
jakirkham commentedon Nov 9, 2021
With Array we have
.blocksand DataFrames we have.partitions.jsignell commentedon Dec 20, 2021
Is this issue good to close? It seems like the discussion is mostly around building understanding.
chrisroat commentedon Dec 20, 2021
It seems like a bug (to me) that simple operations lead to invalid graphs. My concern would be that it could by hiding something subtle. Of course, I could be wrong, and my repro case may be incorrectly coded: #8292 (comment)
jsignell commentedon Dec 20, 2021
I just toyed around with a slightly modified example using
make_df_works. Some notable differences:make_ddf_workswhich callsdd.from_delayedon a list of delayed objects. Note that this is what the function expects as mentioned in graph became invalid in 2021.10.0 #8292 (comment)chrisroat commentedon Dec 20, 2021
Do you have thoughts on why the graph generated with
make_ddf_brokendoes not work?jsignell commentedon Dec 21, 2021
I have one main thoughtsthat is not totally tested. If it is correct we can do a better job with error handling:
dd.from_delayedis meant to handle a list of delayed objects. Inmake_ddf_brokenyou are passing in a single delayed object.jsignell commentedon Dec 21, 2021
No that's not it. I just looked and the first thing Dask does if you pass a
Delayedis just wrap it in a list.