Skip to content
Merged
Show file tree
Hide file tree
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 Dec 27, 2024
ce04f9f
Restart addition of mermaid graph, test with hello_world function
jlheflin Dec 27, 2024
d00bdb7
Trying to add tests for mermaid.cpp
jlheflin Dec 27, 2024
7259026
just like me, ctest keeps failing
jlheflin Dec 29, 2024
0d6659f
Committing clang-format changes
github-actions[bot] Dec 29, 2024
203a8c8
Update mermaid.cpp
ryanmrichard Dec 29, 2024
b08bf98
Update mermaid.cpp
ryanmrichard Dec 29, 2024
6e720d1
Committing clang-format changes
github-actions[bot] Dec 29, 2024
09fb829
Finally actually doing some code
jlheflin Jan 9, 2025
4a419c9
Committing clang-format changes
github-actions[bot] Jan 9, 2025
372538f
Made suggested changes regarding mermaid.cpp, mermaid.hpp and the tes…
jlheflin Jan 9, 2025
ee6fdd4
Made changes with usage of decltype
jlheflin Jan 9, 2025
f61012b
Preparing to add module with several nested modules
jlheflin Jan 10, 2025
29fe47e
Committing clang-format changes
github-actions[bot] Jan 10, 2025
98746b2
loaded test modules into mm
jlheflin Jan 14, 2025
c4ad8dd
Committing clang-format changes
github-actions[bot] Jan 14, 2025
0177e4f
adjusted code to work since it didn't in the previous commit
jlheflin Jan 14, 2025
ff92d0c
Lego'd the modules, compiled normally?
jlheflin Jan 16, 2025
a06ae22
added some debug printout
jlheflin Jan 16, 2025
fca1de6
Committing clang-format changes
github-actions[bot] Jan 16, 2025
af6a531
Added submodule printing function, adjusted module creation
jlheflin Jan 23, 2025
953195f
Added submodule printing function, adjusted module creation
jlheflin Jan 23, 2025
40d249e
In git commit purgatory, making sure I didn't kill anything
jlheflin Jan 23, 2025
5125681
Committing clang-format changes
github-actions[bot] Jan 23, 2025
8c9a575
Really close now
jlheflin Jan 23, 2025
8afb7a8
Committing clang-format changes
github-actions[bot] Jan 23, 2025
015c5af
I am really hating these clang-formats
jlheflin Jan 23, 2025
7e07b3b
Committing clang-format changes
github-actions[bot] Jan 23, 2025
5e5a879
Learned how to deal with missing submodules
jlheflin Jan 24, 2025
6a21485
Committing clang-format changes
github-actions[bot] Jan 24, 2025
7eac1b7
removed some debugging statements and learned clang-format
jlheflin Jan 24, 2025
2d30468
reflowed the files a bit
jlheflin Jan 24, 2025
1a26759
commiting clang-format changes, by myself
jlheflin Jan 24, 2025
ccb47bb
adding changes
jlheflin Jan 25, 2025
2c295a7
if my brain was a stringstream
jlheflin Jan 25, 2025
86a440d
I have an indent in my head
jlheflin Jan 26, 2025
db6470d
I am now a stringstream master (I only know ss.str())
jlheflin Jan 26, 2025
cc0e230
removed indent for modules, not needed
jlheflin Jan 27, 2025
75e9a42
function is now recursive
jlheflin Jan 28, 2025
1bb7e5a
bargain-bin GhostFragment test added
jlheflin Jan 30, 2025
8951fd1
commiting clang-format changes, but this time with more pizzazz
jlheflin Jan 30, 2025
3f3fbc6
removed multi-line comments
jlheflin Jan 30, 2025
9b5d8ab
started conversion to mermaid graph output
jlheflin Jan 30, 2025
9569cbc
clang-format, but with less pizzazz
jlheflin Jan 30, 2025
74bdff6
fixed the letter issue
jlheflin Feb 6, 2025
e373ecf
adjusted src mermaid.cpp to better follow the mermaid style
jlheflin Feb 13, 2025
1748a54
Committing clang-format changes
github-actions[bot] Feb 13, 2025
31ab2f1
Functional Mermaid Graph now implemented in mermaid.cpp
jlheflin Feb 17, 2025
2f33e42
Committing clang-format changes
github-actions[bot] Feb 17, 2025
85be342
Adjusted tests to unit tests instead of an integration test
jlheflin Mar 13, 2025
2cd6ca0
Committing clang-format changes
github-actions[bot] Mar 13, 2025
530d9c6
Merge branch 'master' into mermaid-graph
jlheflin Mar 13, 2025
d611a1c
Apply suggestions from code review
ryanmrichard Mar 13, 2025
3f712ee
remove ss.str() printing
jlheflin Mar 14, 2025
01208fa
unpdate include path
jlheflin Mar 14, 2025
fa74221
Committing clang-format changes
github-actions[bot] Mar 14, 2025
1574ef4
added functions to pluginplay::printing namespace
jlheflin Mar 14, 2025
4de393d
fixed letter code issue
jlheflin Mar 14, 2025
4150c25
adjusted letter generation code
jlheflin Mar 14, 2025
423a6ba
Update src/pluginplay/printing/mermaid.cpp
ryanmrichard Mar 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# These are directories used by IDEs for storing settings
.idea/
.vscode/
.cache

# These are common Python virtual enviornment directory names
venv/
Expand Down
28 changes: 28 additions & 0 deletions include/pluginplay/printing/mermaid.hpp
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
1 change: 1 addition & 0 deletions include/pluginplay/printing/printing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
#pragma once
#include <pluginplay/printing/document_module.hpp>
#include <pluginplay/printing/document_modules.hpp>
#include <pluginplay/printing/mermaid.hpp>
76 changes: 76 additions & 0 deletions src/pluginplay/printing/mermaid.cpp
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) {
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
169 changes: 169 additions & 0 deletions tests/cxx/unit_tests/pluginplay/printing/mermaid.cpp
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());
}
}