You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains 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
The current while-loop metanode is (a) not a nice UI at all, and (b) not pickleable (or even easy to read/understand). I set out to replace it with something like the For class and for_node constructor for for-loops, but didn't find a way of breaking things out well enough to get a clean UI.
In lieu of replacing it with a new tool, here I just remove it entirely and replace it with a raw example (in both the deepdive and the integration tests) how you can make a cyclic subgraph directly as a macro. There is still some "universal" aspects to this that I'd love to eventually abstract out to a @as_while_loop decorator or something, but in the meantime I found sticking to a plain macro makes it much cleaner to handle setting up both the logic and the IO.
As long as body functionality and condition functionality are in turn nicely abstracted into their own nodes/macros, the example below is extremely generic. Note also that since the same nodes get executed multiple times, it also shows how the (new to this PR) AppendToList node can be used to track the parts of the history of the loop that is important to you.
frompyiron_workflowimportWorkflow@Workflow.wrap.as_macro_node("greater")defAddWhileLessThan(self, a, b, cap):
""" Add :param:`b` to :param:`a` while the sum is less than or equal to :param:`cap`. A simple but complete demonstrator for how to construct cyclic flows, including logging key outputs during the loop. """# Bespoke logicself.body=Workflow.create.standard.Add(obj=a, other=b)
self.body.inputs.obj=self.body.outputs.add# Higher priority connection# The output is NOT_DATA on the first pass and `a` gets used,# But after that the node will find and use its own outputself.condition=Workflow.create.standard.LessThan(self.body, cap)
# Universal logicself.switch=Workflow.create.standard.If(condition=self.condition)
self.starting_nodes= [self.body]
self.body>>self.condition>>self.switchself.switch.signals.output.true>>self.body# Bespoke loggingself.history=Workflow.create.standard.AppendToList()
self.history.inputs.existing=self.historyself.history.inputs.new_element=self.bodyself.body>>self.history# Returns are pretty universal for single-value body nodes,# assuming a log of the history is not desired as output,# but in general return values are also bespokereturnself.bodyawlt=AddWhileLessThan()
out=awlt(0, 2, 5)
print(out)
>>> {'greater': 6}
print(awlt.history.outputs.list.value)
>>> [2, 4, 6]
awlt.draw(size=(10, 10))
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%
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.
The current while-loop metanode is (a) not a nice UI at all, and (b) not pickleable (or even easy to read/understand). I set out to replace it with something like the
For
class andfor_node
constructor for for-loops, but didn't find a way of breaking things out well enough to get a clean UI.In lieu of replacing it with a new tool, here I just remove it entirely and replace it with a raw example (in both the deepdive and the integration tests) how you can make a cyclic subgraph directly as a macro. There is still some "universal" aspects to this that I'd love to eventually abstract out to a
@as_while_loop
decorator or something, but in the meantime I found sticking to a plain macro makes it much cleaner to handle setting up both the logic and the IO.As long as body functionality and condition functionality are in turn nicely abstracted into their own nodes/macros, the example below is extremely generic. Note also that since the same nodes get executed multiple times, it also shows how the (new to this PR)
AppendToList
node can be used to track the parts of the history of the loop that is important to you.