Skip to content

Conversation

@liamhuber
Copy link
Member

@liamhuber liamhuber commented May 26, 2025

Introducing a new While node in analogy to the For node. As a second-order, stateful, dynamic node, retrospective provenance gets automatically handled by the way we have individual body nodes. Cyclic loops are specified by reference to IO channel name pairs (strings, ugh...) between the body and the test, and the body and itself:

import pyiron_workflow.api as pwf
from pyiron_workflow.nodes.while_loop import while_node

wf = pwf.Workflow("my_while_loop")
wf.x0 = pwf.std.UserInput(0)
wf.limit = pwf.std.UserInput(5)
wf.step = pwf.std.UserInput(2)
wf.add_while = while_node(
    pwf.std.LessThan,  # Test
    pwf.std.Add,  # Body
    [("add", "obj")],  # body-to-test
    [("add", "obj")],  # body-to-body
    strict_condition_hint=False,  # LessThan doesn't hint it's boolean return...
    test_obj=wf.x0,
    test_other=wf.limit,
    body_obj=wf.x0,
    body_other=wf.step
)
wf.xf = wf.add_while.outputs.add  # While output maps to body output
wf()
>>> {'add_while__add': 6}

TODO:

  • Debug the caching tests
  • Add tests for the cyclic edge maps (disallow non-existent edges)
  • Test and allow continuing from a failed state
    • On failure, we get the provenance graph leading up to the failure; that will suffice for now
  • Add and test executors for the body and condition
  • Docstrings
  • Include in the deepdive
  • (Maybe?) Replace other while examples with this (they still keep working since they're just a hard-code on signal control + some provenance logging, but since they're not encouraged I'm inclined to eliminate them...) Other than the deep dive, I only found the integration test. I actually like the integration test as an example of what we could accomplish by exploiting the separation of data and signal edges, so I'll leave it. Of course, the new While class has significantly better provenance behaviour, so it's the recommended attack for these loops.

Closes #501

@samwaseda, I guess you may be interested to keep a high-level eye here to see if you like my concrete implementation of what we're talking about over in pyiron/flowrep#24. I will naturally try to keep everything here fully compliant with what we decide there.

liamhuber added 15 commits May 23, 2025 13:52
It doesn't actually _do_ anything, but it has the outer shell

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
This will let us call Composite._on_run repeatedly in the While subclass without resetting our provenance tracking, but otherwise made no visible impact in any other use case.

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_workflow/retrospective_while

@liamhuber liamhuber added the enhancement New feature or request label May 26, 2025
liamhuber added 7 commits May 26, 2025 17:48
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
To subclass definition time -- fail early!

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
We handle lists from the instantiator; with the factory it is just lucky that lists were similar enough. But to be proper, let's use the requested type.

Signed-off-by: liamhuber <[email protected]>
@codecov
Copy link

codecov bot commented May 27, 2025

Codecov Report

Attention: Patch coverage is 98.55072% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.87%. Comparing base (66ab17b) to head (5d9b3b4).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pyiron_workflow/create.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #650      +/-   ##
==========================================
+ Coverage   91.61%   91.87%   +0.25%     
==========================================
  Files          33       34       +1     
  Lines        3458     3593     +135     
==========================================
+ Hits         3168     3301     +133     
- Misses        290      292       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

liamhuber added 8 commits May 27, 2025 10:04
Signed-off-by: liamhuber <[email protected]>
Missing coverage noticed by Codecov, tests written by ChatGPT (after I added the extra error)

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
It is already in the creator, so its absence here was just an oversight.

Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
Signed-off-by: liamhuber <[email protected]>
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@liamhuber liamhuber changed the title [WIP] Retrospective while Retrospective while May 27, 2025
@liamhuber liamhuber marked this pull request as ready for review May 27, 2025 18:33
For equivalence with the for-loop example and to get coverage on the creator link

Signed-off-by: liamhuber <[email protected]>
@liamhuber
Copy link
Member Author

@Tara-Lakshmipathy @ligerzero-ai, no action necessary on your part, just an FYI that there is a new interface for while-loops available. It's directly analogous to the existing for-loop interface. It's (hopefully) much easier to use than the old by-hand way of forcing a cyclic macro, and has the advantage of producing a full retrospective provenance graph automatically (unlike the by-hand approach which re-ran the same node repeatedly).

@liamhuber liamhuber merged commit 619ad92 into main May 27, 2025
17 of 18 checks passed
@liamhuber liamhuber deleted the retrospective_while branch May 27, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rework While

2 participants