-
Notifications
You must be signed in to change notification settings - Fork 14
PyManga's C++ kernel #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
PyManga's C++ kernel #388
Conversation
mcwimm
left a comment
There was a problem hiding this 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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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++.
There was a problem hiding this comment.
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): | ||
| """ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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/).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
|
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. |
No description provided.