-
Notifications
You must be signed in to change notification settings - Fork 10
Adding explicit support for blosc but keeping deflate the default #747
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,9 @@ | |
| # pylint: disable=R0912 | ||
|
|
||
| import copy | ||
| import importlib.util | ||
| import logging | ||
| import os | ||
| import sys | ||
| import xml.etree.ElementTree as ET | ||
|
|
||
|
|
@@ -36,7 +38,28 @@ | |
| ) | ||
|
|
||
| logger = logging.getLogger("pynxtools") # pylint: disable=C0103 | ||
| from pynxtools.dataconverter.chunk import COMPRESSION_FILTERS, COMPRESSION_STRENGTH | ||
| from pynxtools.dataconverter.chunk import ( | ||
| COMPRESSION_FILTERS, | ||
| COMPRESSION_STRENGTH, | ||
| PYNX_ENABLE_BLOSC, | ||
| ) | ||
|
|
||
| if ( | ||
| PYNX_ENABLE_BLOSC | ||
| and importlib.util.find_spec("hdf5plugin") is not None | ||
| and importlib.util.find_spec("blosc2") is not None | ||
| ): | ||
|
Comment on lines
+47
to
+51
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either we add these two dependencies to optional in the pyproject.toml then we have a check for them here. Or we keep the pyproject with these as mandatory dependencies and skip the check. |
||
| import blosc2 | ||
| import hdf5plugin | ||
|
|
||
| NTHREADS_BLOSC = blosc2.set_nthreads(max(int(os.cpu_count() / 2), 1)) | ||
| # do not oversubscribe to use hyperthreading cores | ||
|
Comment on lines
+55
to
+56
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this necessary? Aren't there any sane defaults in the hdf5lib already? |
||
| logger.info( | ||
| f"blosc2 is configured to use {blosc2.nthreads} threads on host with {blosc2.ncores} cores" | ||
| ) | ||
| logger.info(blosc2.print_versions()) | ||
| else: | ||
| NTHREADS_BLOSC = 0 | ||
|
|
||
|
|
||
| def does_path_exist(path, h5py_obj) -> bool: | ||
|
|
@@ -153,7 +176,10 @@ def handle_dicts_entries(data, grp, entry_name, output_path, path, append): | |
| elif "compress" in data.keys(): | ||
| if not (isinstance(data["compress"], str) or np.isscalar(data["compress"])): | ||
| if ("filter" in data.keys()) and (data["filter"] in COMPRESSION_FILTERS): | ||
| compression_filter = data["filter"] | ||
| if PYNX_ENABLE_BLOSC and data["filter"] == "blosc": | ||
| compression_filter = data["filter"] | ||
| else: | ||
| compression_filter = COMPRESSION_FILTERS[0] | ||
| else: # fall-back to default | ||
| compression_filter = COMPRESSION_FILTERS[0] | ||
|
|
||
|
|
@@ -168,12 +194,19 @@ def handle_dicts_entries(data, grp, entry_name, output_path, path, append): | |
|
|
||
| if entry_name not in grp: | ||
| try: | ||
| if compression_filter == "gzip": | ||
| compression_config = dict( | ||
| compression=compression_filter, | ||
| compression_opts=compression_strength, | ||
| ) | ||
| else: # by virtue of construction blosc | ||
| compression_config = hdf5plugin.Blosc2(cname="zstd", clevel=9) | ||
| grp.create_dataset( | ||
| entry_name, | ||
| data=data["compress"], | ||
| compression=compression_filter, | ||
| chunks=chunking_strategy(data), | ||
| compression_opts=compression_strength, | ||
| **compression_config, | ||
|
Comment on lines
+197
to
+209
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can have one function that deals with our compression needs instead of if statements here. |
||
| ) | ||
| except ValueError: | ||
| logger.warning(f"ValueError caught upon creating_dataset {path}") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too much of an in code comment. Let's simplify and use some defaults or add this to a more accessible README.md section/link to another .md and/or to the docs.