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

[v3] Buffer ensure correct subclass based on the BufferPrototype argument #1974

Merged
merged 4 commits into from
Jun 25, 2024

Conversation

madsbk
Copy link
Contributor

@madsbk madsbk commented Jun 18, 2024

TODO:

  • Add unit tests and/or doctests in docstrings
  • Add docstrings and API docs for any new/modified user-facing classes and functions
  • New/modified features documented in docs/tutorial.rst
  • Changes documented in docs/release.rst
  • GitHub Actions have all passed
  • Test coverage is 100% (Codecov passes)

src/zarr/buffer.py Outdated Show resolved Hide resolved
@madsbk madsbk mentioned this pull request Jun 18, 2024
6 tasks
Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
@madsbk madsbk marked this pull request as ready for review June 18, 2024 08:33
@madsbk madsbk requested a review from d-v-b June 25, 2024 10:54
src/zarr/buffer.py Outdated Show resolved Hide resolved
src/zarr/buffer.py Outdated Show resolved Hide resolved
Co-authored-by: Davis Bennett <davis.v.bennett@gmail.com>
@d-v-b
Copy link
Contributor

d-v-b commented Jun 25, 2024

I have a broader question about the relationship between the store API and different flavors of buffer (This question is out of scope for this PR, but the answer would help me interpret the effort here).

Taking MemoryStore.get as an example, we have

async def get(
        self,
        key: str,
        prototype: BufferPrototype,
        byte_range: tuple[int | None, int | None] | None = None,
    ) -> Buffer | None:

key and byte range are parametrizing the resource that the store is going to get; we can think of this as basically a query against a {keys: seekable_bytes} map-abstraction of a storage backend. But prototype is different -- it's determining the concrete return type of get.

Do we expect arrays / groups to dynamically use prototype parameter? For example, is the same array instance going to call store.get(prototype=GPUBuffer) for some chunks, and store.get(prototype=CPUBuffer) for other chunks? Alternatively, we might want to constrain a store instance to always use a fixed buffer type, in which case maybe the prototype should be an attribute of the store class? Sorry if I missed a discussion that explains the design here.

@madsbk
Copy link
Contributor Author

madsbk commented Jun 25, 2024

Do we expect arrays / groups to dynamically use prototype parameter? For example, is the same array instance going to call store.get(prototype=GPUBuffer) for some chunks, and store.get(prototype=CPUBuffer) for other chunks?

Yes, e.g. for GPU backed arrays we want the metadata to use CPUBuffer and the data to use GPUBuffer. Furthermore, the end-user might also want to load some part of the array into a numpy array and other parts into a cupy array.

@d-v-b
Copy link
Contributor

d-v-b commented Jun 25, 2024

thanks! that's very helpful

@d-v-b d-v-b merged commit c677da4 into zarr-developers:v3 Jun 25, 2024
18 checks passed
@madsbk
Copy link
Contributor Author

madsbk commented Jun 25, 2024

Thanks @d-v-b !

dcherian added a commit to dcherian/zarr-python that referenced this pull request Jun 25, 2024
* v3: (22 commits)
  [v3] `Buffer` ensure correct subclass based on the `BufferPrototype` argument (zarr-developers#1974)
  Fix doc build (zarr-developers#1987)
  Fix doc build warnings (zarr-developers#1985)
  Automatically generate API reference docs (zarr-developers#1918)
  Update `RemoteStore.__str__` and add UPath tests (zarr-developers#1964)
  [v3] Elevate codec pipeline (zarr-developers#1932)
  0 dim arrays: indexing (zarr-developers#1980)
  `parse_shapelike` allows 0 (zarr-developers#1979)
  Clean up typing and docs for indexing (zarr-developers#1961)
  add json indentation to config (zarr-developers#1952)
  chore: update pre-commit hooks (zarr-developers#1973)
  Bump pypa/gh-action-pypi-publish in the actions group (zarr-developers#1969)
  chore: update pre-commit hooks (zarr-developers#1957)
  Update release.rst (zarr-developers#1960)
  doc: update release notes for 3.0.0.alpha (zarr-developers#1959)
  Basic working FsspecStore (zarr-developers#1785)
  Feature: Top level V3 API (zarr-developers#1884)
  Buffer Prototype Argument (zarr-developers#1910)
  Create issue-metrics.yml
  fixes bug in transpose (zarr-developers#1949)
  ...
@madsbk madsbk deleted the buffer-from-buffer branch June 28, 2024 10:38
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