diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c1104d4..94b514c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,15 +2,17 @@ ci: autoupdate_commit_msg: "chore: update pre-commit hooks" autofix_commit_msg: "style: pre-commit fixes" +exclude: ^src/pscpy/sample/.*$ + repos: - repo: https://github.com/adamchainz/blacken-docs - rev: "1.16.0" + rev: "1.19.1" hooks: - id: blacken-docs additional_dependencies: [black==24.*] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.6.0" + rev: "v5.0.0" hooks: - id: check-added-large-files - id: check-case-conflict @@ -33,27 +35,27 @@ repos: - id: rst-inline-touching-normal - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.1.0" + rev: "v4.0.0-alpha.8" hooks: - id: prettier types_or: [yaml, markdown, html, css, scss, javascript, json] args: [--prose-wrap=always] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.4.1" + rev: "v0.8.4" hooks: - id: ruff args: ["--fix", "--show-fixes"] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-clang-format - rev: "v18.1.4" + rev: "v19.1.5" hooks: - id: clang-format types_or: [c++, c, cuda] - repo: https://github.com/pre-commit/mirrors-mypy - rev: "v1.9.0" + rev: "v1.13.0" hooks: - id: mypy files: src|tests @@ -64,7 +66,7 @@ repos: - adios2 - repo: https://github.com/codespell-project/codespell - rev: "v2.2.6" + rev: "v2.3.0" hooks: - id: codespell @@ -87,13 +89,13 @@ repos: - id: cmake-format - repo: https://github.com/abravalheri/validate-pyproject - rev: "v0.16" + rev: "v0.23" hooks: - id: validate-pyproject additional_dependencies: ["validate-pyproject-schema-store[all]"] - repo: https://github.com/python-jsonschema/check-jsonschema - rev: "0.28.2" + rev: "0.30.0" hooks: - id: check-dependabot - id: check-github-workflows diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 92689b8..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -cmake_minimum_required(VERSION 3.15...3.26) - -set(SKBUILD_PROJECT_NAME pscpy) - -project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) diff --git a/pyproject.toml b/pyproject.toml index 415c37c..996a2b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,8 @@ Homepage = "https://github.com/psc-code/pscpy" Discussions = "https://github.com/psc-code/pscpy/discussions" Changelog = "https://github.com/psc-code/pscpy/releases" +[project.entry-points."xarray.backends"] +pscadios2_engine = "pscpy.pscadios2:PscAdios2BackendEntrypoint" [build-system] build-backend = "setuptools.build_meta" diff --git a/src/pscpy/__init__.py b/src/pscpy/__init__.py index ef4e961..cf141e9 100644 --- a/src/pscpy/__init__.py +++ b/src/pscpy/__init__.py @@ -6,8 +6,13 @@ from __future__ import annotations +import pathlib + from pscpy import pscadios2 # noqa: F401 from ._version import version as __version__ +sample_dir = pathlib.Path(__file__).parent / "sample" + + __all__ = ["__version__"] diff --git a/src/pscpy/adios2py/__init__.py b/src/pscpy/adios2py/__init__.py index 97fef40..f3b0ae3 100644 --- a/src/pscpy/adios2py/__init__.py +++ b/src/pscpy/adios2py/__init__.py @@ -1,6 +1,7 @@ from __future__ import annotations import logging +import os from collections.abc import Collection from types import TracebackType from typing import Any, SupportsInt @@ -109,10 +110,10 @@ def __repr__(self) -> str: class FileState: """Collects the state of a `File` to reflect the fact that they are coupled.""" - def __init__(self, filename: str) -> None: + def __init__(self, filename: str | os.PathLike[Any]) -> None: self.io_name = f"io-{filename}" self.io = _ad.declare_io(self.io_name) - self.engine = self.io.open(filename, adios2.bindings.Mode.Read) + self.engine = self.io.open(str(filename), adios2.bindings.Mode.Read) @staticmethod def is_open(maybe_state: FileState | None) -> TypeGuard[FileState]: @@ -124,7 +125,7 @@ class File: _state: FileState | None - def __init__(self, filename: str, mode: str = "r") -> None: + def __init__(self, filename: str | os.PathLike[Any], mode: str = "r") -> None: logging.debug("adios2py: __init__ %s", filename) assert mode == "r" self._state = FileState(filename) diff --git a/src/pscpy/pscadios2.py b/src/pscpy/pscadios2.py index 70e599a..bde3a44 100644 --- a/src/pscpy/pscadios2.py +++ b/src/pscpy/pscadios2.py @@ -10,7 +10,6 @@ from typing_extensions import Never, override from xarray.backends import CachingFileManager from xarray.backends.common import ( - BACKEND_ENTRYPOINTS, AbstractDataStore, BackendArray, BackendEntrypoint, @@ -198,6 +197,3 @@ def guess_can_open(self, filename_or_obj: str | os.PathLike[Any] | ReadBuffer[An @override def open_datatree(self, filename_or_obj: str | os.PathLike[Any] | ReadBuffer[Any] | AbstractDataStore, **kwargs: Any) -> DataTree: raise NotImplementedError() - - -BACKEND_ENTRYPOINTS["pscadios2"] = ("pscpy", PscAdios2BackendEntrypoint) diff --git a/src/pscpy/sample/pfd.000000400.bp/data.0 b/src/pscpy/sample/pfd.000000400.bp/data.0 new file mode 100644 index 0000000..6465188 Binary files /dev/null and b/src/pscpy/sample/pfd.000000400.bp/data.0 differ diff --git a/src/pscpy/sample/pfd.000000400.bp/md.0 b/src/pscpy/sample/pfd.000000400.bp/md.0 new file mode 100644 index 0000000..6d51316 Binary files /dev/null and b/src/pscpy/sample/pfd.000000400.bp/md.0 differ diff --git a/src/pscpy/sample/pfd.000000400.bp/md.idx b/src/pscpy/sample/pfd.000000400.bp/md.idx new file mode 100644 index 0000000..5f0aa39 Binary files /dev/null and b/src/pscpy/sample/pfd.000000400.bp/md.idx differ diff --git a/src/pscpy/sample/pfd.000000400.bp/profiling.json b/src/pscpy/sample/pfd.000000400.bp/profiling.json new file mode 100644 index 0000000..742fdcd --- /dev/null +++ b/src/pscpy/sample/pfd.000000400.bp/profiling.json @@ -0,0 +1,6 @@ +[ +{ "rank": 0, "start": "Tue_Sep_27_10:16:01_2022", "threads": 1, "bytes": 590260, "mkdir_mus": 193, "memcpy_mus": 505340, "aggregation_mus": 0, "meta_sort_merge_mus": 320, "minmax_mus": 148649, "buffering_mus": 668923, "transport_0": { "type": "File_POSIX", "close_mus": 216, "write_mus": 643, "open_mus": 244 },"transport_1": { "type": "File_POSIX", "close_mus": 0, "write_mus": 41, "open_mus": 250 } }, +{ "rank": 1, "start": "Tue_Sep_27_10:16:01_2022", "threads": 1, "bytes": 590193, "mkdir_mus": 201, "memcpy_mus": 505280, "aggregation_mus": 0, "meta_sort_merge_mus": 165, "minmax_mus": 147485, "buffering_mus": 667610, }, +{ "rank": 2, "start": "Tue_Sep_27_10:16:01_2022", "threads": 1, "bytes": 590193, "mkdir_mus": 205, "memcpy_mus": 472637, "aggregation_mus": 0, "meta_sort_merge_mus": 52, "minmax_mus": 148323, "buffering_mus": 635610, }, +{ "rank": 3, "start": "Tue_Sep_27_10:16:01_2022", "threads": 1, "bytes": 590193, "mkdir_mus": 201, "memcpy_mus": 484106, "aggregation_mus": 0, "meta_sort_merge_mus": 29, "minmax_mus": 148251, "buffering_mus": 647150, } +] diff --git a/tests/test_adios2py.py b/tests/test_adios2py.py new file mode 100644 index 0000000..c00e883 --- /dev/null +++ b/tests/test_adios2py.py @@ -0,0 +1,8 @@ +from __future__ import annotations + +import pscpy +from pscpy import adios2py + + +def test_adios2py_open(): + adios2py.File(pscpy.sample_dir / "pfd.000000400.bp") diff --git a/tests/test_xarray_adios2.py b/tests/test_xarray_adios2.py new file mode 100644 index 0000000..cf08ecd --- /dev/null +++ b/tests/test_xarray_adios2.py @@ -0,0 +1,9 @@ +from __future__ import annotations + +import xarray as xr + +import pscpy + + +def test_open_dataset(): + xr.open_dataset(pscpy.sample_dir / "pfd.000000400.bp", species_names=[], length=[10, 10, 10], corner=[0, 0, 0])