Skip to content

refactor: improve spherical interpolation#485

Merged
henry2004y merged 3 commits intomasterfrom
optimize-interpolation
Mar 5, 2026
Merged

refactor: improve spherical interpolation#485
henry2004y merged 3 commits intomasterfrom
optimize-interpolation

Conversation

@henry2004y
Copy link
Owner

@henry2004y henry2004y commented Mar 5, 2026

  • Remove _ensure_full_phi by using built-in periodic extrapolation support from Interpolations.jl
  • Support high-order spherical interpolations

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the spherical interpolation logic by removing a custom function that handled periodic boundary conditions for the phi coordinate. Instead, it now utilizes the native periodic extrapolation features provided by the Interpolations.jl library, leading to cleaner and potentially more robust code. Additionally, minor formatting and performance improvements were applied to other interpolation-related functions.

Highlights

  • Spherical Interpolation Refinement: The custom _ensure_full_phi function has been removed, leveraging the built-in periodic extrapolation support from the Interpolations.jl package for handling the phi dimension in spherical coordinates.
  • Code Simplification: The build_interpolator function for spherical grids now directly uses Periodic(OnGrid()) or Periodic(OnCell()) boundary conditions, simplifying the logic for handling periodic phi ranges.
  • Performance Improvement: The @inbounds macro was added to the FieldInterpolator1D call operator for potential performance gains by skipping bounds checks.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/utility/interpolation.jl
    • Removed the _ensure_full_phi function, which previously handled periodic extrapolation for the phi dimension.
    • Modified the build_interpolator function for spherical grids to use Periodic(OnGrid()) or Periodic(OnCell()) boundary conditions for the phi coordinate, depending on the grid's extent.
    • Added the @inbounds macro to the FieldInterpolator1D call operator for improved performance.
    • Relocated the build_interpolator definition for CartesianGrid to a more appropriate position after SphericalFieldInterpolator.
    • Adjusted the formatting of several build_interpolator function signatures for better readability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the spherical interpolation logic to use the built-in periodic extrapolation support from Interpolations.jl, which is a great improvement that simplifies the code by removing the manual _ensure_full_phi function. However, this change has also unintentionally removed support for higher-order interpolation on uniform spherical grids, as the new implementation always uses linear interpolation. My review includes a suggestion to restore this functionality while retaining the benefits of the refactoring for non-uniform grids. Other changes are minor improvements like code formatting and adding @inbounds for performance.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Benchmark Results (Julia v1)

Time benchmarks
master b3752b8... master / b3752b8...
interpolation/cartesian 0.13 ± 0.011 μs 0.12 ± 0.001 μs 1.08 ± 0.092
interpolation/spherical 0.411 ± 0.001 μs 0.411 ± 0.001 μs 1 ± 0.0034
interpolation/time-dependent 4.1 ± 3.9 μs 4.41 ± 3.7 μs 0.93 ± 1.2
trace/GC/DiffEq Vern6 5.62 ± 1.8 μs 5.58 ± 1.9 μs 1.01 ± 0.46
trace/GC/Native RK4 0.137 ± 0.00016 s 0.137 ± 0.00017 s 0.999 ± 0.0017
trace/GC/Native RK45 3.52 ± 0.13 μs 3.37 ± 0.14 μs 1.04 ± 0.058
trace/Hybrid/Sheared 2.24 ± 0.08 μs 2.02 ± 0.09 μs 1.11 ± 0.063
trace/analytic field/in place 0.0597 ± 0.04 ms 0.0564 ± 0.04 ms 1.06 ± 1
trace/analytic field/in place relativistic 0.0792 ± 0.031 ms 0.0794 ± 0.036 ms 0.997 ± 0.6
trace/analytic field/out of place 0.0585 ± 0.038 ms 0.0484 ± 0.04 ms 1.21 ± 1.3
trace/normalized/out of place 18.5 ± 11 μs 15.9 ± 9.9 μs 1.16 ± 0.98
trace/numerical field/Adaptive Boris 4.2 ± 0.13 ms 4.19 ± 0.1 ms 1 ± 0.04
trace/numerical field/Boris 7.39 ± 0.07 μs 7.36 ± 0.07 μs 1 ± 0.013
trace/numerical field/Boris ensemble 14.7 ± 0.11 μs 14.7 ± 0.13 μs 1 ± 0.012
trace/numerical field/Boris kernel 9.64 ± 0.13 μs 9.56 ± 0.12 μs 1.01 ± 0.019
trace/numerical field/Boris with fields 8.02 ± 0.08 μs 8.04 ± 0.08 μs 0.996 ± 0.014
trace/numerical field/Multistep Boris 11 ± 0.081 μs 10.9 ± 0.09 μs 1 ± 0.011
trace/numerical field/in place 25.3 ± 5.7 μs 25 ± 5.7 μs 1.01 ± 0.32
trace/numerical field/out of place 18.5 ± 5.5 μs 18.1 ± 5.6 μs 1.02 ± 0.44
trace/time-dependent field/in place 0.136 ± 0.0034 ms 0.133 ± 0.004 ms 1.02 ± 0.04
trace/time-dependent field/out of place 0.123 ± 0.0061 ms 0.108 ± 0.0033 ms 1.14 ± 0.067
time_to_load 1.86 ± 0.0073 s 1.86 ± 0.0032 s 0.996 ± 0.0043
Memory benchmarks
master b3752b8... master / b3752b8...
interpolation/cartesian 2 allocs: 0.234 kB 2 allocs: 0.234 kB 1
interpolation/spherical 2 allocs: 0.203 kB 2 allocs: 0.203 kB 1
interpolation/time-dependent 0.044 k allocs: 9.62 kB 0.044 k allocs: 9.62 kB 1
trace/GC/DiffEq Vern6 0.174 k allocs: 12.2 kB 0.174 k allocs: 12.2 kB 1
trace/GC/Native RK4 13 allocs: 0.382 MB 13 allocs: 0.382 MB 1
trace/GC/Native RK45 16 allocs: 2.44 kB 16 allocs: 2.44 kB 1
trace/Hybrid/Sheared 8 allocs: 2.98 kB 8 allocs: 2.98 kB 1
trace/analytic field/in place 2.07 k allocs: 0.091 MB 2.07 k allocs: 0.091 MB 1
trace/analytic field/in place relativistic 2.07 k allocs: 0.091 MB 2.07 k allocs: 0.091 MB 1
trace/analytic field/out of place 2.04 k allocs: 0.0894 MB 2.04 k allocs: 0.0894 MB 1
trace/normalized/out of place 0.756 k allocs: 0.0332 MB 0.756 k allocs: 0.0332 MB 1
trace/numerical field/Adaptive Boris 27 allocs: 1.5 MB 27 allocs: 1.5 MB 1
trace/numerical field/Boris 6 allocs: 1.16 kB 6 allocs: 1.16 kB 1
trace/numerical field/Boris ensemble 10 allocs: 2.28 kB 10 allocs: 2.28 kB 1
trace/numerical field/Boris kernel 0.038 k allocs: 2.12 kB 0.038 k allocs: 2.12 kB 1
trace/numerical field/Boris with fields 6 allocs: 1.52 kB 6 allocs: 1.52 kB 1
trace/numerical field/Multistep Boris 6 allocs: 1.16 kB 6 allocs: 1.16 kB 1
trace/numerical field/in place 0.411 k allocs: 20.4 kB 0.411 k allocs: 20.4 kB 1
trace/numerical field/out of place 0.378 k allocs: 18.4 kB 0.378 k allocs: 18.4 kB 1
trace/time-dependent field/in place 3.95 k allocs: 0.181 MB 3.95 k allocs: 0.181 MB 1
trace/time-dependent field/out of place 3.92 k allocs: 0.179 MB 3.92 k allocs: 0.179 MB 1
time_to_load 0.149 k allocs: 11.1 kB 0.145 k allocs: 11 kB 1.02

@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.30%. Comparing base (c3283cd) to head (b3752b8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #485      +/-   ##
==========================================
+ Coverage   83.50%   84.30%   +0.79%     
==========================================
  Files          18       18              
  Lines        1898     1880      -18     
==========================================
  Hits         1585     1585              
+ Misses        313      295      -18     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@henry2004y henry2004y merged commit 980414b into master Mar 5, 2026
9 checks passed
@henry2004y henry2004y deleted the optimize-interpolation branch March 5, 2026 05:03
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.

1 participant