fix: Interpolate grid for cfd_python in cross-validation#269
fix: Interpolate grid for cfd_python in cross-validation#269ryancinsight wants to merge 3 commits intomainfrom
Conversation
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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello, 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 Highlights
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough.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 Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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:
| 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 |
There was a problem hiding this comment.
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
⛔ Files ignored due to path filters (5)
validation/__pycache__/__init__.cpython-313.pycis excluded by!**/*.pycvalidation/__pycache__/fenics_reference.cpython-313.pycis excluded by!**/*.pycvalidation/__pycache__/reference_cavity_mac.cpython-313.pycis excluded by!**/*.pycvalidation/__pycache__/reference_cavity_psiomega.cpython-313.pycis excluded by!**/*.pycvalidation/__pycache__/validation_analytical.cpython-313.pycis excluded by!**/*.pyc
📒 Files selected for processing (2)
.gitignorevalidation/compare_cavity_external.py
…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>
Fix interpolation for mismatching cfd grids in
validation/compare_cavity_external.py. Also updates.gitignoreto 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_pythongrid doesn't match the external reference grid. It also cleans up the repository by removing tracked__pycache__files and updating.gitignoreto prevent Python compilation artifacts from being tracked in the future.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
.gitignorevalidation/compare_cavity_external.pyvalidation/__pycache__/__init__.cpython-313.pycvalidation/__pycache__/fenics_reference.cpython-313.pycvalidation/__pycache__/reference_cavity_mac.cpython-313.pycvalidation/__pycache__/reference_cavity_psiomega.cpython-313.pycvalidation/__pycache__/validation_analytical.cpython-313.pycSummary by CodeRabbit
Bug Fixes
Chores