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

Add blogpost on flox heuristics #695

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft

Add blogpost on flox heuristics #695

wants to merge 22 commits into from

Conversation

dcherian
Copy link
Contributor

@dcherian dcherian commented Jul 29, 2024

Copy link

vercel bot commented Jul 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
xarray-dev ✅ Ready (Inspect) Visit Preview 7 resolved Aug 5, 2024 7:30pm

@@ -0,0 +1,157 @@
---
title: 'flox: GroupBy, now with smarts!'
date: '2024-05-31'
Copy link
Contributor Author

@dcherian dcherian Jul 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
date: '2024-05-31'
date: '2024-08-05'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or whenever we decide to merge.


Unlike [Jaccard similarity](https://en.wikipedia.org/wiki/Jaccard_index), _containment_ [isn't skewed](http://ekzhu.com/datasketch/lshensemble.html) when one of the sets is much larger than the other.

The steps are as follows:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this bit clear and useful? Should I take it out? Or expand it?

Copy link
Member

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Really incredible work you have done here @dcherian

I left a few comments: some nits, some minor suggestions on structure/content.


## Avoiding catastrophe

Thus `flox` quickly grew two new modes of computing the groupby reduction.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this sentence down to after you have gone through your two realizations. Otherwise it's confusing when you jump into

First, method="blockwise"

Comment on lines +27 to +29
Notice how much cleaner the graph is in this image:
![map-reduce](https://flox.readthedocs.io/en/latest/_images/new-map-reduce-reindex-True-annotated.svg)
See our [previous blog post](https://xarray.dev/blog/flox) or the [docs](https://flox.readthedocs.io/en/latest/implementation.html#method-map-reduce) for more.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little confusing that these two images are not for identical problems - the inputs are different.

Comment on lines +85 to +88
```python
mean_mapreduce = ds.groupby("time.month").mean(method="map-reduce")
mean_cohorts = ds.groupby("time.month").mean() # this is auto-detected!
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```python
mean_mapreduce = ds.groupby("time.month").mean(method="map-reduce")
mean_cohorts = ds.groupby("time.month").mean() # this is auto-detected!
```
```python
mean_mapreduce = ds.groupby("time.month").mean(method="map-reduce") # mapreduce is a suboptimal manual choice here
mean_cohorts = ds.groupby("time.month").mean() # cohorts is a better choice - auto-detected!

Using the algorithm described below, flox will **automatically** set
`method="cohorts"` for this dataset unless specified, yielding a 5X decrease in
memory used and a 2X increase in runtime. Read on to figure out how!
Read on to figure out how!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Read on to figure out how!

(duplication)


_Note that the improvements here are strongly dependent on the details
of the grouping variable, the chunksize, and even dask's scheduler. In fact, writing this post
prompted the discovery of a bug in dask's scheduler that should substantially improve the "map-reduce"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link?!


The improvements described here are strongly dependent on the details
of the grouping variable, the chunksize, and even dask's scheduler.
In fact, writing this post prompted the discovery of a bug in dask's scheduler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is repeated from above


Importantly this inference is fast — [~250ms for the US county](https://flox.readthedocs.io/en/latest/implementation.html#example-spatial-grouping) GroupBy problem in our [previous post](https://xarray.dev/blog/flox) where approximately 3000 groups are distributed over 2500 chunks; and ~1.25s for grouping by US watersheds ~87000 groups across 640 chunks.

## What's next?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your conclusion is a bit rambly, and I think some of the content (especially call-outs to any other groupby nerds who can help) could be in a footnote.

I think you should end with a succinct one-line conclusion that emphasises that most of this complexity can now be safely ignored by users.

Using the algorithm described below, flox will **automatically** set
`method="cohorts"` for this dataset unless specified, yielding a 5X decrease in
memory used and a 2X increase in runtime. Read on to figure out how!
Read on to figure out how!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A significant number of readers will think it's cool that this is now automatic, but not really care about the specifics of how you did it. That section below is also very dense. I think if there is any other information that you want readers to take away from this point onwards (e.g. that Groupers exist) you should telegraph it, and explicitly give them the option to skip forwards to a different subheading guilt-free.

@dcherian
Copy link
Contributor Author

dcherian commented Aug 6, 2024

Thanks for the review @TomNicholas . I'm waiting for some tests on the new dask release before revising: https://docs.dask.org/en/stable/changelog.html#improve-scheduling-efficiency-for-xarray-groupby-reduce-patterns

@TomNicholas TomNicholas added the blog Blog post label Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog Blog post
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants