Skip to content

[RL] FON: add optional C++ backend#400

Merged
Lgz-tud merged 3 commits into
masterfrom
feature/fon-cpp-backend
Jun 6, 2026
Merged

[RL] FON: add optional C++ backend#400
Lgz-tud merged 3 commits into
masterfrom
feature/fon-cpp-backend

Conversation

@Lgz-tud

@Lgz-tud Lgz-tud commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds an optional C++ backend for the FON (Field of Neighborhood) below-ground resource module, following the same pattern as the AsymmetricZOI (PR #388) and SymmetricZOI (PR #390) C++ backends.

C++ Backend

  • FON.cpp: pybind11 kernel with OpenMP parallelization for FON belowground competition
  • Backend selection via <backend_type>cpp</backend_type> XML tag (auto-selects C++ when available, falls back to Python)
  • Validated against Python backend with 100-year simulations (5 random seeds × 2 backends): tree counts, basal area, bg_factor, and plant positions are identical

Benchmark

Use Benchmarks/TestOutputs/ consistent with SymmetricZOI.xml and AsymmetricZOI.xml.

Changed files

File Change
ResourceLib/BelowGround/Individual/FON/FON.cpp New — pybind11 C++ kernel
ResourceLib/BelowGround/Individual/FON/FON.py Add C++ backend dispatch
ResourceLib/BelowGround/Individual/FON/FON.md Add backend_type attribute, C++ Backend section, cpp example
ResourceLib/CppBackend.md Add FON to supported modules table
CMakeLists.txt Register fonzoi module
Benchmarks/BenchmarkList.xml Register FONcpp_CI and FONcpp under Jabowa
Benchmarks/.../Jabowa/.../FONcpp_CI.xml New — C++ backend CI benchmark
Benchmarks/.../Jabowa/.../FONcpp.xml New — C++ backend long benchmark
Benchmarks/.../Jabowa/.../ReferenceFiles/FONcpp*/ New — reference CSVs
Benchmarks/.../Jabowa/.../FON.xml Fix output_dir self-overwrite bug
Benchmarks/.../Bettina/.../FON.xml Fix output_dir self-overwrite bug

@Lgz-tud Lgz-tud changed the title [RL] FON: add optional C++ backend (pybind11) [RL] FON: add optional C++ backend Apr 6, 2026
@Lgz-tud

Lgz-tud commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator Author

This PR depends on #399 (PBC + phi). Please review and merge #399 first.

@Lgz-tud

Lgz-tud commented Apr 6, 2026

Copy link
Copy Markdown
Collaborator Author

After cloning the C++ backend, need to recompile it locally before it will run.

Base automatically changed from feature/fon-pbc-phi to master April 15, 2026 15:01
- Add FON.cpp with pybind11 bindings for FON belowground competition
- Add backend_type selection in FON.py (cpp/python, auto-fallback)
- Register fonzoi module in CMakeLists.txt
- Add FONcpp benchmarks under Jabowa with reference files
- Fix FON.xml output_dir pointing to ReferenceFiles (self-overwrite bug)
- Update CppBackend.md and FON.md documentation
@Lgz-tud Lgz-tud force-pushed the feature/fon-cpp-backend branch from 5fbe174 to 8f44e3f Compare April 16, 2026 06:26
- Default backend_type to "auto" instead of "cpp" so omitting
  <backend_type> triggers silent auto-selection, matching docs
- Add grid shape equality check in C++ entry point
- Clamp PBC index range to grid size to prevent theoretical
  double-counting when FON radius exceeds domain half-width
@Lgz-tud Lgz-tud requested a review from mcwimm April 22, 2026 10:03

@mcwimm mcwimm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can be merged after the small requested change 👍

```

- FON with C++ backend on a 22x22m² mesh.
- The C++ backend requires compilation (see `CppBackend.md`). If the compiled module is not found, pyMANGA falls back to the pure Python implementation automatically.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- The C++ backend requires compilation (see `CppBackend.md`). If the compiled module is not found, pyMANGA falls back to the pure Python implementation automatically.
- The C++ backend requires compilation (see `pyMANGA.ResourceLib`). If the compiled module is not found, pyMANGA falls back to the pure Python implementation automatically.

By referencing pyMANGA.ResourceLib, users can jump directly to the documentation. Could you please check whether this needs to be changed elsewhere, too?

Per Marie's review on PR #400: linking to the package path lets
users jump directly to the generated documentation.
Lgz-tud added a commit that referenced this pull request Jun 6, 2026
Match the convention applied in PR #400 (FON.md). Linking to the
package path lets users jump directly to the generated documentation.
@Lgz-tud

Lgz-tud commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the suggestion, Marie! Done in 04908ecFON.md:174 now references pyMANGA.ResourceLib.

I also checked elsewhere: SymmetricZOI.md:193 had the same CppBackend.md reference (added in #403). I applied the same fix there in feature/pbc-all-modules (6afe065) so the convention stays consistent. No other docs reference CppBackend.md directly.

@Lgz-tud Lgz-tud merged commit 361c09d into master Jun 6, 2026
1 check passed
@Lgz-tud Lgz-tud deleted the feature/fon-cpp-backend branch June 6, 2026 19:06
Lgz-tud added a commit that referenced this pull request Jun 6, 2026
Match the convention applied in PR #400 (FON.md). Linking to the
package path lets users jump directly to the generated documentation.
jvollhueter pushed a commit to jvollhueter/pyMANGA-1 that referenced this pull request Jun 7, 2026
Per Marie's review on PR pymanga#400: linking to the package path lets
users jump directly to the generated documentation.
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