-
Notifications
You must be signed in to change notification settings - Fork 4
[Feature] Export to Python Workflow Definition #882
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c2a7d4c
Export to Python Workflow Definition
jan-janssen 338d9c9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8683249
Format black
pyiron-runner c8be904
Update dependency.py
jan-janssen df6c8ea
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b36d3a4
Add test
jan-janssen e146432
extend test
jan-janssen c0cf665
fix
jan-janssen 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
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,47 @@ | ||
| import json | ||
| import os | ||
| import unittest | ||
| import numpy as np | ||
| from executorlib import SingleNodeExecutor, get_item_from_future | ||
|
|
||
|
|
||
| def get_sum(x, y): | ||
| return x + y | ||
|
|
||
| def get_prod_and_div(x, y): | ||
| return {"prod": x * y, "div": x / y} | ||
|
|
||
| def get_square(x): | ||
| return x ** 2 | ||
|
|
||
|
|
||
| class TestPythonWorkflowDefinition(unittest.TestCase): | ||
| def tearDown(self): | ||
| if os.path.exists("workflow.json"): | ||
| os.remove("workflow.json") | ||
|
|
||
| def test_arithmetic(self): | ||
| with SingleNodeExecutor(export_workflow_filename="workflow.json") as exe: | ||
| future_prod_and_div = exe.submit(get_prod_and_div, x=1, y=2) | ||
| future_prod = get_item_from_future(future_prod_and_div, key="prod") | ||
| future_div = get_item_from_future(future_prod_and_div, key="div") | ||
| future_sum = exe.submit(get_sum, x=future_prod, y=future_div) | ||
| future_result = exe.submit(get_square, x=future_sum) | ||
| self.assertIsNone(future_result.result()) | ||
|
|
||
| with open("workflow.json", "r") as f: | ||
| content = json.load(f) | ||
|
|
||
| self.assertEqual(len(content["nodes"]), 6) | ||
| self.assertEqual(len(content["edges"]), 6) | ||
|
|
||
| def test_numpy_array(self): | ||
| with SingleNodeExecutor(export_workflow_filename="workflow.json") as exe: | ||
| future_sum = exe.submit(get_sum, x=np.array([1,2]), y=np.array([3,4])) | ||
| self.assertIsNone(future_sum.result()) | ||
|
|
||
| with open("workflow.json", "r") as f: | ||
| content = json.load(f) | ||
|
|
||
| self.assertEqual(len(content["nodes"]), 4) | ||
| self.assertEqual(len(content["edges"]), 3) |
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.
Handle empty edge list to prevent
ValueErroronmax().If
edge_lstis empty,pwd_edges_lstwill be empty, andmax([e["target"] for e in pwd_edges_lst])will raiseValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.🔎 Proposed fix
🤖 Prompt for AI Agents