hidefix


Namehidefix JSON
Version 0.9.0 PyPI version JSON
download
home_page
SummaryConcurrent HDF5 and NetCDF4 reader (experimental)
upload_time2023-11-19 09:02:48
maintainer
docs_urlNone
authorGaute Hope <eg@gaute.vetsj.com>
requires_python>=3.8
licenseLGPL-3.0-or-later
keywords hdf async concurrency
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Crates.io](https://img.shields.io/crates/v/hidefix.svg)](https://crates.io/crates/hidefix)
[![PyPI](https://img.shields.io/pypi/v/hidefix.svg)](https://pypi.org/project/hidefix/)
[![Documentation](https://docs.rs/hidefix/badge.svg)](https://docs.rs/hidefix/)
[![Build (rust)](https://github.com/gauteh/hidefix/workflows/Rust/badge.svg)](https://github.com/gauteh/hidefix/actions?query=branch%3Amain)
[![Build (python)](https://github.com/gauteh/hidefix/workflows/Python/badge.svg)](https://github.com/gauteh/hidefix/actions?query=branch%3Amain)
[![codecov](https://codecov.io/gh/gauteh/hidefix/branch/main/graph/badge.svg)](https://codecov.io/gh/gauteh/hidefix)
[![Rust nightly](https://img.shields.io/badge/rustc-nightly-orange)](https://rust-lang.github.io/rustup/installation/other.html)

<img src="https://raw.githubusercontent.com/gauteh/hidefix/main/idefix.png">

# HIDEFIX

This Rust and Python library provides an alternative reader for the
[HDF5](https://support.hdfgroup.org/HDF5/doc/H5.format.html) file or [NetCDF4
file](https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html)
(which uses HDF5) which supports concurrent access to data. This is achieved by
building an index of the chunks, allowing a thread to use many file handles to
read the file. The original (native) HDF5 library is used to build the index,
but once it has been created it is no longer needed. The index can be
serialized to disk so that performing the indexing is not necessary.

In Rust:

```rust
use hidefix::prelude::*;

let idx = Index::index("tests/data/coads_climatology.nc4").unwrap();
let mut r = idx.reader("SST").unwrap();

let values = r.values::<f32>(None, None).unwrap();

println!("SST: {:?}", values);
```

or with Python using Xarray:
```python
import xarray as xr
import hidefix

ds = xr.open_dataset('file.nc', engine='hidefix')
print(ds)
```

See the [example](examples/) for how to use hidefix for
[regular](examples/read_hfx_cache.rs), [parallel](examples/read_hfx_parallel.rs) or
[concurrent](examples/read_hfx_concurrent.rs) reads.

## Motivation

The HDF5 library requires internal locks to be _thread-safe_ since it relies on
internal buffers which cannot be safely accessed/written to from multiple
threads. This effectively causes multi-threaded applications to use sequential
reads, while competing for the locks. And also apparently cause each other
trouble, perhaps through dropping cached chunks which other threads still need.
It can be safely used from different processes, but that requires potentially
much more overhead than multi-threaded or asynchronous code.

## Some basic benchmarks

`hidefix` is intended to perform better when concurrent reads are made either
to the same dataset, same file or to different files from a single process. For
basic benchmarks the performance is on-par or slightly better compared to doing
standard *sequential* reads than the native HDF5 library (through its
[rust-bindings](https://github.com/aldanor/hdf5-rust)). Where `hidefix` shines
is once the _multiple threads_ in the _same process_ tries to read in _any way_
from a HDF5 file simultaneously.

This simple benchmark tries to read a small dataset sequentially or
concurrently using the `cached` reader from `hidefix` and the native reader
from HDF5. The dataset is chunked, shuffled and compressed (using gzip):

```sh
$ cargo bench --bench concurrency -- --ignored

test shuffled_compressed::cache_concurrent_reads  ... bench:  15,903,406 ns/iter (+/- 220,824)
test shuffled_compressed::cache_sequential        ... bench:  59,778,761 ns/iter (+/- 602,316)
test shuffled_compressed::native_concurrent_reads ... bench: 411,605,868 ns/iter (+/- 35,346,233)
test shuffled_compressed::native_sequential       ... bench: 103,457,237 ns/iter (+/- 7,703,936)
```

## Inspiration and other projects

This work is based in part on the [DMR++
module](https://github.com/OPENDAP/bes/tree/master/modules/dmrpp_module) of the
[OPeNDAP](https://www.opendap.org/) [Hyrax
server](https://www.opendap.org/software/hyrax-data-server). The
[zarr](https://zarr.readthedocs.io/en/stable/) format does something similar,
and the same approach has been [tested out on
HDF5](https://medium.com/pangeo/cloud-performant-reading-of-netcdf4-hdf5-data-using-the-zarr-library-1a95c5c92314)
as swell.



            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "hidefix",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "hdf,async,concurrency",
    "author": "Gaute Hope <eg@gaute.vetsj.com>",
    "author_email": "Gaute Hope <eg@gaute.vetsj.com>",
    "download_url": "https://files.pythonhosted.org/packages/c0/4d/5aedd8e9d1e0165fd8d218348292ccf26ea9bced30a9ff03a2a8954e1432/hidefix-0.9.0.tar.gz",
    "platform": null,
    "description": "[![Crates.io](https://img.shields.io/crates/v/hidefix.svg)](https://crates.io/crates/hidefix)\n[![PyPI](https://img.shields.io/pypi/v/hidefix.svg)](https://pypi.org/project/hidefix/)\n[![Documentation](https://docs.rs/hidefix/badge.svg)](https://docs.rs/hidefix/)\n[![Build (rust)](https://github.com/gauteh/hidefix/workflows/Rust/badge.svg)](https://github.com/gauteh/hidefix/actions?query=branch%3Amain)\n[![Build (python)](https://github.com/gauteh/hidefix/workflows/Python/badge.svg)](https://github.com/gauteh/hidefix/actions?query=branch%3Amain)\n[![codecov](https://codecov.io/gh/gauteh/hidefix/branch/main/graph/badge.svg)](https://codecov.io/gh/gauteh/hidefix)\n[![Rust nightly](https://img.shields.io/badge/rustc-nightly-orange)](https://rust-lang.github.io/rustup/installation/other.html)\n\n<img src=\"https://raw.githubusercontent.com/gauteh/hidefix/main/idefix.png\">\n\n# HIDEFIX\n\nThis Rust and Python library provides an alternative reader for the\n[HDF5](https://support.hdfgroup.org/HDF5/doc/H5.format.html) file or [NetCDF4\nfile](https://www.unidata.ucar.edu/software/netcdf/docs/file_format_specifications.html)\n(which uses HDF5) which supports concurrent access to data. This is achieved by\nbuilding an index of the chunks, allowing a thread to use many file handles to\nread the file. The original (native) HDF5 library is used to build the index,\nbut once it has been created it is no longer needed. The index can be\nserialized to disk so that performing the indexing is not necessary.\n\nIn Rust:\n\n```rust\nuse hidefix::prelude::*;\n\nlet idx = Index::index(\"tests/data/coads_climatology.nc4\").unwrap();\nlet mut r = idx.reader(\"SST\").unwrap();\n\nlet values = r.values::<f32>(None, None).unwrap();\n\nprintln!(\"SST: {:?}\", values);\n```\n\nor with Python using Xarray:\n```python\nimport xarray as xr\nimport hidefix\n\nds = xr.open_dataset('file.nc', engine='hidefix')\nprint(ds)\n```\n\nSee the [example](examples/) for how to use hidefix for\n[regular](examples/read_hfx_cache.rs), [parallel](examples/read_hfx_parallel.rs) or\n[concurrent](examples/read_hfx_concurrent.rs) reads.\n\n## Motivation\n\nThe HDF5 library requires internal locks to be _thread-safe_ since it relies on\ninternal buffers which cannot be safely accessed/written to from multiple\nthreads. This effectively causes multi-threaded applications to use sequential\nreads, while competing for the locks. And also apparently cause each other\ntrouble, perhaps through dropping cached chunks which other threads still need.\nIt can be safely used from different processes, but that requires potentially\nmuch more overhead than multi-threaded or asynchronous code.\n\n## Some basic benchmarks\n\n`hidefix` is intended to perform better when concurrent reads are made either\nto the same dataset, same file or to different files from a single process. For\nbasic benchmarks the performance is on-par or slightly better compared to doing\nstandard *sequential* reads than the native HDF5 library (through its\n[rust-bindings](https://github.com/aldanor/hdf5-rust)). Where `hidefix` shines\nis once the _multiple threads_ in the _same process_ tries to read in _any way_\nfrom a HDF5 file simultaneously.\n\nThis simple benchmark tries to read a small dataset sequentially or\nconcurrently using the `cached` reader from `hidefix` and the native reader\nfrom HDF5. The dataset is chunked, shuffled and compressed (using gzip):\n\n```sh\n$ cargo bench --bench concurrency -- --ignored\n\ntest shuffled_compressed::cache_concurrent_reads  ... bench:  15,903,406 ns/iter (+/- 220,824)\ntest shuffled_compressed::cache_sequential        ... bench:  59,778,761 ns/iter (+/- 602,316)\ntest shuffled_compressed::native_concurrent_reads ... bench: 411,605,868 ns/iter (+/- 35,346,233)\ntest shuffled_compressed::native_sequential       ... bench: 103,457,237 ns/iter (+/- 7,703,936)\n```\n\n## Inspiration and other projects\n\nThis work is based in part on the [DMR++\nmodule](https://github.com/OPENDAP/bes/tree/master/modules/dmrpp_module) of the\n[OPeNDAP](https://www.opendap.org/) [Hyrax\nserver](https://www.opendap.org/software/hyrax-data-server). The\n[zarr](https://zarr.readthedocs.io/en/stable/) format does something similar,\nand the same approach has been [tested out on\nHDF5](https://medium.com/pangeo/cloud-performant-reading-of-netcdf4-hdf5-data-using-the-zarr-library-1a95c5c92314)\nas swell.\n\n\n",
    "bugtrack_url": null,
    "license": "LGPL-3.0-or-later",
    "summary": "Concurrent HDF5 and NetCDF4 reader (experimental)",
    "version": "0.9.0",
    "project_urls": {
        "Source Code": "https://github.com/gauteh/hidefix"
    },
    "split_keywords": [
        "hdf",
        "async",
        "concurrency"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "504bfea42c0928a95f6fae10234ab50a19a0189426cfa6f9cdbca1a68900379a",
                "md5": "50ccb936552edc9006cecea368e7fb95",
                "sha256": "3940e0f0f5ed5956b30d3791bc349344a9c70cdf689a74d147e1b2a234d68bb8"
            },
            "downloads": -1,
            "filename": "hidefix-0.9.0-cp38-abi3-macosx_10_12_x86_64.whl",
            "has_sig": false,
            "md5_digest": "50ccb936552edc9006cecea368e7fb95",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 1801581,
            "upload_time": "2023-11-19T09:02:40",
            "upload_time_iso_8601": "2023-11-19T09:02:40.697416Z",
            "url": "https://files.pythonhosted.org/packages/50/4b/fea42c0928a95f6fae10234ab50a19a0189426cfa6f9cdbca1a68900379a/hidefix-0.9.0-cp38-abi3-macosx_10_12_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa545c539db93f5f305e5e9dbfce29d72093d932b1bf742dba746f567a4e8581",
                "md5": "fb50a2df4b27e9f34906c062a4cef86a",
                "sha256": "c70db38c8474ead0c75cc21756bec9bd3376e8404997b6151377f871fb7a7bd1"
            },
            "downloads": -1,
            "filename": "hidefix-0.9.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "fb50a2df4b27e9f34906c062a4cef86a",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 9556668,
            "upload_time": "2023-11-19T09:02:43",
            "upload_time_iso_8601": "2023-11-19T09:02:43.431046Z",
            "url": "https://files.pythonhosted.org/packages/fa/54/5c539db93f5f305e5e9dbfce29d72093d932b1bf742dba746f567a4e8581/hidefix-0.9.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e8a0b5d9ff3e6100d36a362e901293540e894d3e16bc1ab64e7a1d2f574b6fe",
                "md5": "b131838a7acd4918950a6efba874b244",
                "sha256": "6c269fcf8548db8c703aac74743eb38c866356f2cf265c529f582ad9c6ba608e"
            },
            "downloads": -1,
            "filename": "hidefix-0.9.0-cp38-abi3-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "b131838a7acd4918950a6efba874b244",
            "packagetype": "bdist_wheel",
            "python_version": "cp38",
            "requires_python": ">=3.8",
            "size": 1919259,
            "upload_time": "2023-11-19T09:02:46",
            "upload_time_iso_8601": "2023-11-19T09:02:46.209033Z",
            "url": "https://files.pythonhosted.org/packages/9e/8a/0b5d9ff3e6100d36a362e901293540e894d3e16bc1ab64e7a1d2f574b6fe/hidefix-0.9.0-cp38-abi3-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c04d5aedd8e9d1e0165fd8d218348292ccf26ea9bced30a9ff03a2a8954e1432",
                "md5": "d9ea55e7a57e3de68a369bd6671f8d13",
                "sha256": "228cf0748279546047eda25acb90b4fdaa344ad4d37b36e34c74d5558498172a"
            },
            "downloads": -1,
            "filename": "hidefix-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "d9ea55e7a57e3de68a369bd6671f8d13",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 9152029,
            "upload_time": "2023-11-19T09:02:48",
            "upload_time_iso_8601": "2023-11-19T09:02:48.599673Z",
            "url": "https://files.pythonhosted.org/packages/c0/4d/5aedd8e9d1e0165fd8d218348292ccf26ea9bced30a9ff03a2a8954e1432/hidefix-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-19 09:02:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gauteh",
    "github_project": "hidefix",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "hidefix"
}
        
Elapsed time: 0.13619s