Skip to content

Feature/derived fields api#17

Merged
shaia merged 6 commits intomasterfrom
feature/derived-fields-api
Jan 2, 2026
Merged

Feature/derived fields api#17
shaia merged 6 commits intomasterfrom
feature/derived-fields-api

Conversation

@shaia
Copy link
Copy Markdown
Owner

@shaia shaia commented Jan 1, 2026

No description provided.

shaia added 2 commits January 1, 2026 21:10
Add Python bindings for derived field computation and statistics:

- calculate_field_stats(data): Compute min, max, avg, sum for any field
- compute_velocity_magnitude(u, v, nx, ny): Compute sqrt(u^2 + v^2)
- compute_flow_statistics(u, v, p, nx, ny): Comprehensive stats for all
  flow field components including velocity magnitude

All functions include proper error handling for empty lists, wrong types,
and size mismatches. Comprehensive tests added in test_derived_fields.py.
Resolved merge conflicts to include both:
- Phase 3: Derived Fields & Statistics API
- Phase 5: Backend Availability API (v0.1.6)
@shaia shaia requested a review from Copilot January 1, 2026 19:21
@shaia shaia self-assigned this Jan 1, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements Phase 3 of the migration plan by adding a derived fields and statistics API to cfd_python. The new API provides three functions for computing field statistics and derived quantities from CFD simulation data.

  • Adds calculate_field_stats() for computing min/max/avg/sum statistics on arbitrary field data
  • Adds compute_velocity_magnitude() for calculating velocity magnitude from u/v components
  • Adds compute_flow_statistics() for comprehensive statistics on all flow field components

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
tests/test_derived_fields.py Comprehensive test suite for all three new functions with edge cases and error handling
src/cfd_python.c C implementation of Python bindings for the three derived fields functions
cfd_python/_loader.py Exports the new functions from the C extension module
cfd_python/__init__.py Updates module docstring and all to include new functions
MIGRATION_PLAN.md Marks Phase 3 as completed with actual effort tracking

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

shaia added 4 commits January 2, 2026 06:33
PyDict_SetItemString increments the reference count of the value, so
PyFloat_FromDouble results must be DECREFed after insertion. The
ADD_STATS macro now stores each PyFloat in a temp variable and properly
calls Py_DECREF after PyDict_SetItemString, following the established
pattern from ADD_TO_STATS at line 519-524.
Consistent with the import style used in test_boundary_conditions.py
and other test files in the codebase.
PyDict_SetItemString returns -1 on failure. Both calculate_field_stats_py
and the ADD_STATS macro now check these return values and properly clean
up resources before returning NULL on error.
Ruff's isort enforces alphabetical ordering, which made the section
comments inaccurate (e.g., clear_error was listed under "Derived fields"
instead of "Error handling"). Removed all section comments from the
import block since they don't provide value when imports are auto-sorted.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +551 to 554
| Phase 5: Backend Availability (v0.1.6) | ✅ 0.5 days | 4 days |
| Phase 6: CPU Features | 1 day | 5 days |
| Phase 7: Docs & Tests | 2 days | 7 days |

Copy link

Copilot AI Jan 2, 2026

Choose a reason for hiding this comment

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

The cumulative timeline is confusing because phases were completed out of order (Phase 5 before Phase 3 and 4). Consider either: (1) reordering the table to show completion order with actual cumulative times, or (2) adding a note that explains the cumulative column shows estimated sequential totals, not actual completion timeline. The "4 days" for Phase 5 cumulative appears to represent total completed work rather than sequential cumulative, which is inconsistent with other rows.

Suggested change
| Phase 5: Backend Availability (v0.1.6) | ✅ 0.5 days | 4 days |
| Phase 6: CPU Features | 1 day | 5 days |
| Phase 7: Docs & Tests | 2 days | 7 days |
| Phase 5: Backend Availability (v0.1.6) | ✅ 0.5 days | 4 days (completed work to date) |
| Phase 6: CPU Features | 1 day | 5 days |
| Phase 7: Docs & Tests | 2 days | 7 days |
_Note: The **Cumulative** column shows a sequential estimate assuming phases are done in numeric order. Phase 5 was completed earlier than Phases 3 and 4, so its "4 days (completed work to date)" value reflects total work finished so far rather than an additional sequential day._

Copilot uses AI. Check for mistakes.
@shaia shaia merged commit bf93317 into master Jan 2, 2026
21 checks passed
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.

2 participants