Skip to content

Fast interpolations#479

Open
henry2004y wants to merge 25 commits intomasterfrom
fast-interpolations
Open

Fast interpolations#479
henry2004y wants to merge 25 commits intomasterfrom
fast-interpolations

Conversation

@henry2004y
Copy link
Owner

@henry2004y henry2004y commented Mar 1, 2026

Check the efficiency of replacing Interpolations.jl with FastInterpolations.jl. Address #241


With FastInterpolations.jl 0.3, there are some type constraints that prohibit interpolating for SVectors. If that is addressed, I expect the performance would be much better.


With FastInterpolations.jl 0.4, SVectors are supported. The only thing left is a lack of NaN boundary treatment (or, as quoted from the original author, the constant extrapolation method). As a temporary workaround, we use flat boundary for now.

@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 transitions the project's interpolation backend from Interpolations.jl to FastInterpolations.jl. This change is motivated by the potential for improved performance and efficiency in field interpolations. The core interpolation logic has been rewritten to integrate with the new library, supporting different grid structures and interpolation orders. Additionally, documentation for AI agents has been updated to reflect best practices for package management and testing within the repository.

Highlights

  • Dependency Update: Replaced the Interpolations.jl package with FastInterpolations.jl to enhance performance and efficiency of field interpolations.
  • Interpolation Logic Refactor: Introduced a new utility module, fastinterpolation.jl, which implements various field interpolators (1D, 2D, 3D, spherical) using the FastInterpolations.jl library, including support for different grid types and interpolation orders.
  • Documentation for AI Agents: Updated the AGENTS.md file to provide clearer instructions for AI agents on how to run tests and manage package dependencies, specifically regarding modifications to Project.toml.
  • Test Suite Adjustments: Modified existing tests to use approximate equality () for floating-point comparisons, accounting for potential minor numerical differences introduced by the new interpolation library.

🧠 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
  • AGENTS.md
    • Updated instructions for running the test suite.
    • Clarified guidelines for AI agents on modifying Project.toml for compat entries and using Pkg.add/Pkg.rm for package management.
  • Project.toml
    • Removed Interpolations from dependencies.
    • Added FastInterpolations as a new dependency with version 0.3.0.
  • src/TestParticle.jl
    • Removed Interpolations module imports.
    • Changed the included utility file from utility/interpolation.jl to utility/fastinterpolation.jl.
  • src/utility/fastinterpolation.jl
    • Added a new file implementing field interpolations using FastInterpolations.jl.
    • Defined AbstractFieldInterpolator and concrete types like FieldInterpolator, FieldInterpolator2D, FieldInterpolator1D, and SphericalFieldInterpolator.
    • Implemented _fastinterp for various interpolation orders (linear, quadratic, cubic, constant) and extrapolation modes.
    • Included logic for handling SVector types and ensuring full phi range for spherical grids.
    • Introduced LazyTimeInterpolator for time-dependent field interpolation with buffering.
  • test/runtests.jl
    • Modified a test assertion for spherical field interpolation to use approximate equality () instead of exact equality (==).
  • test/test_utility.jl
    • Updated multiple test assertions for scalar field interpolation to use approximate equality ().
    • Adjusted expected values in some scalar interpolation tests to match the behavior of FastInterpolations.jl.
Activity
  • No specific activity has been recorded for this pull request yet.
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 replaces Interpolations.jl with FastInterpolations.jl to improve performance. The changes include updating dependencies, replacing the interpolation logic in a new src/utility/fastinterpolation.jl file, and adjusting tests.

My review found a few critical issues in the new interpolation file related to out-of-bounds handling, which will likely cause errors at runtime. I've provided suggestions to fix these. I've also included a suggestion to improve the clarity of the testing instructions in AGENTS.md. Overall, the switch to FastInterpolations.jl is a good direction, but the implementation needs some fixes.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

Benchmark Results (Julia v1)

Time benchmarks
master b60523f... master / b60523f...
interpolation/cartesian 0.12 ± 0.011 μs 0.111 ± 0.01 μs 1.08 ± 0.14
interpolation/spherical 0.411 ± 0.01 μs 0.341 ± 0.001 μs 1.21 ± 0.03
interpolation/time-dependent 4.06 ± 3.9 μs 3.56 ± 3.8 μs 1.14 ± 1.6
trace/GC/DiffEq Vern6 5.94 ± 1.8 μs 5.6 ± 1.8 μs 1.06 ± 0.46
trace/GC/Native RK4 0.136 ± 0.00019 s 0.137 ± 7.6e-05 s 0.994 ± 0.0015
trace/GC/Native RK45 3.46 ± 0.11 μs 3.37 ± 0.12 μs 1.03 ± 0.049
trace/Hybrid/Sheared 2.02 ± 0.07 μs 2.02 ± 0.08 μs 1 ± 0.053
trace/analytic field/in place 0.0571 ± 0.04 ms 0.0576 ± 0.04 ms 0.993 ± 0.98
trace/analytic field/in place relativistic 0.0799 ± 0.034 ms 0.0801 ± 0.034 ms 0.997 ± 0.61
trace/analytic field/out of place 0.0496 ± 0.039 ms 0.0485 ± 0.039 ms 1.02 ± 1.2
trace/normalized/out of place 16.1 ± 9.8 μs 16.2 ± 10 μs 0.994 ± 0.86
trace/numerical field/Adaptive Boris 4.18 ± 0.36 ms 4.19 ± 0.096 ms 0.997 ± 0.088
trace/numerical field/Boris 7.35 ± 0.07 μs 7.54 ± 0.07 μs 0.975 ± 0.013
trace/numerical field/Boris ensemble 14.7 ± 0.11 μs 15 ± 0.12 μs 0.974 ± 0.011
trace/numerical field/Boris kernel 9.55 ± 0.12 μs 9.93 ± 0.11 μs 0.962 ± 0.016
trace/numerical field/Boris with fields 7.98 ± 0.07 μs 8.15 ± 0.069 μs 0.979 ± 0.012
trace/numerical field/Multistep Boris 11 ± 0.08 μs 11.1 ± 0.07 μs 0.992 ± 0.0096
trace/numerical field/in place 25.3 ± 5.6 μs 27.3 ± 5.4 μs 0.925 ± 0.27
trace/numerical field/out of place 18.3 ± 5.4 μs 19.1 ± 5.5 μs 0.96 ± 0.4
trace/time-dependent field/in place 0.136 ± 0.0044 ms 0.136 ± 0.0038 ms 1.01 ± 0.043
trace/time-dependent field/out of place 0.11 ± 0.0037 ms 0.108 ± 0.0038 ms 1.02 ± 0.05
time_to_load 1.88 ± 0.017 s 1.86 ± 0.014 s 1.01 ± 0.012
Memory benchmarks
master b60523f... master / b60523f...
interpolation/cartesian 2 allocs: 0.234 kB 2 allocs: 0.234 kB 1
interpolation/spherical 2 allocs: 0.203 kB 2 allocs: 0.25 kB 0.812
interpolation/time-dependent 0.044 k allocs: 9.62 kB 24 allocs: 8.94 kB 1.08
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

@codecov
Copy link

codecov bot commented Mar 2, 2026

Codecov Report

❌ Patch coverage is 74.66667% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.62%. Comparing base (f6a5fd3) to head (b60523f).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/utility/fastinterpolation.jl 85.49% 19 Missing ⚠️
src/utility/interpolation.jl 0.00% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #479      +/-   ##
==========================================
- Coverage   83.50%   77.62%   -5.89%     
==========================================
  Files          18       19       +1     
  Lines        1898     2007     +109     
==========================================
- Hits         1585     1558      -27     
- Misses        313      449     +136     

☔ 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 force-pushed the fast-interpolations branch from 3256c6e to c01cc53 Compare March 4, 2026 18:01
@henry2004y
Copy link
Owner Author

/gemini review

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 replaces Interpolations.jl with FastInterpolations.jl to improve performance by updating dependencies, replacing the interpolation logic with a new fastinterpolation.jl file, and adjusting tests. No security vulnerabilities were identified. However, there are a few areas for improvement: the old interpolation.jl file appears unused and should be removed, the interpolation function has a silent fallback for unsupported orders that could be made safer by throwing an error, and a memory allocation always occurs in one case, contradicting the docstring about in-place modification. Addressing these points will improve code clarity and robustness.

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