From 9cfba09eaf9d24ed2f46d1ba0010bda4353f9bc8 Mon Sep 17 00:00:00 2001 From: Juniper Tyree Date: Mon, 25 Aug 2025 11:44:45 +0300 Subject: [PATCH 1/3] Add random projection codec to the benchmark --- .../compressor/compressors/__init__.py | 4 ++++ .../compressor/compressors/rp.py | 21 +++++++++++++++++++ .../compressor/compressors/rp_dct.py | 19 +++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 src/climatebenchpress/compressor/compressors/rp.py create mode 100644 src/climatebenchpress/compressor/compressors/rp_dct.py diff --git a/src/climatebenchpress/compressor/compressors/__init__.py b/src/climatebenchpress/compressor/compressors/__init__.py index b523c75..7ae1bda 100644 --- a/src/climatebenchpress/compressor/compressors/__init__.py +++ b/src/climatebenchpress/compressor/compressors/__init__.py @@ -2,6 +2,8 @@ "BitRound", "BitRoundPco", "Jpeg2000", + "RP", + "RPDct", "Sperr", "StochRound", "StochRoundPco", @@ -15,6 +17,8 @@ from .bitround import BitRound from .bitround_pco import BitRoundPco from .jpeg2000 import Jpeg2000 +from .rp import RP +from .rp_dct import RPDct from .sperr import Sperr from .stochround import StochRound from .stochround_pco import StochRoundPco diff --git a/src/climatebenchpress/compressor/compressors/rp.py b/src/climatebenchpress/compressor/compressors/rp.py new file mode 100644 index 0000000..e3a1456 --- /dev/null +++ b/src/climatebenchpress/compressor/compressors/rp.py @@ -0,0 +1,21 @@ +__all__ = ["RP"] + +import numcodecs_random_projection +import numcodecs_wasm_swizzle_reshape +from numcodecs_combinators.stack import CodecStack + +from .abc import Compressor + + +class RP(Compressor): + name = "rp" + description = "Random Projection (Gaussian)" + + @staticmethod + def abs_bound_codec(error_bound, **kwargs): + return CodecStack( + numcodecs_wasm_swizzle_reshape.SwizzleReshape(axes=[[0, 1, 2], [3, 4]]), + numcodecs_random_projection.RPCodec( + mae=error_bound, method="gaussian", seed=42 + ), + ) diff --git a/src/climatebenchpress/compressor/compressors/rp_dct.py b/src/climatebenchpress/compressor/compressors/rp_dct.py new file mode 100644 index 0000000..0a3422b --- /dev/null +++ b/src/climatebenchpress/compressor/compressors/rp_dct.py @@ -0,0 +1,19 @@ +__all__ = ["RPDct"] + +import numcodecs_random_projection +import numcodecs_wasm_swizzle_reshape +from numcodecs_combinators.stack import CodecStack + +from .abc import Compressor + + +class RPDct(Compressor): + name = "rp-dct" + description = "Random Projection (DCT)" + + @staticmethod + def abs_bound_codec(error_bound, **kwargs): + return CodecStack( + numcodecs_wasm_swizzle_reshape.SwizzleReshape(axes=[[0, 1, 2], [3, 4]]), + numcodecs_random_projection.RPCodec(mae=error_bound, method="dct", seed=0), + ) From 44d0f4e019519deb8c8e5eb8f84e704f05d9d6d6 Mon Sep 17 00:00:00 2001 From: Juniper Tyree Date: Mon, 25 Aug 2025 11:48:31 +0300 Subject: [PATCH 2/3] Add numcodecs-wasm-swizzle-reshape to the deps --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 9f91171..a1b05c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dependencies = [ "numcodecs-wasm-round~=0.4.0", "numcodecs-wasm-sperr~=0.1.0", "numcodecs-wasm-stochastic-rounding~=0.1.1", + "numcodecs-wasm-swizzle-reshape~=0.3.0", "numcodecs-wasm-sz3~=0.6.0", "numcodecs-wasm-tthresh~=0.2.0", "numcodecs-wasm-zfp~=0.5.3", From 1ae1936857649b9d8e6d29c89f904cd1481c6682 Mon Sep 17 00:00:00 2001 From: Juniper Tyree Date: Fri, 29 Aug 2025 12:52:55 +0300 Subject: [PATCH 3/3] Enable debug logging for the RP codecs --- src/climatebenchpress/compressor/compressors/rp.py | 2 +- src/climatebenchpress/compressor/compressors/rp_dct.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/climatebenchpress/compressor/compressors/rp.py b/src/climatebenchpress/compressor/compressors/rp.py index e3a1456..dfa942b 100644 --- a/src/climatebenchpress/compressor/compressors/rp.py +++ b/src/climatebenchpress/compressor/compressors/rp.py @@ -16,6 +16,6 @@ def abs_bound_codec(error_bound, **kwargs): return CodecStack( numcodecs_wasm_swizzle_reshape.SwizzleReshape(axes=[[0, 1, 2], [3, 4]]), numcodecs_random_projection.RPCodec( - mae=error_bound, method="gaussian", seed=42 + mae=error_bound, method="gaussian", seed=42, debug=True ), ) diff --git a/src/climatebenchpress/compressor/compressors/rp_dct.py b/src/climatebenchpress/compressor/compressors/rp_dct.py index 0a3422b..9a8d771 100644 --- a/src/climatebenchpress/compressor/compressors/rp_dct.py +++ b/src/climatebenchpress/compressor/compressors/rp_dct.py @@ -15,5 +15,7 @@ class RPDct(Compressor): def abs_bound_codec(error_bound, **kwargs): return CodecStack( numcodecs_wasm_swizzle_reshape.SwizzleReshape(axes=[[0, 1, 2], [3, 4]]), - numcodecs_random_projection.RPCodec(mae=error_bound, method="dct", seed=0), + numcodecs_random_projection.RPCodec( + mae=error_bound, method="dct", seed=0, debug=True + ), )