-
-
Save K-Meech/7c0f34fb6de4be86e9f394a33e401e94 to your computer and use it in GitHub Desktop.
Test with latency
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
| from typing import Any | |
| import zarr | |
| from zarr.metadata.migrate_v3 import migrate_v2_to_v3 | |
| from zarr.testing.store import LatencyStore | |
| from zarr.abc.store import Store | |
| import time | |
| def create_nested_zarr(store: Store, attributes: dict[str, Any], separator: str, levels: int) -> list[str]: | |
| """Create a zarr with nested groups / arrays""" | |
| root_group = zarr.create_group(store=store, zarr_format=2, attributes=attributes, overwrite=True) | |
| groups = [root_group] | |
| # n levels of nested groups | |
| for i in range(levels): | |
| new_group = groups[-1].create_group(name=f"g_{i}", attributes=attributes, overwrite=True) | |
| groups.append(new_group) | |
| # 1 array per group | |
| array = new_group.create_array( | |
| name=f"a_{i}", | |
| shape=(10, 10), | |
| chunks=(5, 5), | |
| dtype="uint16", | |
| attributes=attributes, | |
| chunk_key_encoding={"name": "v2", "separator": separator}, | |
| overwrite=True | |
| ) | |
| array[:] = 1 | |
| create_nested_zarr("data/images/nested-latent-zarr.zarr", {"baz": 42, "qux": [1, 4, 7, 12]}, "/", 30) | |
| local_store = zarr.storage.LocalStore("data/images/nested-latent-zarr.zarr", read_only=False) | |
| latency_store = LatencyStore(local_store, get_latency=0.1, set_latency=0.1) | |
| start_time = time.perf_counter() | |
| migrate_v2_to_v3(input_store=latency_store) | |
| end_time = time.perf_counter() | |
| print(end_time - start_time, "seconds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment