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 rechunking to save_dataset #981

Closed
benjeffery opened this issue Dec 21, 2022 · 4 comments · Fixed by #988
Closed

Add rechunking to save_dataset #981

benjeffery opened this issue Dec 21, 2022 · 4 comments · Fixed by #988

Comments

@benjeffery
Copy link
Collaborator

benjeffery commented Dec 21, 2022

I'm creating a workflow where I need to subset the variants in a dataset and write it back to zarr. However:

ds = sg.simulate_genotype_call_dataset(50000,10)
sg.save_dataset('test.zarr')
ds = sg.load_dataset('test.zarr')
selection = xr.ones_like(ds['variant_position'], dtype=bool)
selection[1000:1100] = False
ds = ds.sel(variants=selection)
sg.save_dataset('test.zarr')

Results in: ValueError: Final chunk of Zarr array must be the same size or smaller than the first.
Or with more chunks: ValueError: Zarr requires uniform chunk sizes except for final chunk.

I could rechunk all the arrays with a variants dimension - this doesn't make for an easy time for the average user though.
Should save_dataset auto rechunk in these situations?

@tomwhite
Copy link
Collaborator

tomwhite commented Jan 3, 2023

Good question. When we added save_dataset we didn't include auto-rechunking, since it can perform poorly depending on chunk size, and it's good for the user to be aware of what's happening.

At a minimum we could improve the documentation, and give some examples (including at https://pystatgen.github.io/sgkit/latest/how_do_i.html#save-results-to-a-zarr-file).

We could also add an optional parameter to save_dataset to control rechunking; perhaps opt-in?

@benjeffery
Copy link
Collaborator Author

Thanks @tomwhite. I agree with your point about auto-rechunking being a heavy operation and it should be opt-in. I think adding an opt-in parameter to save_dataset would be nice. save_dataset could then detect that re-chunking was needed and throw a friendly error message pointing out the flag?

@tomwhite
Copy link
Collaborator

tomwhite commented Jan 4, 2023

I agree - this sounds like a good addition.

@benjeffery benjeffery changed the title Unequal chunks after subsetting. Add rechunking to save_dataset Jan 4, 2023
@tomwhite
Copy link
Collaborator

tomwhite commented Jan 4, 2023

This was mentioned in #296 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants