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

Lazy rectilinear interpolator #6084

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

Conversation

fnattino
Copy link
Contributor

🚀 Pull Request

Description

Different take to enable the rectilinear interpolator to run lazily #6002 .

Trying to address the same issue as #6006, but there I have made the underlying _RegularGridInterpolator from _scipy_interpolate to run on lazy data, which required switching from scipy.sparse to sparse (not ideal since it would add numba as a dependency).

Here I have tried instead to implement a similar approach as used for regridding, which works on lazy data as well. The downside is that the chunks in the dimensions we are interpolating over need to be merged, but at least we could run interpolation in parallel over the chunks in the other dimensions (and we do not need to add extra dependencies to iris).

@fnattino fnattino marked this pull request as ready for review July 25, 2024 09:44
@bouweandela
Copy link
Member

Nice to see this progressing @fnattino! Did you notice that CI is failing on this pull request?

Copy link

codecov bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.83%. Comparing base (d76a4d8) to head (3481e46).
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6084   +/-   ##
=======================================
  Coverage   89.82%   89.83%           
=======================================
  Files          88       88           
  Lines       23150    23180   +30     
  Branches     5043     5043           
=======================================
+ Hits        20794    20823   +29     
+ Misses       1624     1622    -2     
- Partials      732      735    +3     

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

@trexfeathers trexfeathers self-assigned this Sep 4, 2024
@trexfeathers
Copy link
Contributor

@fnattino just want to reassure you that I have been looking at this, but since I have never worked with our interpolators before it is slow progress. Having another go this afternoon with help from some coffee ☕

@fnattino
Copy link
Contributor Author

No worries @trexfeathers, but thanks for the heads-up! :)

Copy link
Contributor

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

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

Hi @fnattino, thank you for your hard work on this.

Here is a partial review. I have left myself a couple of TODO comments. But the suggestions I have already might take some time, and may change the code significantly - mainly #6084 (comment) - so it seemed important to get these suggestions to you as soon as possible.

Also thank you to @HarriKeenan for helping me with this review last week 🤜🤛

lib/iris/analysis/_interpolation.py Outdated Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
Comment on lines +168 to +174
def _interpolated_dtype(dtype, method):
"""Determine the minimum base dtype required by the underlying interpolator."""
if method == "nearest":
result = dtype
else:
result = np.result_type(_DEFAULT_DTYPE, dtype)
return result
Copy link
Contributor

@trexfeathers trexfeathers Sep 5, 2024

Choose a reason for hiding this comment

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

If this needs to stay (see my other comment about args=[self] - #6084 (comment)), then I'd be interested in us unifying this function with RectilinearInterpolator._interpolated_dtype().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to put this back as a (static)method of the RectilinearInterpolator? Or to merge the body of this function with RectilinearInterpolator._interpolate?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean find any appropriate way for there to be only 1 _interpolated_dtype() in this file, which can be used by both:

  • RectilinearInterpolator._interpolate()
  • RectilinearInterpolator._points()

Up to you how this is achieved.

lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
Copy link
Contributor Author

@fnattino fnattino left a comment

Choose a reason for hiding this comment

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

@trexfeathers thanks a lot for the review and apologies for the scattered response.

As I have tried to explain in reply to your comments, I am a bit hesitant to implement the solution that would copy the current instance of the RectilinearInterpolation - but I am very curious to hear your thoughts on this!

lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
Comment on lines +168 to +174
def _interpolated_dtype(dtype, method):
"""Determine the minimum base dtype required by the underlying interpolator."""
if method == "nearest":
result = dtype
else:
result = np.result_type(_DEFAULT_DTYPE, dtype)
return result
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean to put this back as a (static)method of the RectilinearInterpolator? Or to merge the body of this function with RectilinearInterpolator._interpolate?

Copy link
Contributor

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

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

OK I got my head back in the space and I understand your logic better now. Nearly there.

If you're busy with other things please let me know and I can try actioning the remaining stuff myself.

lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
Comment on lines +168 to +174
def _interpolated_dtype(dtype, method):
"""Determine the minimum base dtype required by the underlying interpolator."""
if method == "nearest":
result = dtype
else:
result = np.result_type(_DEFAULT_DTYPE, dtype)
return result
Copy link
Contributor

Choose a reason for hiding this comment

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

I mean find any appropriate way for there to be only 1 _interpolated_dtype() in this file, which can be used by both:

  • RectilinearInterpolator._interpolate()
  • RectilinearInterpolator._points()

Up to you how this is achieved.

lib/iris/analysis/_interpolation.py Show resolved Hide resolved
lib/iris/analysis/_interpolation.py Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried writing a benchmark to demonstrate the benefits of this but everything either stayed the same or got slower.

Could you share with me the results you have seen? Especially if it's something I/we could turn into a benchmark. Thanks

Copy link
Contributor

@trexfeathers trexfeathers left a comment

Choose a reason for hiding this comment

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

Clicked the wrong button with my previous review!

@fnattino
Copy link
Contributor Author

Thanks a lot for the effort of getting back to this @trexfeathers ! I should have time to get back to this next week, but I will keep you posted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants