-
Notifications
You must be signed in to change notification settings - Fork 207
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
Bitrounding + Lossless compression #3599
base: main
Are you sure you want to change the base?
Changes from all commits
1f37d24
7416b7b
a2c8793
2d3e8b4
bbf80e1
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using BitInformation | ||
|
||
struct BitRounder{K} | ||
keepbits :: K | ||
end | ||
|
||
# number of keepbits (mantissa bits) for each variable | ||
default_bit_rounding(::Val{name}) where name = 23 # single precision default | ||
default_bit_rounding(::Val{:u}) = 2 | ||
default_bit_rounding(::Val{:v}) = 2 | ||
default_bit_rounding(::Val{:w}) = 2 | ||
default_bit_rounding(::Val{:T}) = 7 | ||
default_bit_rounding(::Val{:S}) = 16 # 12 at the surface, 16 deep ocean | ||
default_bit_rounding(::Val{:η}) = 6 | ||
|
||
function BitRounding(outputs = nothing; | ||
user_rounding...) | ||
Comment on lines
+16
to
+17
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. For the purpose of figuring out good defaults perhaps we should include 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. Then |
||
|
||
keepbits = Dict() | ||
|
||
# TODO: | ||
# Check that the dimensions of keepbits are | ||
# compatible with outputs if user_rounding | ||
# contains an abstract array (support functions?) | ||
|
||
for name in keys(outputs) | ||
if name ∈ keys(user_rounding) | ||
keepbits[name] = user_rounding[name] | ||
else | ||
keepbits[name] = default_bit_rounding(Val(name)) | ||
end | ||
end | ||
|
||
return BitRounding(keepbits) | ||
end | ||
|
||
# Getindex to allow indexing a BitRounder as | ||
Base.getindex(bit_rounding::BitRounding, name::Symbol) = BitRounding(bit_rounding[name]) | ||
|
||
function round_data!(output_array, bit_rounder::BitRounder) | ||
|
||
# The actual rounding... | ||
keepbits = bit_rounder.keepbits | ||
|
||
# TODO: make sure that the rounding happens | ||
# as we expect (priority to the vertical direction!) | ||
round!(output_array, keepbits) | ||
|
||
return output_array | ||
end | ||
|
||
|
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.
This is interesting. Why is there a difference between T, S? Is this specific to the simulation that this was tested on, or can we be sure this is valid for all simulations, past climates, future climates, idealized simulations at other resolutions, etc?
It seems we need to have default bit rounding for passive tracers.
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.
Although relatively robust through time and space, this depends on a lot of things, also whether your unit carries some offset around (e.g. Kelvin vs ˚C, density vs density anomaly). So it's tricky to generalise. I suggest to have some reasonable defaults if someone uses bit rounding (default
nothing
or single precision as you like) but suggest to highlight that this should be checked similar to how I did it here with the bitinformation analysis above.For global ocean simulations I expect these to be reasonable defaults. I believe for now this is mostly to reduce the filesizes for OMIP simulations
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.
True, I'm just not sure that OMIP is going to be the most common use case, so there's a question about what default is appropriate here
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.
The OMIP defaults might belong in the
ClimaOcean
setup, perhapsThere 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.
We could set the defaults here as 23 mantissa bits (=Float32 precision, whether you use Float32 or 64) and then lower in ClimaOcean?