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

Switch to blosc2; add Python 3.12 support #719

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
fail-fast: false
steps:

Expand Down Expand Up @@ -90,7 +91,7 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]
fail-fast: false
steps:

Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ classifiers = [
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Physics",
]

Expand All @@ -51,7 +52,7 @@ all = [
"asyncpg",
"appdirs",
"awkward >=2.4.3",
"blosc",
"blosc2",
"cachetools",
"cachey",
"click !=8.1.0",
Expand Down Expand Up @@ -108,7 +109,7 @@ array = [
client = [
"appdirs",
"awkward >=2.4.3",
"blosc",
"blosc2",
"click !=8.1.0",
"dask[array]",
"dask[dataframe]",
Expand All @@ -132,7 +133,7 @@ client = [
# These are used by the client/server to more efficiently compress.
# They fall back to gzip (which is slower) if these are not installed.
compression = [
"blosc",
"blosc2",
"lz4",
"zstandard",
]
Expand Down Expand Up @@ -233,7 +234,7 @@ server = [
"asgi-correlation-id",
"asyncpg",
"awkward >=2.4.3",
"blosc",
"blosc2",
"cachetools",
"cachey",
"click !=8.1.0",
Expand Down
6 changes: 3 additions & 3 deletions tiled/client/decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ..utils import modules_available

if modules_available("blosc"):
if modules_available("blosc2"):

class BloscDecoder:
def __init__(self):
Expand All @@ -18,13 +18,13 @@ def decode(self, data: bytes) -> bytes:

def flush(self) -> bytes:
# Hide this here to defer the numpy import that it triggers.
import blosc
import blosc2

if len(self._data) == 1:
(data,) = self._data
else:
data = b"".join(self._data)
return blosc.decompress(data)
return blosc2.decompress(data)

SUPPORTED_DECODERS["blosc"] = BloscDecoder

Expand Down
14 changes: 4 additions & 10 deletions tiled/media_type_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,8 @@ def close(self):
]:
compression_registry.register(media_type, "lz4", LZ4Buffer)

if modules_available("blosc"):
import blosc

# The choice of settings here is cribbed from distributed.protocol.compression.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cargo-culted these settings from dask.distributed in the first place without any benchmarking. They aren't directly transferrable to blsoc2, so I have reverted to just going with the defaults for now until we have time to benchmark.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to retain this TODO as a comment or as a low-priority github issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Done #724

n = blosc.set_nthreads(2)
if hasattr("blosc", "releasegil"):
blosc.set_releasegil(True)
blosc_settings = {"cname": "lz4", "clevel": 5}
if modules_available("blosc2"):
import blosc2

class BloscBuffer:
"""
Expand All @@ -352,9 +346,9 @@ def write(self, b):
if hasattr(b, "itemsize"):
# This could be memoryview or numpy.ndarray, for example.
# Blosc uses item-aware shuffling for improved results.
compressed = blosc.compress(b, typesize=b.itemsize, **blosc_settings)
compressed = blosc2.compress(b, typesize=b.itemsize)
else:
compressed = blosc.compress(b, **blosc_settings)
compressed = blosc2.compress(b)
self._file.write(compressed)

def close(self):
Expand Down
Loading