Skip to content

Conversation

@Lgz-tud
Copy link
Collaborator

@Lgz-tud Lgz-tud commented Sep 16, 2025

No description provided.

@Lgz-tud Lgz-tud changed the title [RL] Using C++ to Refactor AsymmetricZOI PyManga's C++ kernel Sep 16, 2025
Copy link
Collaborator

@mcwimm mcwimm left a comment

Choose a reason for hiding this comment

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

Great! It's much clearer than before. I haven't tried it yet.

In general, I'm still not 100% convinced by the structure if we want to include it for more modules. Perhaps we could make both versions (original and CPP) available without having multiple modules (as before). I think you're almost there.

This would also enable us to create benchmarks for comparing the implementations individually.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm don't get why this benchmark file is located in this location and what the difference to the previous one is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, they are identical. We can directly reference the previous XML file without placing it in a new location.

@@ -0,0 +1,251 @@
# ============================================================
# CmakeLists overview (pymanga_cpp) — What this CMake does
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is something a user needs to do before using cpp modules, we need to provide this information elsewhere, e.g., in the source code and input documentation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

CMakeLists.txt serves as our build script, instructing CMake on how to compile and link our source code. The introductory remarks could be included in the readme, though such complexity is unnecessary. I have written this in such detail solely for your review. Typically, when publishing a model, such exhaustive explanations are unnecessary. Often, it suffices to state in the README that we use CMake, much like iland's Qt implementation: https://github.com/edfm-tum/iland-model

@@ -0,0 +1,154 @@
// ResourceLib/AboveGround/AsymmetricZOI/AsymmetricZOI.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please check whether we can include these files in our source code and input documentation? If so, could you also check what the comment format is to do this automatically?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, I will check it.

The C++ core parallelizes the grid evaluation using OpenMP, allowing efficient simulation of large stands with many individuals and fine spatial resolution.


# Compilation
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this will be the same for all modules. So maybe we should find another position in the documentation where we can describe this once.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I agree with your point.

- Define the grid on which to calculate above-ground resource availability.
- The total size is 20x20 m, and a cell is 0.25 x 0.25 m (20 m / 80 cells = 0.25 m/cell).
- Define the large grid on which to calculate above-ground resource availability.
- The total size is 1000x1000 m, and a cell is 0.25 x 0.25 m (20 m / 80 cells = 0.25 m/cell).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would keep the examples here small as they are supposed to run very quickly for all users.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No problem. This can be adjusted as required.

#!/usr/bin/env python3 # Shebang for Unix-like systems to run the script with Python 3
# -*- coding: utf-8 -*- # File encoding declaration

import numpy as np
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to implement a switch, e.g., at project level, so that we can keep the plain python implementation. Depending on the settings in the project file, the python or cpp module is used.

Not every user will be able to change the c-code or wants to compile C++.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, need to add a new conditional function. Then expose a parameter interface, allowing users to freely utilise the module by controlling whether to enable C++.

The class computes per-plant aboveground resource factors via asymzoi.compute_aboveground_resources.
"""
def __init__(self, args):
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Docstrings (""" THIS IS A COMMENT""") will be automatically included in our source code documentation. Could you please leave them where they are?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

gx, gy = self._require_grid() # Retrieve validated grid arrays (2D and same shape)

# Convert inputs to C-contiguous float32 arrays to match the C++ interface and save memory
xe = np.ascontiguousarray(np.asarray(self.xe, dtype=np.float32)) # X positions of plants
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to avoid making comments that say the same thing as the code (Check out the first rule here: https://stackoverflow.blog/2021/12/23/best-practices-for-writing-code-comments/).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

@Lgz-tud
Copy link
Collaborator Author

Lgz-tud commented Sep 30, 2025

I shall be taking a week's leave from the afternoon of today until the 8th of October. I cannot confirm whether the new submission will be completed today. Should it not be finalised today, the new pull request will be processed after the 8th.

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