Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refactor zarr data copying to use store.set instead of fsspec operations#194

Merged
mosegontar merged 3 commits into
mainfrom
remove-fsspec-copy-put-operations
Aug 6, 2025
Merged

Refactor zarr data copying to use store.set instead of fsspec operations#194
mosegontar merged 3 commits into
mainfrom
remove-fsspec-copy-put-operations

Conversation

@mosegontar

@mosegontar mosegontar commented Aug 5, 2025

Copy link
Copy Markdown
Contributor

This PR refactors how we handle copying of data shards and metadata from the tmp store to another storage location. Instead of using fsspec_apply we can use the set method on our destination store. This also sets us up to be able to interface with an icechunk store in the same way (where fsspec operations would not work).

Comment thread src/reformatters/common/zarr.py Outdated
PROCESSED_VARIABLES_KEY = "processed_variables"


def _get_fs_and_path(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved this into here because now it is the only module making use of this function and we intend to deprecate/remove when we move onto refactoring progress tracking.

@mosegontar mosegontar changed the title Initial replacement of fsspec interactions with store.set Refactor zarr data copying to use store.set instead of fsspec operations Aug 6, 2025
@mosegontar mosegontar marked this pull request as ready for review August 6, 2025 15:12
Comment thread src/reformatters/common/zarr.py Outdated
zarr.core.sync.sync(
store.set(
key,
zarr.core.buffer.cpu.Buffer.from_bytes(data),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If there's any way we can avoid a copy when creating the Buffer that would be ideal. im not sure we can but check out the methods on it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh good thought, i'll take a look

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For posterity, we tracked this down and it looks like the CPU buffer will use np.frombuffer https://zarr.readthedocs.io/en/main/_modules/zarr/core/buffer/cpu.html#Buffer.from_bytes

which won't make a copy https://numpy.org/doc/2.1/reference/generated/numpy.frombuffer.html

source = f"{tmp_store / relative_dir}/"
dest = f"{path}/{relative_dir}"
fsspec_apply(fs, "put", source, dest, recursive=True, auto_mkdir=True)
for file in tmp_store.glob(f"{relative_dir}**/*"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is likely going from parallel to not parallel. lets keep an eye on if this is impacting perf at all, but i think it should be fine

@aldenks aldenks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approved after comments!

@mosegontar mosegontar merged commit 1becc8f into main Aug 6, 2025
5 checks passed
@mosegontar mosegontar deleted the remove-fsspec-copy-put-operations branch August 6, 2025 16:44
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 this pull request may close these issues.

2 participants