-
Notifications
You must be signed in to change notification settings - Fork 19
feat: LoopGraph #2262
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
Draft
trisyoungs
wants to merge
18
commits into
develop2
Choose a base branch
from
dissolve2/loop-subgraph
base: develop2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: LoopGraph #2262
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5fc76f6
Add basic structure.
trisyoungs 212c797
Don't forget to register the node.
7c5f384
Don't override node name.
a2ee897
Clear out old unit test code.
ca47696
Use InputsNode for loopback.
618565a
Proof of concept.
trisyoungs a169013
Fully working.
trisyoungs 0f7aa3f
Add Edge::requiresPull().
trisyoungs 4180ecc
Add controlling loopbackinvalidates_ option, tidy up, pause for a ret…
trisyoungs cbcdca4
Add debug output for testing.
trisyoungs 55d5a97
Getting somewhere (maybe).
trisyoungs 033f58d
This seems to do what we want.
trisyoungs b016808
Tidy up 1.
trisyoungs 28ab352
Tidy up 2.
trisyoungs add7bd5
Update node messaging, adding debug-level status.
trisyoungs 9fdee4f
Always copy parameters through edges, even if up-to-date.
trisyoungs ae259ee
Add Node::setEcho().
trisyoungs 4452f29
Remove comment from test.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2025 Team Dissolve and contributors | ||
|
|
||
| #include "nodes/debug.h" | ||
| #include <format> | ||
|
|
||
| namespace GraphDebug | ||
| { | ||
| // Current indent for printing | ||
| int indent_{0}; | ||
| // Return current indent | ||
| std::string indent() { return std::format("{:02d}{}", indent_, std::string(std::max(indent_, 0) * 2, ' ')); } | ||
| // Increase current indent | ||
| void increaseIndent() { ++indent_; } | ||
| // Decrease current indent | ||
| void decreaseIndent() { --indent_; } | ||
| }; // namespace GraphDebug |
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,15 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2025 Team Dissolve and contributors | ||
|
|
||
| #pragma once | ||
| #include <string> | ||
|
|
||
| namespace GraphDebug | ||
| { | ||
| // Return current indent | ||
| std::string indent(); | ||
| // Increase current indent | ||
| void increaseIndent(); | ||
| // Decrease current indent | ||
| void decreaseIndent(); | ||
| }; // namespace GraphDebug |
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
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
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
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,67 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2025 Team Dissolve and contributors | ||
|
|
||
| #include "nodes/loop.h" | ||
| #include "nodes/edge.h" | ||
| #include "nodes/inputs.h" | ||
|
|
||
| LoopGraph::LoopGraph(Graph *parentGraph) : Graph(parentGraph) | ||
| { | ||
| addOption<Number>("Iterations", "Number of iterations to perform", iterations_); | ||
| } | ||
|
|
||
| /* | ||
| * Definitions (Virtuals) | ||
| */ | ||
|
|
||
| // Return type of the node | ||
| std::string_view LoopGraph::type() const { return "Loop"; } | ||
|
|
||
| // Return short summary of the node's purpose | ||
| std::string_view LoopGraph::summary() const { return "A graph which iterates"; } | ||
|
|
||
| /* | ||
| * Processing & Validity | ||
| */ | ||
|
|
||
| // Perform processing | ||
| NodeConstants::ProcessResult LoopGraph::process() | ||
| { | ||
| // Before arriving here we will have pulled in any external input edges, and this is the data we should use on the | ||
| // first iteration of the loop. So, we only pull from inputs to our InputsNode (proxyInputs_) after the first | ||
| // iteration. Furthermore, we do this manually here rather than let InputsNode pull its own edges as otherwise we | ||
| // get into an infinite loop when the graph tries to run. In this sense the | ||
|
|
||
| for (auto n = 0; n < iterations_.asInteger(); ++n) | ||
| { | ||
| debug("{}LoopGraph({})::process() - iteration {}", GraphDebug::indent(), name(), n); | ||
|
|
||
| // Pull edges connected to our InputsNode *if* | ||
| if (n > 0) | ||
| { | ||
| for (auto &[inputName, edges] : proxyInputs_->inputEdges()) | ||
| { | ||
| for (const auto edge : edges) | ||
| { | ||
| debug("{}LoopGraph::process() - Pulling edge {}...\n", GraphDebug::indent(), edge->definition().asString()); | ||
| switch (edge->pull()) | ||
| { | ||
| case (NodeConstants::ProcessResult::Failed): | ||
| case (NodeConstants::ProcessResult::InputsNotSatisfied): | ||
| return NodeConstants::ProcessResult::Failed; | ||
| case (NodeConstants::ProcessResult::Success): | ||
| case (NodeConstants::ProcessResult::Unchanged): | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Process child nodes, returning early if we encounter an error | ||
| auto result = Graph::process(); | ||
| if (result == NodeConstants::ProcessResult::Failed || result == NodeConstants::ProcessResult::InputsNotSatisfied) | ||
| return NodeConstants::ProcessResult::Failed; | ||
| } | ||
|
Comment on lines
+35
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we had discussed your proposal during the stand-up, I had misunderstood and thought that you were putting this logic into the input nodes. Having this in the node answers 95% of my concerns. |
||
|
|
||
| return NodeConstants::ProcessResult::Success; | ||
| } | ||
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,37 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // Copyright (c) 2025 Team Dissolve and contributors | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "nodes/graph.h" | ||
|
|
||
| // Loop Graph | ||
| class LoopGraph : public Graph | ||
| { | ||
| public: | ||
| LoopGraph(Graph *parentGraph); | ||
| ~LoopGraph() = default; | ||
|
|
||
| /* | ||
| * Definition (Virtuals) | ||
| */ | ||
| public: | ||
| // Return type of the node | ||
| std::string_view type() const override; | ||
| // Return short summary of the node's purpose | ||
| std::string_view summary() const override; | ||
|
|
||
| /* | ||
| * Data | ||
| */ | ||
| public: | ||
| // Number of iterations to loop for | ||
| Number iterations_{1}; | ||
|
|
||
| /* | ||
| * Processing & Validity | ||
| */ | ||
| public: | ||
| // Perform processing | ||
| NodeConstants::ProcessResult process(); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Seems like there was more to come here!