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

Add interpolation routine to make Var.resampled_as faster #183

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ph-kev
Copy link
Member

@ph-kev ph-kev commented Dec 4, 2024

closes #182 - This commit adds an interpolation routine that makes resampled_as and any other functions that use interpolations faster.

Checklist

  • Add benchmarks on postprocessing pipeline for 4D OutputVars (see issue on ClimaCoupler)
  • Add results from current postprocessing pipeline to demonstrate results do not change
  • Add this to NEWS.md

Benchmarks from @time

# Latest commit on main (on first run)
490.620013 seconds (6.27 G allocations: 370.999 GiB, 5.72% gc time, 9.64% compilation time: 13% of which was recompilation)

# Latest commit on main (on second run)
449.763246 seconds (6.19 G allocations: 365.709 GiB, 6.46% gc time, 0.27% compilation time)

# This PR (on first run)
166.437237 seconds (849.41 M allocations: 151.120 GiB, 7.57% gc time, 28.15% compilation time: 14% of which was recompilation)

# This PR (on second run)
125.102550 seconds (769.52 M allocations: 145.852 GiB, 8.16% gc time, 0.96% compilation time)

The image below is from the current postprocessing pipeline using the latest commit on main.
bias_pr_all_seasons_orig_intp

The image below is from the current postprocessing pipeline using this PR.
bias_pr_all_seasons_new_intp

Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.31%. Comparing base (09e360d) to head (bd1319b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
+ Coverage   98.19%   98.31%   +0.11%     
==========================================
  Files          12       13       +1     
  Lines        1220     1302      +82     
==========================================
+ Hits         1198     1280      +82     
  Misses         22       22              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/Numerics.jl Outdated Show resolved Hide resolved
src/Numerics.jl Outdated Show resolved Hide resolved
Copy link
Member

@Sbozzolo Sbozzolo left a comment

Choose a reason for hiding this comment

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

Could you also move all the linear interpolation into its own module, so that it will be easier in the future to switch it to something else?

@ph-kev ph-kev force-pushed the kp/new-intp branch 2 times, most recently from 2037384 to 25c7808 Compare December 13, 2024 18:05
This commit adds an interpolation routine for use in ClimaAnalysis,
which seeks to replace Interpolations.jl in Var.jl. The interpolation
routine supports N-dimensional linear interpolation on a grid with
throw, flat, or periodic boundary conditions. Compared against
Interpolations.jl, the interpolation routine does not make a struct and
does not allocate anything on the heap when interpolating a point.
This commit removes Interpolations.jl from Var.jl. To do this, the
function `_make_interpolant` was removed. Three new functions are added
which are `_check_interpolant`, `interpolate_point`, and
`interpolate_points`, where the latter two functions replace the
functionality of `_make_interpolant`. Furthermore, the function
`_find_extp_bound_cond` was refactored to `_find_extp_bound_conds` which
find multiple extrapolation condtions using `_find_extp_bound_cond`
which is refactored to find the extrapolation condition for a single
point.

All functions that use an interpolant are updated to use the new
interpolation routine. The test for computing the bias in Atmos changes
to check approximately close to 0.0, due to floating point errors. The
tests that check for errors when interpolating out of bounds now check
for ErrorException instead of BoundsError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Var.resampled_as too much allocations
2 participants