DatasetChunker stops write slices at the 4MB minimum instead of filling toward the max - #693
Open
rhaegar325 wants to merge 1 commit into
Open
DatasetChunker stops write slices at the 4MB minimum instead of filling toward the max#693rhaegar325 wants to merge 1 commit into
DatasetChunker stops write slices at the 4MB minimum instead of filling toward the max#693rhaegar325 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #693 +/- ##
=====================================
Coverage 78.7% 78.8%
=====================================
Files 41 41
Lines 9061 9070 +9
Branches 1693 1692 -1
=====================================
+ Hits 7134 7143 +9
Misses 1592 1592
Partials 335 335
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Every daily variable was writing ~4MB Dask slices regardless of the 128MB
maximum, because
calculate_chunk_size_for_variable()only grew the timechunk far enough to reach
target_chunk_size_mb(the 4MB minimum) whena single time step was smaller than it. For
atmos.ta.tavg-p19-hxy-air.daythat meant 730 write slices per 4-year output file; each slice costs a
serial graph-cull /
client.compute/ gather round trip in the main process,so the Dask workers idled while that round trip repeated.
Fixed by batching time steps toward
max_chunk_size_mbin both regimes,which collapses the two branches into one expression.
Measured on real ACCESS-ESM1-6 data, PBS compute nodes,
tap19 daily,years 101-104, 7 workers / 128GB:
submit(serial, main process)Output is bit-identical: all 8 variables in the file compared element-wise,
including the full 1461x19x144x192
taarray.Root cause: a storage-chunk rule applied to Dask task size
DatasetChunkerarrived (3b8d03a0, 2025-12-09, PR #137 "Chunking of data tofollow new CMIP7 directives") with only a 4MB minimum and no upper bound
at all, framed as an HDF5 storage-layout rule — CMIP7 mandates >=4 MiB storage
chunks. With no ceiling to grow toward, "stop once you reach 4MB" was the
entire algorithm, not a decision against larger chunks.
But the value never set a storage chunk.
chunksizeswas passed briefly in429451f2(2025-12-03) via ato_netcdf/encoding write path and removed thesame day in
a56ea2adwhen the write was rewritten to the manual two-phasecreateVariablepath.DatasetChunkerlanded six days later into a code paththat no longer had storage chunking, so the 4MB floor has only ever controlled
Dask task size while carrying a storage-layout rule's name.
Two later PRs each fixed one half and left the other as found:
edcd014b(fix: bound Dask spatial chunk sizes #555, 2026-07-27) addedmax_chunk_size_mb=128.0purely as ashrink ceiling for oversized spatial slabs, and documented in the docstring
that these are not storage chunks. It never touched the growth side.
7e5efa2f(DatasetChunkernever batches multiple time steps when a single step already meets the minimum target #603, 2026-08-10) fixed growth for thestep size >= targetregime (
atmos.cl). Its own table listsstep size < targetas"unchanged: grows toward the 4MB target" — left alone because it satisfied
the original "at least 4MB" rule. Daily variables are almost all in that
regime (
tap19 is 2.02MB/step,tasis 0.11MB/step).The CMIP7 >=4 MiB directive is real and still enforced — by
cmip7repack -d(minimum 4194304). This change does not touch output storage chunks.
Change
src/access_moppy/base.py— both branches now use the same expression:The now-unused local
min_target_elementsis removed. Note thatself.target_chunk_size_bytesis left in place but has no remaining reader;target_chunk_size_mbis still validated againstmax_chunk_size_mbandlogged, so the constructor's public surface is unchanged.
Two diagnostic log lines were added alongside, because the investigation could
not attribute wall time without them and neither could the next one:
_write_dask_slicesreports slice count, slice size and thesubmit/wait/writesplit — onlywaitis parallel worker time._repack_cmip7_outputreports its elapsed time —cmip7repackis asingle-threaded external process, so its share of wall time is time no
worker can be busy for.