-
Notifications
You must be signed in to change notification settings - Fork 2
Mermaid graph #363
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
Merged
Merged
Mermaid graph #363
Changes from all commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
c4726e3
Start of adding mermaid graphs
jlheflin ce04f9f
Restart addition of mermaid graph, test with hello_world function
jlheflin d00bdb7
Trying to add tests for mermaid.cpp
jlheflin 7259026
just like me, ctest keeps failing
jlheflin 0d6659f
Committing clang-format changes
github-actions[bot] 203a8c8
Update mermaid.cpp
ryanmrichard b08bf98
Update mermaid.cpp
ryanmrichard 6e720d1
Committing clang-format changes
github-actions[bot] 09fb829
Finally actually doing some code
jlheflin 4a419c9
Committing clang-format changes
github-actions[bot] 372538f
Made suggested changes regarding mermaid.cpp, mermaid.hpp and the tes…
jlheflin ee6fdd4
Made changes with usage of decltype
jlheflin f61012b
Preparing to add module with several nested modules
jlheflin 29fe47e
Committing clang-format changes
github-actions[bot] 98746b2
loaded test modules into mm
jlheflin c4ad8dd
Committing clang-format changes
github-actions[bot] 0177e4f
adjusted code to work since it didn't in the previous commit
jlheflin ff92d0c
Lego'd the modules, compiled normally?
jlheflin a06ae22
added some debug printout
jlheflin fca1de6
Committing clang-format changes
github-actions[bot] af6a531
Added submodule printing function, adjusted module creation
jlheflin 953195f
Added submodule printing function, adjusted module creation
jlheflin 40d249e
In git commit purgatory, making sure I didn't kill anything
jlheflin 5125681
Committing clang-format changes
github-actions[bot] 8c9a575
Really close now
jlheflin 8afb7a8
Committing clang-format changes
github-actions[bot] 015c5af
I am really hating these clang-formats
jlheflin 7e07b3b
Committing clang-format changes
github-actions[bot] 5e5a879
Learned how to deal with missing submodules
jlheflin 6a21485
Committing clang-format changes
github-actions[bot] 7eac1b7
removed some debugging statements and learned clang-format
jlheflin 2d30468
reflowed the files a bit
jlheflin 1a26759
commiting clang-format changes, by myself
jlheflin ccb47bb
adding changes
jlheflin 2c295a7
if my brain was a stringstream
jlheflin 86a440d
I have an indent in my head
jlheflin db6470d
I am now a stringstream master (I only know ss.str())
jlheflin cc0e230
removed indent for modules, not needed
jlheflin 75e9a42
function is now recursive
jlheflin 1bb7e5a
bargain-bin GhostFragment test added
jlheflin 8951fd1
commiting clang-format changes, but this time with more pizzazz
jlheflin 3f3fbc6
removed multi-line comments
jlheflin 9b5d8ab
started conversion to mermaid graph output
jlheflin 9569cbc
clang-format, but with less pizzazz
jlheflin 74bdff6
fixed the letter issue
jlheflin e373ecf
adjusted src mermaid.cpp to better follow the mermaid style
jlheflin 1748a54
Committing clang-format changes
github-actions[bot] 31ab2f1
Functional Mermaid Graph now implemented in mermaid.cpp
jlheflin 2f33e42
Committing clang-format changes
github-actions[bot] 85be342
Adjusted tests to unit tests instead of an integration test
jlheflin 2cd6ca0
Committing clang-format changes
github-actions[bot] 530d9c6
Merge branch 'master' into mermaid-graph
jlheflin d611a1c
Apply suggestions from code review
ryanmrichard 3f712ee
remove ss.str() printing
jlheflin 01208fa
unpdate include path
jlheflin fa74221
Committing clang-format changes
github-actions[bot] 1574ef4
added functions to pluginplay::printing namespace
jlheflin 4de393d
fixed letter code issue
jlheflin 4150c25
adjusted letter generation code
jlheflin 423a6ba
Update src/pluginplay/printing/mermaid.cpp
ryanmrichard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * Copyright 2023 NWChemEx-Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
| #include <pluginplay/module_manager/module_manager_class.hpp> | ||
| #include <sstream> | ||
|
|
||
| namespace pluginplay::printing { | ||
|
|
||
| std::stringstream create_mermaid_graph(const pluginplay::ModuleManager& mm); | ||
|
|
||
| void print_submods(const std::string module_key, | ||
| const pluginplay::ModuleManager& mm, std::stringstream& ss, | ||
| std::string& module_code); | ||
| } // namespace pluginplay::printing | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright 2024 NWChemEx-Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <pluginplay/module/module_class.hpp> | ||
| #include <pluginplay/module_manager/module_manager_class.hpp> | ||
| #include <sstream> | ||
|
|
||
| namespace pluginplay::printing { | ||
|
|
||
| void add_letter(std::string& code) { | ||
| if(code.size() == 0) return; | ||
| for(int i = (code.size() - 1); i >= 0; --i) { | ||
ryanmrichard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if(code[i] == 'Z') { | ||
| code[i] = 'A'; | ||
| } else { | ||
| code[i]++; | ||
| return; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void print_submods(const std::string module_key, | ||
| const pluginplay::ModuleManager& mm, std::stringstream& ss, | ||
| std::string& module_code) { | ||
| const auto& mm_module = mm.at(module_key); // Results in a PluginPlay Module | ||
| const auto& submods = mm_module.submods(); // Results in list of Submodules | ||
| auto main_mod_code = module_code; | ||
|
|
||
| // Key is the ID/Tag, Value is the reference to the Module | ||
| for(const auto& [key, value] : submods) { | ||
| ss << "\n\t" << main_mod_code << "-->" | ||
| << "|" << key << "| "; | ||
| if(value.has_module() == false) { | ||
| add_letter(module_code); | ||
| ss << module_code << "[No Submodule associated with Key]"; | ||
| } else { | ||
| add_letter(module_code); | ||
| ss << module_code << "[" << value.get_name() << "]"; | ||
| print_submods(value.get_name(), mm, ss, module_code); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| std::stringstream create_mermaid_graph(const pluginplay::ModuleManager& mm) { | ||
| auto n_modules = mm.size(); | ||
| std::stringstream ss; | ||
| std::string module_code = "AAA"; | ||
| if(n_modules == 0) { | ||
| ss << "No modules are loaded, load some modules!"; | ||
| } else { | ||
| for(decltype(n_modules) i = 0; i < n_modules; i++) { | ||
| ss << "\n```mermaid"; | ||
| ss << "\nflowchart LR\n"; | ||
| auto mod = mm.keys()[i]; | ||
| ss << "\t" << module_code << "[" << mod << "]"; | ||
| print_submods(mod, mm, ss, module_code); | ||
| ss << "\n```"; | ||
| add_letter(module_code); | ||
| } | ||
| } | ||
| return ss; | ||
| } | ||
| } // namespace pluginplay::printing | ||
ryanmrichard marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /* | ||
| * Copyright 2024 NWChemEx-Project | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "../catch.hpp" | ||
| #include "../test_common.hpp" | ||
| #include "unit_testing_pts.hpp" | ||
| #include <catch2/catch_test_macros.hpp> | ||
| #include <pluginplay/module/macros.hpp> | ||
| #include <pluginplay/module_manager/module_manager.hpp> | ||
| #include <pluginplay/printing/mermaid.hpp> | ||
| #include <sstream> | ||
| #include <string> | ||
|
|
||
| DECLARE_MODULE(OneModule); | ||
| inline MODULE_CTOR(OneModule) { satisfies_property_type<testing::NullPT>(); } | ||
| inline MODULE_RUN(OneModule) { return results(); } | ||
|
|
||
| DECLARE_MODULE(TwoModule); | ||
| inline MODULE_CTOR(TwoModule) { satisfies_property_type<testing::NullPT>(); } | ||
| inline MODULE_RUN(TwoModule) { return results(); } | ||
|
|
||
| DECLARE_MODULE(ThreeModule); | ||
| inline MODULE_CTOR(ThreeModule) { satisfies_property_type<testing::NullPT>(); } | ||
| inline MODULE_RUN(ThreeModule) { return results(); } | ||
|
|
||
| DECLARE_MODULE(OneModuleSubTwo); | ||
| inline MODULE_CTOR(OneModuleSubTwo) { | ||
| satisfies_property_type<testing::NullPT>(); | ||
| add_submodule<testing::NullPT>("Submodule"); | ||
| } | ||
| inline MODULE_RUN(OneModuleSubTwo) { return results(); } | ||
|
|
||
| DECLARE_MODULE(TwoModuleSubThree); | ||
| inline MODULE_CTOR(TwoModuleSubThree) { | ||
| satisfies_property_type<testing::NullPT>(); | ||
| add_submodule<testing::NullPT>("Submodule"); | ||
| } | ||
| inline MODULE_RUN(TwoModuleSubThree) { return results(); } | ||
|
|
||
| DECLARE_MODULE(OneModuleSubTwoThree); | ||
| inline MODULE_CTOR(OneModuleSubTwoThree) { | ||
| satisfies_property_type<testing::NullPT>(); | ||
| add_submodule<testing::NullPT>("Submodule 1"); | ||
| add_submodule<testing::NullPT>("Submodule 2"); | ||
| } | ||
| inline MODULE_RUN(OneModuleSubTwoThree) { return results(); } | ||
|
|
||
| TEST_CASE("Mermaid Graph") { | ||
| SECTION("No Modules") { | ||
| pluginplay::ModuleManager no_mods; | ||
| auto hello = pluginplay::printing::create_mermaid_graph(no_mods); | ||
| REQUIRE(hello.str() == "No modules are loaded, load some modules!"); | ||
| } | ||
|
|
||
| SECTION("One Module") { | ||
| pluginplay::ModuleManager one_mod; | ||
| one_mod.add_module<OneModule>("One Module"); | ||
| auto onemod = pluginplay::printing::create_mermaid_graph(one_mod); | ||
| std::string val = "\n```mermaid\nflowchart LR\n\tAAA[One Module]\n```"; | ||
|
|
||
| REQUIRE(val == onemod.str()); | ||
| } | ||
|
|
||
| SECTION("2 Modules, Not Related") { | ||
| std::stringstream ss; | ||
| pluginplay::ModuleManager two_mods_unrelated; | ||
| two_mods_unrelated.add_module<OneModule>("One Module"); | ||
| two_mods_unrelated.add_module<TwoModule>("Two Module"); | ||
| auto twomod = | ||
| pluginplay::printing::create_mermaid_graph(two_mods_unrelated); | ||
| ss << "\n```mermaid\nflowchart LR\n\tAAA[One Module]\n```"; | ||
| ss << "\n```mermaid\nflowchart LR\n\tAAB[Two Module]\n```"; | ||
|
|
||
| REQUIRE(ss.str() == twomod.str()); | ||
| } | ||
|
|
||
| SECTION("2 Modules, Related") { | ||
| std::stringstream ss2; | ||
| pluginplay::ModuleManager two_mods_related; | ||
| two_mods_related.add_module<OneModuleSubTwo>("One Module Submod Two"); | ||
| two_mods_related.add_module<TwoModule>("Two Module"); | ||
| two_mods_related.change_submod("One Module Submod Two", "Submodule", | ||
| "Two Module"); | ||
| auto twomodrelated = | ||
| pluginplay::printing::create_mermaid_graph(two_mods_related); | ||
| ss2 << "\n```mermaid\nflowchart LR\n\tAAA[One Module Submod Two]\n"; | ||
| ss2 << "\tAAA-->|Submodule| AAB[Two Module]\n```"; | ||
| ss2 << "\n```mermaid\nflowchart LR\n\tAAC[Two Module]\n```"; | ||
| REQUIRE(ss2.str() == twomodrelated.str()); | ||
| } | ||
|
|
||
| SECTION("3 Modules, Nested") { | ||
| std::stringstream ss3; | ||
| pluginplay::ModuleManager three_mods_recursive; | ||
| three_mods_recursive.add_module<OneModuleSubTwo>( | ||
| "One Module Submod Two"); | ||
| three_mods_recursive.add_module<TwoModuleSubThree>( | ||
| "Two Module Submod Three"); | ||
| three_mods_recursive.add_module<ThreeModule>("Three Module"); | ||
| three_mods_recursive.change_submod("One Module Submod Two", "Submodule", | ||
| "Two Module Submod Three"); | ||
| three_mods_recursive.change_submod("Two Module Submod Three", | ||
| "Submodule", "Three Module"); | ||
| auto threemodrecursive = | ||
| pluginplay::printing::create_mermaid_graph(three_mods_recursive); | ||
| ss3 << "\n```mermaid\n"; | ||
| ss3 << "flowchart LR\n"; | ||
| ss3 << "\tAAA[One Module Submod Two]\n"; | ||
| ss3 << "\tAAA-->|Submodule| AAB[Two Module Submod Three]\n"; | ||
| ss3 << "\tAAB-->|Submodule| AAC[Three Module]\n"; | ||
| ss3 << "```"; | ||
| ss3 << "\n```mermaid\n"; | ||
| ss3 << "flowchart LR\n"; | ||
| ss3 << "\tAAD[Three Module]\n"; | ||
| ss3 << "```"; | ||
| ss3 << "\n```mermaid\n"; | ||
| ss3 << "flowchart LR\n"; | ||
| ss3 << "\tAAE[Two Module Submod Three]\n"; | ||
| ss3 << "\tAAE-->|Submodule| AAF[Three Module]\n"; | ||
| ss3 << "```"; | ||
|
|
||
| REQUIRE(ss3.str() == threemodrecursive.str()); | ||
| } | ||
|
|
||
| SECTION("3 Modules, Branched") { | ||
| std::stringstream ss4; | ||
| pluginplay::ModuleManager three_mods_branched; | ||
| three_mods_branched.add_module<OneModuleSubTwoThree>( | ||
| "One Module Submod Two Three"); | ||
| three_mods_branched.add_module<OneModule>("One Module"); | ||
| three_mods_branched.add_module<TwoModule>("Two Module"); | ||
| three_mods_branched.change_submod("One Module Submod Two Three", | ||
| "Submodule 1", "One Module"); | ||
| three_mods_branched.change_submod("One Module Submod Two Three", | ||
| "Submodule 2", "Two Module"); | ||
| auto threemodsbranched = | ||
| pluginplay::printing::create_mermaid_graph(three_mods_branched); | ||
|
|
||
| ss4 << "\n```mermaid\n"; | ||
| ss4 << "flowchart LR\n"; | ||
| ss4 << "\tAAA[One Module]\n"; | ||
| ss4 << "```"; | ||
| ss4 << "\n```mermaid\n"; | ||
| ss4 << "flowchart LR\n"; | ||
| ss4 << "\tAAB[One Module Submod Two Three]\n"; | ||
| ss4 << "\tAAB-->|Submodule 1| AAC[One Module]\n"; | ||
| ss4 << "\tAAB-->|Submodule 2| AAD[Two Module]\n"; | ||
| ss4 << "```"; | ||
| ss4 << "\n```mermaid\n"; | ||
| ss4 << "flowchart LR\n"; | ||
| ss4 << "\tAAE[Two Module]\n"; | ||
| ss4 << "```"; | ||
|
|
||
| REQUIRE(ss4.str() == threemodsbranched.str()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.