Skip to content

refactor interpolation utilities#483

Merged
henry2004y merged 4 commits intomasterfrom
refactor-interpolation
Mar 4, 2026
Merged

refactor interpolation utilities#483
henry2004y merged 4 commits intomasterfrom
refactor-interpolation

Conversation

@henry2004y
Copy link
Owner

@henry2004y henry2004y commented Mar 4, 2026

This PR refactors interpolation.jl to create a cleaner and more logical structure.

What was Changed

  • Unified API (build_interpolator): I removed getinterp, get_interpolator, and getinterp_scalar and combined them into a single, unified build_interpolator function.

  • Multiple Dispatch Improvements: By checking the dimensions and typing (SVector vs non-vector arrays). build_interpolator automatically identifies whether the problem is 1D, 2D, or 3D, and vector or scalar. I properly typed grid arguments as AbstractVector to avoid method ambiguities, making dispatch much safer.

  • Types and Aliases: Reordered interpolation.jl so all type definitions (FieldInterpolator, SphericalFieldInterpolator, etc.) are grouped together. Added an alias const FieldInterpolator3D = FieldInterpolator.

  • Updated References: Replaced all references of removed interpolation functions with build_interpolator across the codebase, including tests, benchmarks, docs, and core simulator files (src/prepare.jl, src/fieldline.jl, src/gc.jl).

  • Renamed trace_fieldline: Since the function trace_fieldline constructs the ODE problem instead of actually solving it, I renamed it to TraceFieldlineProblem.

After cleaning up the interpolation code, we can further experiment about shifting to FastInterpolations.jl on top of #479

@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 significantly refactors the interpolation utilities to provide a cleaner, more logical, and unified API. By consolidating multiple interpolation functions into a single entry point with improved multiple dispatch, the codebase becomes easier to understand and maintain. This change streamlines how interpolators are created and used throughout the system, enhancing consistency and reducing cognitive load for developers.

Highlights

  • Unified API for Interpolation: The functions getinterp, get_interpolator, and getinterp_scalar have been consolidated into a single, unified build_interpolator function, simplifying the API for creating field interpolators.
  • Improved Multiple Dispatch: The new build_interpolator function leverages multiple dispatch to automatically identify 1D, 2D, or 3D problems, and vector or scalar fields, based on the dimensions and typing (SVector vs. non-vector arrays) of the input data. Grid arguments are now properly typed as AbstractVector to enhance dispatch safety.
  • Type and Alias Reorganization: All type definitions, such as FieldInterpolator and SphericalFieldInterpolator, within interpolation.jl have been grouped together for better readability and maintainability. An alias const FieldInterpolator3D = FieldInterpolator was also added.
  • Codebase-Wide Reference Updates: All instances of the removed interpolation functions (getinterp, get_interpolator, getinterp_scalar) have been updated to use the new build_interpolator function across the entire codebase, including benchmarks, documentation examples, tests, and core simulator files.

🧠 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
  • benchmark/benchmarks.jl
    • Updated interpolation function calls from getinterp to build_interpolator.
  • docs/examples/applications/demo_fermi_foreshock.jl
    • Updated interpolation function calls from getinterp to build_interpolator.
  • docs/examples/features/demo_coevolution.jl
    • Updated interpolation function calls from getinterp to build_interpolator.
  • docs/examples/features/demo_interpolation.md
    • Updated interpolation function calls from getinterp and getinterp_scalar to build_interpolator.
    • Removed references to TestParticle.getinterp and TestParticle.getinterp_scalar from the API documentation.
  • src/fieldline.jl
    • Updated interpolation function calls from getinterp to build_interpolator.
  • src/gc.jl
    • Updated interpolation function calls from getinterp to build_interpolator.
  • src/prepare.jl
    • Updated interpolation function calls from getinterp to build_interpolator.
  • src/utility/interpolation.jl
    • Replaced getinterp and getinterp_scalar functions with a single build_interpolator function.
    • Added const FieldInterpolator3D = FieldInterpolator alias.
    • Refactored build_interpolator to use multiple dispatch for different grid types and array dimensions.
    • Consolidated internal helper functions for interpolation object creation.
    • Removed redundant get_interpolator methods.
  • test/test_utility.jl
    • Updated interpolation function calls from getinterp and getinterp_scalar to build_interpolator.
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 does a great job of refactoring the interpolation utilities into a unified build_interpolator function, which significantly cleans up the API. The use of multiple dispatch is well-executed and makes the code more robust. However, I've found a critical issue in the implementation for RectilinearGrid when handling SVector data, which could lead to runtime errors. Please see the specific comment for details.

@codecov
Copy link

codecov bot commented Mar 4, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #483      +/-   ##
==========================================
+ Coverage   82.66%   83.50%   +0.84%     
==========================================
  Files          18       18              
  Lines        1932     1898      -34     
==========================================
- Hits         1597     1585      -12     
+ Misses        335      313      -22     

☔ 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 f6a5fd3 into master Mar 4, 2026
5 checks passed
@henry2004y henry2004y deleted the refactor-interpolation branch March 4, 2026 17:58
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

Benchmark Results (Julia v1)

Time benchmarks
master e272fbd... master / e272fbd...
interpolation/cartesian 0.12 ± 0.01 μs 0.11 ± 0.01 μs 1.09 ± 0.13
interpolation/spherical 0.411 ± 0.001 μs 0.411 ± 0.01 μs 1 ± 0.024
interpolation/time-dependent 4.48 ± 3.6 μs 4.53 ± 3.7 μs 0.989 ± 1.1
trace/GC/DiffEq Vern6 5.74 ± 1.7 μs 5.75 ± 1.9 μs 0.998 ± 0.44
trace/GC/Native RK4 0.137 ± 0.00011 s 0.137 ± 0.00018 s 1 ± 0.0015
trace/GC/Native RK45 3.34 ± 0.12 μs 3.36 ± 0.11 μs 0.994 ± 0.049
trace/Hybrid/Sheared 2.03 ± 0.071 μs 2.01 ± 0.07 μs 1.01 ± 0.05
trace/analytic field/in place 0.0586 ± 0.041 ms 0.0599 ± 0.041 ms 0.979 ± 0.96
trace/analytic field/in place relativistic 0.0794 ± 0.031 ms 0.0789 ± 0.031 ms 1.01 ± 0.55
trace/analytic field/out of place 0.0499 ± 0.04 ms 0.0523 ± 0.04 ms 0.953 ± 1.1
trace/normalized/out of place 16.6 ± 11 μs 16.2 ± 11 μs 1.02 ± 0.95
trace/numerical field/Adaptive Boris 4.26 ± 0.19 ms 4.22 ± 0.31 ms 1.01 ± 0.088
trace/numerical field/Boris 7.35 ± 0.06 μs 7.36 ± 0.061 μs 0.999 ± 0.012
trace/numerical field/Boris ensemble 14.6 ± 0.1 μs 14.7 ± 0.11 μs 0.997 ± 0.01
trace/numerical field/Boris kernel 9.53 ± 0.12 μs 9.49 ± 0.12 μs 1 ± 0.018
trace/numerical field/Boris with fields 7.98 ± 0.07 μs 8.01 ± 0.07 μs 0.996 ± 0.012
trace/numerical field/Multistep Boris 11 ± 0.08 μs 10.9 ± 0.071 μs 1 ± 0.0098
trace/numerical field/in place 25.3 ± 5.6 μs 25.5 ± 5.6 μs 0.995 ± 0.31
trace/numerical field/out of place 18.6 ± 5.5 μs 18.5 ± 5.5 μs 1.01 ± 0.42
trace/time-dependent field/in place 0.133 ± 0.0041 ms 0.135 ± 0.0046 ms 0.992 ± 0.046
trace/time-dependent field/out of place 0.111 ± 0.0078 ms 0.11 ± 0.0076 ms 1.01 ± 0.099
time_to_load 1.96 ± 0.0027 s 1.96 ± 0.036 s 1 ± 0.019
Memory benchmarks
master e272fbd... master / e272fbd...
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.145 k allocs: 11 kB 0.145 k allocs: 11 kB 1

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