Skip to content

fix: Interpolate grid for cfd_python in cross-validation#269

Open
ryancinsight wants to merge 3 commits intomainfrom
fix/python-bindings-for-TODOs-2701939570082706582
Open

fix: Interpolate grid for cfd_python in cross-validation#269
ryancinsight wants to merge 3 commits intomainfrom
fix/python-bindings-for-TODOs-2701939570082706582

Conversation

@ryancinsight
Copy link
Owner

@ryancinsight ryancinsight commented Mar 17, 2026

Fix interpolation for mismatching cfd grids in validation/compare_cavity_external.py. Also updates .gitignore to prevent tracking __pycache__.


PR created automatically by Jules for task 2701939570082706582 started by @ryancinsight

High-level PR Summary

This PR fixes grid interpolation issues in CFD validation by implementing bivariate spline interpolation when the cfd_python grid doesn't match the external reference grid. It also cleans up the repository by removing tracked __pycache__ files and updating .gitignore to prevent Python compilation artifacts from being tracked in the future.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 .gitignore
2 validation/compare_cavity_external.py
3 validation/__pycache__/__init__.cpython-313.pyc
4 validation/__pycache__/fenics_reference.cpython-313.pyc
5 validation/__pycache__/reference_cavity_mac.cpython-313.pyc
6 validation/__pycache__/reference_cavity_psiomega.cpython-313.pyc
7 validation/__pycache__/validation_analytical.cpython-313.pyc

Need help? Join our Discord

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation comparison to handle grid-size mismatches by interpolating CFD results onto external reference grids, enabling reliable comparisons and plotting across differing meshes.
  • Chores

    • Updated version control to ignore Python virtual environments and compiled bytecode artifacts.
    • Standardized performance benchmarking workflow targets and installation steps for consistent build and run behavior.

This patch addresses the TODO tag in `validation/compare_cavity_external.py` where a `cfd_python` result and an `external_result` may have mismatched grid shapes. When that occurs, we now transpose the output fields and use `scipy.interpolate.RectBivariateSpline` to interpolate them onto the external reference grid.
Also fixes `__pycache__` tracking in git by adding it to `.gitignore` and untracking existing files.

Co-authored-by: ryancinsight <55164720+ryancinsight@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Contributor

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 addresses a critical issue in the cross-validation process where cfd_python results could not be accurately compared against external solutions due to differing grid sizes. By introducing robust interpolation, the system can now seamlessly align data for comparison. Additionally, the update enhances repository hygiene by preventing the accidental tracking of build artifacts and virtual environment files.

Highlights

  • Grid Interpolation Fix: Implemented a solution to interpolate cfd_python results when grid sizes mismatch with external solutions during cross-validation, ensuring comparisons can proceed.
  • Gitignore Update: Expanded the .gitignore file to include common Python compilation artifacts and virtual environment directories, improving repository cleanliness.
Changelog
  • .gitignore
    • Added entries to ignore Python compilation artifacts such as __pycache__, *.pyc, *.pyo, *.pyd.
    • Included .venv/ to prevent tracking virtual environment directories.
  • validation/compare_cavity_external.py
    • Replaced a TODO comment and return None with an implementation of scipy.interpolate.RectBivariateSpline.
    • Enabled interpolation of cfd_python_result's u, v, and p fields to match the grid dimensions of the external_result when a size mismatch is detected.
Activity
  • PR created automatically by Jules for task 2701939570082706582 started by @ryancinsight.
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.

@coderabbitai
Copy link

coderabbitai bot commented Mar 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8850c32b-d561-4190-be30-3147a217589a

📥 Commits

Reviewing files that changed from the base of the PR and between 52955b2 and ecad284.

📒 Files selected for processing (1)
  • .github/workflows/performance-benchmarking.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/performance-benchmarking.yml

📝 Walkthrough

Walkthrough

.gitignore gains Python virtualenv and bytecode ignores. Validation now interpolates CFD fields and centerlines onto an external grid using RectBivariateSpline when grids mismatch instead of returning early. CI workflow benchmark target renamed from comprehensive_cfd_benchmarks to performance_benchmarks.

Changes

Cohort / File(s) Summary
Repo ignore patterns
\.gitignore
Add .venv/, __pycache__/, *.pyc, *.pyo, *.pyd to ignore Python venv and bytecode artifacts.
CFD validation & interpolation
validation/compare_cavity_external.py
On grid-size mismatch, interpolate CFD fields (u, v, p) and centerlines onto the external grid using RectBivariateSpline (local import), transposing arrays for interpolation and updating plotting coordinates; replaces prior early-return behavior.
CI benchmark workflow
.github/workflows/performance-benchmarking.yml
Rename build/run benchmark target from comprehensive_cfd_benchmarks to performance_benchmarks and adjust install packages to include libfontconfig1-dev.

Sequence Diagram(s)

sequenceDiagram
    participant Validator as "Validation Script"
    participant CFD as "CFD Results (u,v,p)"
    participant External as "External Grid/Ref"
    participant Interp as "RectBivariateSpline\n(Interpolator)"
    participant Plot as "Plot / Output"

    rect rgba(200,230,255,0.5)
    Validator->>CFD: load CFD arrays & centerlines
    Validator->>External: load external grid & centerlines
    end

    rect rgba(220,255,200,0.5)
    Validator->>Interp: create interpolator(s) for CFD fields
    Interp-->>Validator: interpolated fields on external grid
    Validator->>Interp: 1D interp centerlines
    Interp-->>Validator: interpolated centerlines
    end

    rect rgba(255,230,200,0.5)
    Validator->>CFD: assign interpolated arrays back into result
    Validator->>Plot: update x/y coords and generate comparison plots
    Plot-->>Validator: plots/metrics produced
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped through files at break of day,

Hid .venv where crumbs won't stay.
I stitched the grids with spline and thread,
Aligned the flows where numbers spread.
Benchmarks renamed — I twitched my nose and leapt away. 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: implementing grid interpolation for cfd_python results in cross-validation, which is the primary focus of changes in validation/compare_cavity_external.py.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/python-bindings-for-TODOs-2701939570082706582
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

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

Review by RecurseML

🔍 Review performed on a879535..b57c012

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (2)

.gitignore
validation/compare_cavity_external.py

Copy link
Contributor

@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 addresses a grid mismatch issue in cross-validation by implementing interpolation and updates the .gitignore file to exclude Python artifacts. My review focuses on the new interpolation logic in validation/compare_cavity_external.py. I've provided a suggestion to improve robustness by handling a potential ImportError for the optional scipy dependency and to refactor the code for better maintainability by removing duplication.

Comment on lines +108 to +123
from scipy.interpolate import RectBivariateSpline

# cfd_python arrays are (ny, nx), RectBivariateSpline expects (x, y)
# So we transpose the CFD result fields (.T) for interpolation
interp_u = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["u"].T)
interp_v = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["v"].T)
interp_p = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["p"].T)

# Evaluate on the external grid. Note that ext_solver.x and ext_solver.y are 1D arrays
new_u = interp_u(ext_solver.x, ext_solver.y).T
new_v = interp_v(ext_solver.x, ext_solver.y).T
new_p = interp_p(ext_solver.x, ext_solver.y).T

cfd_python_result["u"] = new_u
cfd_python_result["v"] = new_v
cfd_python_result["p"] = new_p
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The local import of scipy could lead to an unhandled ImportError if the optional dependency is not installed, causing the script to crash. It's better to wrap this in a try...except block for graceful error handling.

Additionally, the interpolation logic is duplicated for the u, v, and p fields. This can be refactored into a loop to make the code more concise and easier to maintain.

Here is a suggestion that addresses both points:

Suggested change
from scipy.interpolate import RectBivariateSpline
# cfd_python arrays are (ny, nx), RectBivariateSpline expects (x, y)
# So we transpose the CFD result fields (.T) for interpolation
interp_u = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["u"].T)
interp_v = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["v"].T)
interp_p = RectBivariateSpline(cfd_python_result["x"], cfd_python_result["y"], cfd_python_result["p"].T)
# Evaluate on the external grid. Note that ext_solver.x and ext_solver.y are 1D arrays
new_u = interp_u(ext_solver.x, ext_solver.y).T
new_v = interp_v(ext_solver.x, ext_solver.y).T
new_p = interp_p(ext_solver.x, ext_solver.y).T
cfd_python_result["u"] = new_u
cfd_python_result["v"] = new_v
cfd_python_result["p"] = new_p
try:
from scipy.interpolate import RectBivariateSpline
except ImportError:
print("WARN: scipy is not installed, cannot interpolate grids. Skipping comparison.")
return None
x_src, y_src = cfd_python_result["x"], cfd_python_result["y"]
x_dst, y_dst = ext_solver.x, ext_solver.y
for field in ["u", "v", "p"]:
# cfd_python arrays are (ny, nx), but RectBivariateSpline expects z of shape (nx, ny),
# so we transpose the field. The result is (nx_dst, ny_dst), so we transpose back.
interpolator = RectBivariateSpline(x_src, y_src, cfd_python_result[field].T)
cfd_python_result[field] = interpolator(x_dst, y_dst).T

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@validation/compare_cavity_external.py`:
- Around line 121-123: After replacing the interpolated fields in
cfd_python_result with new_u/new_v/new_p, also recompute all derived arrays that
depend on the grid so they reference the interpolated grid/data instead of the
old values; specifically update x and y and any derived quantities like
u_centerline and v_centerline (and any other cached arrays that use
cfd_python_result["x"]/["y"]/["u"]/["v"]) so downstream code (vortex location,
plotting) uses the new interpolated fields.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d819842c-1e16-446c-9bc1-0b1d0948af26

📥 Commits

Reviewing files that changed from the base of the PR and between a879535 and b57c012.

⛔ Files ignored due to path filters (5)
  • validation/__pycache__/__init__.cpython-313.pyc is excluded by !**/*.pyc
  • validation/__pycache__/fenics_reference.cpython-313.pyc is excluded by !**/*.pyc
  • validation/__pycache__/reference_cavity_mac.cpython-313.pyc is excluded by !**/*.pyc
  • validation/__pycache__/reference_cavity_psiomega.cpython-313.pyc is excluded by !**/*.pyc
  • validation/__pycache__/validation_analytical.cpython-313.pyc is excluded by !**/*.pyc
📒 Files selected for processing (2)
  • .gitignore
  • validation/compare_cavity_external.py

google-labs-jules bot and others added 2 commits March 17, 2026 01:47
…ub actions

This patch addresses the TODO tag in `validation/compare_cavity_external.py` where a `cfd_python` result and an `external_result` may have mismatched grid shapes. When that occurs, we now transpose the output fields and use `scipy.interpolate.RectBivariateSpline` to interpolate them onto the external reference grid. We also interpolate the centerlines.

Also fixes `__pycache__` tracking in git by adding it to `.gitignore` and untracking existing files.

Finally, we update the `performance-benchmarking.yml` file to use `performance_benchmarks` instead of `comprehensive_cfd_benchmarks` as dictated by the memory.

Co-authored-by: ryancinsight <55164720+ryancinsight@users.noreply.github.com>
This ensures that the `yeslogic-fontconfig-sys` cargo crate successfully builds on the linux runner.

Co-authored-by: ryancinsight <55164720+ryancinsight@users.noreply.github.com>
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