Perform topological sort to order components#428
Conversation
|
This is nearly done. Remaining tasks:
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #428 +/- ##
==========================================
+ Coverage 29.52% 30.51% +0.98%
==========================================
Files 94 94
Lines 8768 8903 +135
Branches 1228 1257 +29
==========================================
+ Hits 2589 2717 +128
- Misses 5914 5916 +2
- Partials 265 270 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a75b2ce to
8d049e2
Compare
c31490e to
e650c1c
Compare
e650c1c to
9dbeed5
Compare
9dbeed5 to
04a8977
Compare
Note that components still aren't setting up any permissions, so there would be runtime errors when executing the transform methods. Furthermore, there are some missing methods I realise I need for GuardedOptions. The unit tests are also failing to compile, although I don't understand what the problem is for them, yet.
04a8977 to
8fc17e0
Compare
|
I missed this in #421, but I see that you added a long-needed feature - a better way to determine species type which is based on the charge: hermes-3/src/component_scheduler.cxx Lines 339 to 352 in 8fc17e0 There is already a function that does the same in hermes-3/include/hermes_utils.hxx Lines 61 to 70 in 053c9bb Ideally there should be only one tool to do this, and your new one seems more robust. Is there any reason not to replace the one in |
Probably not. I just wasn't sure if people would be happy about me changing that bit of code. Note that this will require changing the function signature of |
|
I went through the sorting algorithm and I see that you have left a good amount of comments on the individual bits. However, I found it difficult to get my head around what's going on just because of the amount of steps involved. It would be very useful to have a paragraph describing how the algorithm works step-by-step, either in the docs or in the comments (or both) |
|
There are some places (e.g., when writing tests) where it was convenient to just be able to have a list of species names and use the old heuristics to categorise them. Probably not a good enough reason to keep that though. |
ZedThree
left a comment
There was a problem hiding this comment.
LGTM, thanks @cmacmackin!
There's some trivial bits that I'm happy to fix myself
| const std::set<std::string> ComponentScheduler::predeclared_variables = { | ||
| "time", "linear", "units:inv_meters_cubed", "units:eV", "units:Tesla", | ||
| "units:seconds", "units:meters"}; |
There was a problem hiding this comment.
Given this is only used in this file, we can move the declaration out of the header and just have it here.
|
|
||
| /// Get all the parent sections of a variable "path". Sections are | ||
| /// separated by colons in the path. | ||
| std::set<std::string> getParents(const std::string& name) { |
There was a problem hiding this comment.
Is this just strsplit(name, ':')?
There was a problem hiding this comment.
No, because rather than splitting on ':' it is returning the hierarchy of parent sections. So, e.g., getParents("species:d:collision_frequencies:d_d_coll") would return {"species", "species:d", "species:d:collision_frequencies"}.
There was a problem hiding this comment.
Ah, I see! I'll add that example to the docstring, that's very clear
| // FIXME: this isn't an empty set | ||
| //result.insert({name, {name}}); | ||
| result.insert({name, {}}); |
There was a problem hiding this comment.
I'm a bit confused by the comment -- is it outdated?
There was a problem hiding this comment.
Yes, should have deleted that and the commented line. I must have left that during some debugging.
| /// In pratice, `item` here represents the index of a particular | ||
| /// component. The indices of the dependencies of `item` are stored in | ||
| /// the corresponding element of `dependencies`. | ||
| void topological_sort(const std::vector<std::set<size_t>>& dependencies, size_t item, |
There was a problem hiding this comment.
All these local functions can go in an anonymous namespace
There was a problem hiding this comment.
What is the advantage of putting them in an anonymous namespace?
There was a problem hiding this comment.
It's a guard against One Definition Rule (ODR) violations -- basically ensures that functions have names unique to the translation unit, and so if there happens to be another function with the same name somewhere else, they won't clash at link time.
|
|
||
| All component constructors must pass a `Permissions` object to the | ||
| constructor on the `Component::Component` base class. This specifies | ||
| which variables will be read/written by the `Component::transform` | ||
| method and will be used to construct a `GuardedOptions` object to be | ||
| passed into `Component::transform_impl`. The `Permissions` object | ||
| (`Component::state_variable_access`) can be further updated in the | ||
| body of the constructor of your component, based on what | ||
| configurations were specified in ``alloptions``. You should give read | ||
| and write permissions to the minimum number of variables necessary, to | ||
| avoid circular dependencies arising among components. |
There was a problem hiding this comment.
This paragraph appears to be a duplicate which arose due to a mistake during a rebase (almost certainly my fault!). It should be deleted.
Using the access control information introduced in #421, this PR makes it possible for Hermes-3 to work out the order of components at run-time. This will make things far simpler and more robust for users. It will also fail faster if there is an unsatisfiable or circular dependency.
Closes #384.