Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/executorlib/executor/flux.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ class FluxJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -105,6 +106,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -152,6 +154,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -189,6 +192,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -255,6 +259,7 @@ class FluxClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -293,6 +298,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -338,6 +344,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -420,6 +427,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ class SingleNodeExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -94,6 +95,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -138,6 +140,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -171,6 +174,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -226,6 +230,7 @@ class TestClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -262,6 +267,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -299,6 +305,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -358,6 +365,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ class SlurmClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -101,6 +102,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -146,6 +148,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -225,6 +228,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand DownExpand Up@@ -275,6 +279,7 @@ class SlurmJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -312,6 +317,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -360,6 +366,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -394,6 +401,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand Down
23 changes: 17 additions & 6 deletions src/executorlib/task_scheduler/interactive/dependency.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
)
from executorlib.task_scheduler.base import TaskSchedulerBase
from executorlib.task_scheduler.interactive.dependency_plot import (
export_dependency_graph_function,
generate_nodes_and_edges_for_plotting,
generate_task_hash_for_plotting,
plot_dependency_graph_function,
Expand All@@ -28,6 +29,7 @@ class DependencyTaskScheduler(TaskSchedulerBase):
refresh_rate (float, optional): The refresh rate for updating the executor queue. Defaults to 0.01.
plot_dependency_graph (bool, optional): Whether to generate and plot the dependency graph. Defaults to False.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.

Attributes:
_future_hash_dict (Dict[str, Future]): A dictionary mapping task hash to future object.
Expand All@@ -44,6 +46,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
) -> None:
super().__init__(max_cores=max_cores)
self._process_kwargs = {
Expand All@@ -61,7 +64,8 @@ def __init__(
self._future_hash_dict: dict = {}
self._task_hash_dict: dict = {}
self._plot_dependency_graph_filename = plot_dependency_graph_filename
if plot_dependency_graph_filename is None:
self._export_workflow_filename = export_workflow_filename
if plot_dependency_graph_filename is None and export_workflow_filename is None:
self._generate_dependency_graph = plot_dependency_graph
else:
self._generate_dependency_graph = True
Expand DownExpand Up@@ -209,11 +213,18 @@ def __exit__(
v: k for k, v in self._future_hash_dict.items()
},
)
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
if self._export_workflow_filename is not None:
return export_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
file_name=self._export_workflow_filename,
)
else:
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
else:
return None

Expand Down
75 changes: 75 additions & 0 deletions src/executorlib/task_scheduler/interactive/dependency_plot.py
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
import inspect
import json
import os.path
from concurrent.futures import Future
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand DownExpand Up@@ -230,3 +232,76 @@ def plot_dependency_graph_function(
from IPython.display import SVG, display # noqa

display(SVG(nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")))


def export_dependency_graph_function(
node_lst: list, edge_lst: list, file_name: str = "workflow.json"
):
"""
Export the graph visualization of nodes and edges as a JSON dictionary.

Args:
node_lst (list): List of nodes.
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
pwd_nodes_lst.append(
{"id": n["id"], "type": n["type"], "value": n["value"]}
)
elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"].tolist(),
"name": n["name"],
}
)
else:
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"],
"name": n["name"],
}
)

final_node = {"id": len(pwd_nodes_lst), "type": "output", "name": "result"}
pwd_nodes_lst.append(final_node)
pwd_edges_lst = [
(
{
"target": e["end"],
"targetPort": e["label"],
"source": e["start"],
"sourcePort": None,
}
if "start_label" not in e
else {
"target": e["end"],
"targetPort": e["end_label"],
"source": e["start"],
"sourcePort": e["start_label"],
}
)
for e in edge_lst
]
pwd_edges_lst.append(
{
"target": final_node["id"],
"targetPort": None,
"source": max([e["target"] for e in pwd_edges_lst]),
"sourcePort": None,
}
)
Comment on lines +293 to +300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle empty edge list to prevent ValueError on max().

If edge_lst is empty, pwd_edges_lst will be empty, and max([e["target"] for e in pwd_edges_lst]) will raise ValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.

🔎 Proposed fix
- pwd_edges_lst.append(- {- "target": final_node["id"],- "targetPort": None,- "source": max([e["target"] for e in pwd_edges_lst]),- "sourcePort": None,- }- )+ if pwd_edges_lst:+ pwd_edges_lst.append(+ {+ "target": final_node["id"],+ "targetPort": None,+ "source": max(e["target"] for e in pwd_edges_lst),+ "sourcePort": None,+ }+ )
🤖 Prompt for AI Agents
In src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
293-300, the code calls max() on pwd_edges_lst which raises ValueError when
pwd_edges_lst is empty; update the logic to handle an empty list by computing
source only if pwd_edges_lst has elements (e.g., source = max(e["target"] for e
in pwd_edges_lst)), otherwise set source to a safe fallback (for example
final_node["id"] or None) or skip adding the edge entirely; implement a short
conditional that selects the fallback and then append the dict using that source
to avoid the max() on an empty sequence.

pwd_dict = {
"version": "0.1.0",
"nodes": pwd_nodes_lst,
"edges": pwd_edges_lst,
}
with open(file_name, "w") as f:
json.dump(pwd_dict, f, indent=4)
47 changes: 47 additions & 0 deletions tests/test_singlenodeexecutor_pwd.py
Original file line numberDiff line numberDiff 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)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all \u003cpre\u003e\u003ccode\u003e blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks"); } } catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); } })(); (function(){ try { var __m = "github.com"; var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/executorlib/executor/flux.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ class FluxJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -105,6 +106,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -152,6 +154,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -189,6 +192,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -255,6 +259,7 @@ class FluxClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -293,6 +298,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -338,6 +344,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -420,6 +427,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ class SingleNodeExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -94,6 +95,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -138,6 +140,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -171,6 +174,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -226,6 +230,7 @@ class TestClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -262,6 +267,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -299,6 +305,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -358,6 +365,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ class SlurmClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -101,6 +102,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -146,6 +148,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -225,6 +228,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand DownExpand Up@@ -275,6 +279,7 @@ class SlurmJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -312,6 +317,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -360,6 +366,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -394,6 +401,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand Down
23 changes: 17 additions & 6 deletions src/executorlib/task_scheduler/interactive/dependency.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
)
from executorlib.task_scheduler.base import TaskSchedulerBase
from executorlib.task_scheduler.interactive.dependency_plot import (
export_dependency_graph_function,
generate_nodes_and_edges_for_plotting,
generate_task_hash_for_plotting,
plot_dependency_graph_function,
Expand All@@ -28,6 +29,7 @@ class DependencyTaskScheduler(TaskSchedulerBase):
refresh_rate (float, optional): The refresh rate for updating the executor queue. Defaults to 0.01.
plot_dependency_graph (bool, optional): Whether to generate and plot the dependency graph. Defaults to False.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.

Attributes:
_future_hash_dict (Dict[str, Future]): A dictionary mapping task hash to future object.
Expand All@@ -44,6 +46,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
) -> None:
super().__init__(max_cores=max_cores)
self._process_kwargs = {
Expand All@@ -61,7 +64,8 @@ def __init__(
self._future_hash_dict: dict = {}
self._task_hash_dict: dict = {}
self._plot_dependency_graph_filename = plot_dependency_graph_filename
if plot_dependency_graph_filename is None:
self._export_workflow_filename = export_workflow_filename
if plot_dependency_graph_filename is None and export_workflow_filename is None:
self._generate_dependency_graph = plot_dependency_graph
else:
self._generate_dependency_graph = True
Expand DownExpand Up@@ -209,11 +213,18 @@ def __exit__(
v: k for k, v in self._future_hash_dict.items()
},
)
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
if self._export_workflow_filename is not None:
return export_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
file_name=self._export_workflow_filename,
)
else:
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
else:
return None

Expand Down
75 changes: 75 additions & 0 deletions src/executorlib/task_scheduler/interactive/dependency_plot.py
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
import inspect
import json
import os.path
from concurrent.futures import Future
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand DownExpand Up@@ -230,3 +232,76 @@ def plot_dependency_graph_function(
from IPython.display import SVG, display # noqa

display(SVG(nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")))


def export_dependency_graph_function(
node_lst: list, edge_lst: list, file_name: str = "workflow.json"
):
"""
Export the graph visualization of nodes and edges as a JSON dictionary.

Args:
node_lst (list): List of nodes.
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
pwd_nodes_lst.append(
{"id": n["id"], "type": n["type"], "value": n["value"]}
)
elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"].tolist(),
"name": n["name"],
}
)
else:
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"],
"name": n["name"],
}
)

final_node = {"id": len(pwd_nodes_lst), "type": "output", "name": "result"}
pwd_nodes_lst.append(final_node)
pwd_edges_lst = [
(
{
"target": e["end"],
"targetPort": e["label"],
"source": e["start"],
"sourcePort": None,
}
if "start_label" not in e
else {
"target": e["end"],
"targetPort": e["end_label"],
"source": e["start"],
"sourcePort": e["start_label"],
}
)
for e in edge_lst
]
pwd_edges_lst.append(
{
"target": final_node["id"],
"targetPort": None,
"source": max([e["target"] for e in pwd_edges_lst]),
"sourcePort": None,
}
)
Comment on lines +293 to +300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle empty edge list to prevent ValueError on max().

If edge_lst is empty, pwd_edges_lst will be empty, and max([e["target"] for e in pwd_edges_lst]) will raise ValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.

🔎 Proposed fix
- pwd_edges_lst.append(- {- "target": final_node["id"],- "targetPort": None,- "source": max([e["target"] for e in pwd_edges_lst]),- "sourcePort": None,- }- )+ if pwd_edges_lst:+ pwd_edges_lst.append(+ {+ "target": final_node["id"],+ "targetPort": None,+ "source": max(e["target"] for e in pwd_edges_lst),+ "sourcePort": None,+ }+ )
🤖 Prompt for AI Agents
In src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
293-300, the code calls max() on pwd_edges_lst which raises ValueError when
pwd_edges_lst is empty; update the logic to handle an empty list by computing
source only if pwd_edges_lst has elements (e.g., source = max(e["target"] for e
in pwd_edges_lst)), otherwise set source to a safe fallback (for example
final_node["id"] or None) or skip adding the edge entirely; implement a short
conditional that selects the fallback and then append the dict using that source
to avoid the max() on an empty sequence.

pwd_dict = {
"version": "0.1.0",
"nodes": pwd_nodes_lst,
"edges": pwd_edges_lst,
}
with open(file_name, "w") as f:
json.dump(pwd_dict, f, indent=4)
47 changes: 47 additions & 0 deletions tests/test_singlenodeexecutor_pwd.py
Original file line numberDiff line numberDiff 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)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/executorlib/executor/flux.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ class FluxJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -105,6 +106,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -152,6 +154,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -189,6 +192,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -255,6 +259,7 @@ class FluxClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -293,6 +298,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -338,6 +344,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -420,6 +427,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ class SingleNodeExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -94,6 +95,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -138,6 +140,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -171,6 +174,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -226,6 +230,7 @@ class TestClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -262,6 +267,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -299,6 +305,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -358,6 +365,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ class SlurmClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -101,6 +102,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -146,6 +148,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -225,6 +228,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand DownExpand Up@@ -275,6 +279,7 @@ class SlurmJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -312,6 +317,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -360,6 +366,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -394,6 +401,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand Down
23 changes: 17 additions & 6 deletions src/executorlib/task_scheduler/interactive/dependency.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
)
from executorlib.task_scheduler.base import TaskSchedulerBase
from executorlib.task_scheduler.interactive.dependency_plot import (
export_dependency_graph_function,
generate_nodes_and_edges_for_plotting,
generate_task_hash_for_plotting,
plot_dependency_graph_function,
Expand All@@ -28,6 +29,7 @@ class DependencyTaskScheduler(TaskSchedulerBase):
refresh_rate (float, optional): The refresh rate for updating the executor queue. Defaults to 0.01.
plot_dependency_graph (bool, optional): Whether to generate and plot the dependency graph. Defaults to False.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.

Attributes:
_future_hash_dict (Dict[str, Future]): A dictionary mapping task hash to future object.
Expand All@@ -44,6 +46,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
) -> None:
super().__init__(max_cores=max_cores)
self._process_kwargs = {
Expand All@@ -61,7 +64,8 @@ def __init__(
self._future_hash_dict: dict = {}
self._task_hash_dict: dict = {}
self._plot_dependency_graph_filename = plot_dependency_graph_filename
if plot_dependency_graph_filename is None:
self._export_workflow_filename = export_workflow_filename
if plot_dependency_graph_filename is None and export_workflow_filename is None:
self._generate_dependency_graph = plot_dependency_graph
else:
self._generate_dependency_graph = True
Expand DownExpand Up@@ -209,11 +213,18 @@ def __exit__(
v: k for k, v in self._future_hash_dict.items()
},
)
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
if self._export_workflow_filename is not None:
return export_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
file_name=self._export_workflow_filename,
)
else:
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
else:
return None

Expand Down
75 changes: 75 additions & 0 deletions src/executorlib/task_scheduler/interactive/dependency_plot.py
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
import inspect
import json
import os.path
from concurrent.futures import Future
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand DownExpand Up@@ -230,3 +232,76 @@ def plot_dependency_graph_function(
from IPython.display import SVG, display # noqa

display(SVG(nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")))


def export_dependency_graph_function(
node_lst: list, edge_lst: list, file_name: str = "workflow.json"
):
"""
Export the graph visualization of nodes and edges as a JSON dictionary.

Args:
node_lst (list): List of nodes.
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
pwd_nodes_lst.append(
{"id": n["id"], "type": n["type"], "value": n["value"]}
)
elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"].tolist(),
"name": n["name"],
}
)
else:
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"],
"name": n["name"],
}
)

final_node = {"id": len(pwd_nodes_lst), "type": "output", "name": "result"}
pwd_nodes_lst.append(final_node)
pwd_edges_lst = [
(
{
"target": e["end"],
"targetPort": e["label"],
"source": e["start"],
"sourcePort": None,
}
if "start_label" not in e
else {
"target": e["end"],
"targetPort": e["end_label"],
"source": e["start"],
"sourcePort": e["start_label"],
}
)
for e in edge_lst
]
pwd_edges_lst.append(
{
"target": final_node["id"],
"targetPort": None,
"source": max([e["target"] for e in pwd_edges_lst]),
"sourcePort": None,
}
)
Comment on lines +293 to +300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle empty edge list to prevent ValueError on max().

If edge_lst is empty, pwd_edges_lst will be empty, and max([e["target"] for e in pwd_edges_lst]) will raise ValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.

🔎 Proposed fix
- pwd_edges_lst.append(- {- "target": final_node["id"],- "targetPort": None,- "source": max([e["target"] for e in pwd_edges_lst]),- "sourcePort": None,- }- )+ if pwd_edges_lst:+ pwd_edges_lst.append(+ {+ "target": final_node["id"],+ "targetPort": None,+ "source": max(e["target"] for e in pwd_edges_lst),+ "sourcePort": None,+ }+ )
🤖 Prompt for AI Agents
In src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
293-300, the code calls max() on pwd_edges_lst which raises ValueError when
pwd_edges_lst is empty; update the logic to handle an empty list by computing
source only if pwd_edges_lst has elements (e.g., source = max(e["target"] for e
in pwd_edges_lst)), otherwise set source to a safe fallback (for example
final_node["id"] or None) or skip adding the edge entirely; implement a short
conditional that selects the fallback and then append the dict using that source
to avoid the max() on an empty sequence.

pwd_dict = {
"version": "0.1.0",
"nodes": pwd_nodes_lst,
"edges": pwd_edges_lst,
}
with open(file_name, "w") as f:
json.dump(pwd_dict, f, indent=4)
47 changes: 47 additions & 0 deletions tests/test_singlenodeexecutor_pwd.py
Original file line numberDiff line numberDiff 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)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length \u003e 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/executorlib/executor/flux.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ class FluxJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -105,6 +106,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -152,6 +154,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -189,6 +192,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -255,6 +259,7 @@ class FluxClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -293,6 +298,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -338,6 +344,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -420,6 +427,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ class SingleNodeExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -94,6 +95,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -138,6 +140,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -171,6 +174,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -226,6 +230,7 @@ class TestClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -262,6 +267,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -299,6 +305,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -358,6 +365,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ class SlurmClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -101,6 +102,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -146,6 +148,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -225,6 +228,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand DownExpand Up@@ -275,6 +279,7 @@ class SlurmJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -312,6 +317,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -360,6 +366,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -394,6 +401,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand Down
23 changes: 17 additions & 6 deletions src/executorlib/task_scheduler/interactive/dependency.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
)
from executorlib.task_scheduler.base import TaskSchedulerBase
from executorlib.task_scheduler.interactive.dependency_plot import (
export_dependency_graph_function,
generate_nodes_and_edges_for_plotting,
generate_task_hash_for_plotting,
plot_dependency_graph_function,
Expand All@@ -28,6 +29,7 @@ class DependencyTaskScheduler(TaskSchedulerBase):
refresh_rate (float, optional): The refresh rate for updating the executor queue. Defaults to 0.01.
plot_dependency_graph (bool, optional): Whether to generate and plot the dependency graph. Defaults to False.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.

Attributes:
_future_hash_dict (Dict[str, Future]): A dictionary mapping task hash to future object.
Expand All@@ -44,6 +46,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
) -> None:
super().__init__(max_cores=max_cores)
self._process_kwargs = {
Expand All@@ -61,7 +64,8 @@ def __init__(
self._future_hash_dict: dict = {}
self._task_hash_dict: dict = {}
self._plot_dependency_graph_filename = plot_dependency_graph_filename
if plot_dependency_graph_filename is None:
self._export_workflow_filename = export_workflow_filename
if plot_dependency_graph_filename is None and export_workflow_filename is None:
self._generate_dependency_graph = plot_dependency_graph
else:
self._generate_dependency_graph = True
Expand DownExpand Up@@ -209,11 +213,18 @@ def __exit__(
v: k for k, v in self._future_hash_dict.items()
},
)
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
if self._export_workflow_filename is not None:
return export_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
file_name=self._export_workflow_filename,
)
else:
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
else:
return None

Expand Down
75 changes: 75 additions & 0 deletions src/executorlib/task_scheduler/interactive/dependency_plot.py
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
import inspect
import json
import os.path
from concurrent.futures import Future
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand DownExpand Up@@ -230,3 +232,76 @@ def plot_dependency_graph_function(
from IPython.display import SVG, display # noqa

display(SVG(nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")))


def export_dependency_graph_function(
node_lst: list, edge_lst: list, file_name: str = "workflow.json"
):
"""
Export the graph visualization of nodes and edges as a JSON dictionary.

Args:
node_lst (list): List of nodes.
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
pwd_nodes_lst.append(
{"id": n["id"], "type": n["type"], "value": n["value"]}
)
elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"].tolist(),
"name": n["name"],
}
)
else:
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"],
"name": n["name"],
}
)

final_node = {"id": len(pwd_nodes_lst), "type": "output", "name": "result"}
pwd_nodes_lst.append(final_node)
pwd_edges_lst = [
(
{
"target": e["end"],
"targetPort": e["label"],
"source": e["start"],
"sourcePort": None,
}
if "start_label" not in e
else {
"target": e["end"],
"targetPort": e["end_label"],
"source": e["start"],
"sourcePort": e["start_label"],
}
)
for e in edge_lst
]
pwd_edges_lst.append(
{
"target": final_node["id"],
"targetPort": None,
"source": max([e["target"] for e in pwd_edges_lst]),
"sourcePort": None,
}
)
Comment on lines +293 to +300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle empty edge list to prevent ValueError on max().

If edge_lst is empty, pwd_edges_lst will be empty, and max([e["target"] for e in pwd_edges_lst]) will raise ValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.

🔎 Proposed fix
- pwd_edges_lst.append(- {- "target": final_node["id"],- "targetPort": None,- "source": max([e["target"] for e in pwd_edges_lst]),- "sourcePort": None,- }- )+ if pwd_edges_lst:+ pwd_edges_lst.append(+ {+ "target": final_node["id"],+ "targetPort": None,+ "source": max(e["target"] for e in pwd_edges_lst),+ "sourcePort": None,+ }+ )
🤖 Prompt for AI Agents
In src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
293-300, the code calls max() on pwd_edges_lst which raises ValueError when
pwd_edges_lst is empty; update the logic to handle an empty list by computing
source only if pwd_edges_lst has elements (e.g., source = max(e["target"] for e
in pwd_edges_lst)), otherwise set source to a safe fallback (for example
final_node["id"] or None) or skip adding the edge entirely; implement a short
conditional that selects the fallback and then append the dict using that source
to avoid the max() on an empty sequence.

pwd_dict = {
"version": "0.1.0",
"nodes": pwd_nodes_lst,
"edges": pwd_edges_lst,
}
with open(file_name, "w") as f:
json.dump(pwd_dict, f, indent=4)
47 changes: 47 additions & 0 deletions tests/test_singlenodeexecutor_pwd.py
Original file line numberDiff line numberDiff 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)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/executorlib/executor/flux.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ class FluxJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -105,6 +106,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -152,6 +154,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -189,6 +192,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -255,6 +259,7 @@ class FluxClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -293,6 +298,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -338,6 +344,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -420,6 +427,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ class SingleNodeExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -94,6 +95,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -138,6 +140,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -171,6 +174,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -226,6 +230,7 @@ class TestClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -262,6 +267,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -299,6 +305,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -358,6 +365,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ class SlurmClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -101,6 +102,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -146,6 +148,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -225,6 +228,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand DownExpand Up@@ -275,6 +279,7 @@ class SlurmJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -312,6 +317,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -360,6 +366,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -394,6 +401,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand Down
23 changes: 17 additions & 6 deletions src/executorlib/task_scheduler/interactive/dependency.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
)
from executorlib.task_scheduler.base import TaskSchedulerBase
from executorlib.task_scheduler.interactive.dependency_plot import (
export_dependency_graph_function,
generate_nodes_and_edges_for_plotting,
generate_task_hash_for_plotting,
plot_dependency_graph_function,
Expand All@@ -28,6 +29,7 @@ class DependencyTaskScheduler(TaskSchedulerBase):
refresh_rate (float, optional): The refresh rate for updating the executor queue. Defaults to 0.01.
plot_dependency_graph (bool, optional): Whether to generate and plot the dependency graph. Defaults to False.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.

Attributes:
_future_hash_dict (Dict[str, Future]): A dictionary mapping task hash to future object.
Expand All@@ -44,6 +46,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
) -> None:
super().__init__(max_cores=max_cores)
self._process_kwargs = {
Expand All@@ -61,7 +64,8 @@ def __init__(
self._future_hash_dict: dict = {}
self._task_hash_dict: dict = {}
self._plot_dependency_graph_filename = plot_dependency_graph_filename
if plot_dependency_graph_filename is None:
self._export_workflow_filename = export_workflow_filename
if plot_dependency_graph_filename is None and export_workflow_filename is None:
self._generate_dependency_graph = plot_dependency_graph
else:
self._generate_dependency_graph = True
Expand DownExpand Up@@ -209,11 +213,18 @@ def __exit__(
v: k for k, v in self._future_hash_dict.items()
},
)
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
if self._export_workflow_filename is not None:
return export_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
file_name=self._export_workflow_filename,
)
else:
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
else:
return None

Expand Down
75 changes: 75 additions & 0 deletions src/executorlib/task_scheduler/interactive/dependency_plot.py
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
import inspect
import json
import os.path
from concurrent.futures import Future
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand DownExpand Up@@ -230,3 +232,76 @@ def plot_dependency_graph_function(
from IPython.display import SVG, display # noqa

display(SVG(nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")))


def export_dependency_graph_function(
node_lst: list, edge_lst: list, file_name: str = "workflow.json"
):
"""
Export the graph visualization of nodes and edges as a JSON dictionary.

Args:
node_lst (list): List of nodes.
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
pwd_nodes_lst.append(
{"id": n["id"], "type": n["type"], "value": n["value"]}
)
elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"].tolist(),
"name": n["name"],
}
)
else:
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"],
"name": n["name"],
}
)

final_node = {"id": len(pwd_nodes_lst), "type": "output", "name": "result"}
pwd_nodes_lst.append(final_node)
pwd_edges_lst = [
(
{
"target": e["end"],
"targetPort": e["label"],
"source": e["start"],
"sourcePort": None,
}
if "start_label" not in e
else {
"target": e["end"],
"targetPort": e["end_label"],
"source": e["start"],
"sourcePort": e["start_label"],
}
)
for e in edge_lst
]
pwd_edges_lst.append(
{
"target": final_node["id"],
"targetPort": None,
"source": max([e["target"] for e in pwd_edges_lst]),
"sourcePort": None,
}
)
Comment on lines +293 to +300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle empty edge list to prevent ValueError on max().

If edge_lst is empty, pwd_edges_lst will be empty, and max([e["target"] for e in pwd_edges_lst]) will raise ValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.

🔎 Proposed fix
- pwd_edges_lst.append(- {- "target": final_node["id"],- "targetPort": None,- "source": max([e["target"] for e in pwd_edges_lst]),- "sourcePort": None,- }- )+ if pwd_edges_lst:+ pwd_edges_lst.append(+ {+ "target": final_node["id"],+ "targetPort": None,+ "source": max(e["target"] for e in pwd_edges_lst),+ "sourcePort": None,+ }+ )
🤖 Prompt for AI Agents
In src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
293-300, the code calls max() on pwd_edges_lst which raises ValueError when
pwd_edges_lst is empty; update the logic to handle an empty list by computing
source only if pwd_edges_lst has elements (e.g., source = max(e["target"] for e
in pwd_edges_lst)), otherwise set source to a safe fallback (for example
final_node["id"] or None) or skip adding the edge entirely; implement a short
conditional that selects the fallback and then append the dict using that source
to avoid the max() on an empty sequence.

pwd_dict = {
"version": "0.1.0",
"nodes": pwd_nodes_lst,
"edges": pwd_edges_lst,
}
with open(file_name, "w") as f:
json.dump(pwd_dict, f, indent=4)
47 changes: 47 additions & 0 deletions tests/test_singlenodeexecutor_pwd.py
Original file line numberDiff line numberDiff 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)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/executorlib/executor/flux.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ class FluxJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -105,6 +106,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -152,6 +154,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -189,6 +192,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -255,6 +259,7 @@ class FluxClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -293,6 +298,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -338,6 +344,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -420,6 +427,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ class SingleNodeExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -94,6 +95,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -138,6 +140,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -171,6 +174,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -226,6 +230,7 @@ class TestClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -262,6 +267,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -299,6 +305,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -358,6 +365,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ class SlurmClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -101,6 +102,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -146,6 +148,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -225,6 +228,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand DownExpand Up@@ -275,6 +279,7 @@ class SlurmJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -312,6 +317,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -360,6 +366,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -394,6 +401,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand Down
23 changes: 17 additions & 6 deletions src/executorlib/task_scheduler/interactive/dependency.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
)
from executorlib.task_scheduler.base import TaskSchedulerBase
from executorlib.task_scheduler.interactive.dependency_plot import (
export_dependency_graph_function,
generate_nodes_and_edges_for_plotting,
generate_task_hash_for_plotting,
plot_dependency_graph_function,
Expand All@@ -28,6 +29,7 @@ class DependencyTaskScheduler(TaskSchedulerBase):
refresh_rate (float, optional): The refresh rate for updating the executor queue. Defaults to 0.01.
plot_dependency_graph (bool, optional): Whether to generate and plot the dependency graph. Defaults to False.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.

Attributes:
_future_hash_dict (Dict[str, Future]): A dictionary mapping task hash to future object.
Expand All@@ -44,6 +46,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
) -> None:
super().__init__(max_cores=max_cores)
self._process_kwargs = {
Expand All@@ -61,7 +64,8 @@ def __init__(
self._future_hash_dict: dict = {}
self._task_hash_dict: dict = {}
self._plot_dependency_graph_filename = plot_dependency_graph_filename
if plot_dependency_graph_filename is None:
self._export_workflow_filename = export_workflow_filename
if plot_dependency_graph_filename is None and export_workflow_filename is None:
self._generate_dependency_graph = plot_dependency_graph
else:
self._generate_dependency_graph = True
Expand DownExpand Up@@ -209,11 +213,18 @@ def __exit__(
v: k for k, v in self._future_hash_dict.items()
},
)
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
if self._export_workflow_filename is not None:
return export_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
file_name=self._export_workflow_filename,
)
else:
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
else:
return None

Expand Down
75 changes: 75 additions & 0 deletions src/executorlib/task_scheduler/interactive/dependency_plot.py
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
import inspect
import json
import os.path
from concurrent.futures import Future
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand DownExpand Up@@ -230,3 +232,76 @@ def plot_dependency_graph_function(
from IPython.display import SVG, display # noqa

display(SVG(nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")))


def export_dependency_graph_function(
node_lst: list, edge_lst: list, file_name: str = "workflow.json"
):
"""
Export the graph visualization of nodes and edges as a JSON dictionary.

Args:
node_lst (list): List of nodes.
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
pwd_nodes_lst.append(
{"id": n["id"], "type": n["type"], "value": n["value"]}
)
elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"].tolist(),
"name": n["name"],
}
)
else:
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"],
"name": n["name"],
}
)

final_node = {"id": len(pwd_nodes_lst), "type": "output", "name": "result"}
pwd_nodes_lst.append(final_node)
pwd_edges_lst = [
(
{
"target": e["end"],
"targetPort": e["label"],
"source": e["start"],
"sourcePort": None,
}
if "start_label" not in e
else {
"target": e["end"],
"targetPort": e["end_label"],
"source": e["start"],
"sourcePort": e["start_label"],
}
)
for e in edge_lst
]
pwd_edges_lst.append(
{
"target": final_node["id"],
"targetPort": None,
"source": max([e["target"] for e in pwd_edges_lst]),
"sourcePort": None,
}
)
Comment on lines +293 to +300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle empty edge list to prevent ValueError on max().

If edge_lst is empty, pwd_edges_lst will be empty, and max([e["target"] for e in pwd_edges_lst]) will raise ValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.

🔎 Proposed fix
- pwd_edges_lst.append(- {- "target": final_node["id"],- "targetPort": None,- "source": max([e["target"] for e in pwd_edges_lst]),- "sourcePort": None,- }- )+ if pwd_edges_lst:+ pwd_edges_lst.append(+ {+ "target": final_node["id"],+ "targetPort": None,+ "source": max(e["target"] for e in pwd_edges_lst),+ "sourcePort": None,+ }+ )
🤖 Prompt for AI Agents
In src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
293-300, the code calls max() on pwd_edges_lst which raises ValueError when
pwd_edges_lst is empty; update the logic to handle an empty list by computing
source only if pwd_edges_lst has elements (e.g., source = max(e["target"] for e
in pwd_edges_lst)), otherwise set source to a safe fallback (for example
final_node["id"] or None) or skip adding the edge entirely; implement a short
conditional that selects the fallback and then append the dict using that source
to avoid the max() on an empty sequence.

pwd_dict = {
"version": "0.1.0",
"nodes": pwd_nodes_lst,
"edges": pwd_edges_lst,
}
with open(file_name, "w") as f:
json.dump(pwd_dict, f, indent=4)
47 changes: 47 additions & 0 deletions tests/test_singlenodeexecutor_pwd.py
Original file line numberDiff line numberDiff 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)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/executorlib/executor/flux.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ class FluxJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -105,6 +106,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -152,6 +154,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -189,6 +192,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -255,6 +259,7 @@ class FluxClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -293,6 +298,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -338,6 +344,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -420,6 +427,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ class SingleNodeExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -94,6 +95,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -138,6 +140,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -171,6 +174,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -226,6 +230,7 @@ class TestClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -262,6 +267,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -299,6 +305,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -358,6 +365,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ class SlurmClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -101,6 +102,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -146,6 +148,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -225,6 +228,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand DownExpand Up@@ -275,6 +279,7 @@ class SlurmJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -312,6 +317,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -360,6 +366,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -394,6 +401,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand Down
23 changes: 17 additions & 6 deletions src/executorlib/task_scheduler/interactive/dependency.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
)
from executorlib.task_scheduler.base import TaskSchedulerBase
from executorlib.task_scheduler.interactive.dependency_plot import (
export_dependency_graph_function,
generate_nodes_and_edges_for_plotting,
generate_task_hash_for_plotting,
plot_dependency_graph_function,
Expand All@@ -28,6 +29,7 @@ class DependencyTaskScheduler(TaskSchedulerBase):
refresh_rate (float, optional): The refresh rate for updating the executor queue. Defaults to 0.01.
plot_dependency_graph (bool, optional): Whether to generate and plot the dependency graph. Defaults to False.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.

Attributes:
_future_hash_dict (Dict[str, Future]): A dictionary mapping task hash to future object.
Expand All@@ -44,6 +46,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
) -> None:
super().__init__(max_cores=max_cores)
self._process_kwargs = {
Expand All@@ -61,7 +64,8 @@ def __init__(
self._future_hash_dict: dict = {}
self._task_hash_dict: dict = {}
self._plot_dependency_graph_filename = plot_dependency_graph_filename
if plot_dependency_graph_filename is None:
self._export_workflow_filename = export_workflow_filename
if plot_dependency_graph_filename is None and export_workflow_filename is None:
self._generate_dependency_graph = plot_dependency_graph
else:
self._generate_dependency_graph = True
Expand DownExpand Up@@ -209,11 +213,18 @@ def __exit__(
v: k for k, v in self._future_hash_dict.items()
},
)
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
if self._export_workflow_filename is not None:
return export_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
file_name=self._export_workflow_filename,
)
else:
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
else:
return None

Expand Down
75 changes: 75 additions & 0 deletions src/executorlib/task_scheduler/interactive/dependency_plot.py
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
import inspect
import json
import os.path
from concurrent.futures import Future
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand DownExpand Up@@ -230,3 +232,76 @@ def plot_dependency_graph_function(
from IPython.display import SVG, display # noqa

display(SVG(nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")))


def export_dependency_graph_function(
node_lst: list, edge_lst: list, file_name: str = "workflow.json"
):
"""
Export the graph visualization of nodes and edges as a JSON dictionary.

Args:
node_lst (list): List of nodes.
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
pwd_nodes_lst.append(
{"id": n["id"], "type": n["type"], "value": n["value"]}
)
elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"].tolist(),
"name": n["name"],
}
)
else:
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"],
"name": n["name"],
}
)

final_node = {"id": len(pwd_nodes_lst), "type": "output", "name": "result"}
pwd_nodes_lst.append(final_node)
pwd_edges_lst = [
(
{
"target": e["end"],
"targetPort": e["label"],
"source": e["start"],
"sourcePort": None,
}
if "start_label" not in e
else {
"target": e["end"],
"targetPort": e["end_label"],
"source": e["start"],
"sourcePort": e["start_label"],
}
)
for e in edge_lst
]
pwd_edges_lst.append(
{
"target": final_node["id"],
"targetPort": None,
"source": max([e["target"] for e in pwd_edges_lst]),
"sourcePort": None,
}
)
Comment on lines +293 to +300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle empty edge list to prevent ValueError on max().

If edge_lst is empty, pwd_edges_lst will be empty, and max([e["target"] for e in pwd_edges_lst]) will raise ValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.

🔎 Proposed fix
- pwd_edges_lst.append(- {- "target": final_node["id"],- "targetPort": None,- "source": max([e["target"] for e in pwd_edges_lst]),- "sourcePort": None,- }- )+ if pwd_edges_lst:+ pwd_edges_lst.append(+ {+ "target": final_node["id"],+ "targetPort": None,+ "source": max(e["target"] for e in pwd_edges_lst),+ "sourcePort": None,+ }+ )
🤖 Prompt for AI Agents
In src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
293-300, the code calls max() on pwd_edges_lst which raises ValueError when
pwd_edges_lst is empty; update the logic to handle an empty list by computing
source only if pwd_edges_lst has elements (e.g., source = max(e["target"] for e
in pwd_edges_lst)), otherwise set source to a safe fallback (for example
final_node["id"] or None) or skip adding the edge entirely; implement a short
conditional that selects the fallback and then append the dict using that source
to avoid the max() on an empty sequence.

pwd_dict = {
"version": "0.1.0",
"nodes": pwd_nodes_lst,
"edges": pwd_edges_lst,
}
with open(file_name, "w") as f:
json.dump(pwd_dict, f, indent=4)
47 changes: 47 additions & 0 deletions tests/test_singlenodeexecutor_pwd.py
Original file line numberDiff line numberDiff 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)
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions src/executorlib/executor/flux.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,6 +65,7 @@ class FluxJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -105,6 +106,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -152,6 +154,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -189,6 +192,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -255,6 +259,7 @@ class FluxClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -293,6 +298,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -338,6 +344,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -420,6 +427,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/single.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -58,6 +58,7 @@ class SingleNodeExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -94,6 +95,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -138,6 +140,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -171,6 +174,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand DownExpand Up@@ -226,6 +230,7 @@ class TestClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -262,6 +267,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -299,6 +305,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -358,6 +365,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand Down
8 changes: 8 additions & 0 deletions src/executorlib/executor/slurm.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,6 +63,7 @@ class SlurmClusterExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -101,6 +102,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -146,6 +148,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -225,6 +228,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)

Expand DownExpand Up@@ -275,6 +279,7 @@ class SlurmJobExecutor(BaseExecutor):
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

Examples:
Expand DownExpand Up@@ -312,6 +317,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
log_obj_size: bool = False,
):
"""
Expand DownExpand Up@@ -360,6 +366,7 @@ def __init__(
plot_dependency_graph (bool): Plot the dependencies of multiple future objects without executing them. For
debugging purposes and to get an overview of the specified dependencies.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.
log_obj_size (bool): Enable debug mode which reports the size of the communicated objects.

"""
Expand DownExpand Up@@ -394,6 +401,7 @@ def __init__(
refresh_rate=refresh_rate,
plot_dependency_graph=plot_dependency_graph,
plot_dependency_graph_filename=plot_dependency_graph_filename,
export_workflow_filename=export_workflow_filename,
)
)
else:
Expand Down
23 changes: 17 additions & 6 deletions src/executorlib/task_scheduler/interactive/dependency.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
)
from executorlib.task_scheduler.base import TaskSchedulerBase
from executorlib.task_scheduler.interactive.dependency_plot import (
export_dependency_graph_function,
generate_nodes_and_edges_for_plotting,
generate_task_hash_for_plotting,
plot_dependency_graph_function,
Expand All@@ -28,6 +29,7 @@ class DependencyTaskScheduler(TaskSchedulerBase):
refresh_rate (float, optional): The refresh rate for updating the executor queue. Defaults to 0.01.
plot_dependency_graph (bool, optional): Whether to generate and plot the dependency graph. Defaults to False.
plot_dependency_graph_filename (str): Name of the file to store the plotted graph in.
export_workflow_filename (str): Name of the file to store the exported workflow graph in.

Attributes:
_future_hash_dict (Dict[str, Future]): A dictionary mapping task hash to future object.
Expand All@@ -44,6 +46,7 @@ def __init__(
refresh_rate: float = 0.01,
plot_dependency_graph: bool = False,
plot_dependency_graph_filename: Optional[str] = None,
export_workflow_filename: Optional[str] = None,
) -> None:
super().__init__(max_cores=max_cores)
self._process_kwargs = {
Expand All@@ -61,7 +64,8 @@ def __init__(
self._future_hash_dict: dict = {}
self._task_hash_dict: dict = {}
self._plot_dependency_graph_filename = plot_dependency_graph_filename
if plot_dependency_graph_filename is None:
self._export_workflow_filename = export_workflow_filename
if plot_dependency_graph_filename is None and export_workflow_filename is None:
self._generate_dependency_graph = plot_dependency_graph
else:
self._generate_dependency_graph = True
Expand DownExpand Up@@ -209,11 +213,18 @@ def __exit__(
v: k for k, v in self._future_hash_dict.items()
},
)
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
if self._export_workflow_filename is not None:
return export_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
file_name=self._export_workflow_filename,
)
else:
return plot_dependency_graph_function(
node_lst=node_lst,
edge_lst=edge_lst,
filename=self._plot_dependency_graph_filename,
)
else:
return None

Expand Down
75 changes: 75 additions & 0 deletions src/executorlib/task_scheduler/interactive/dependency_plot.py
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
import inspect
import json
import os.path
from concurrent.futures import Future
from typing import Optional

import cloudpickle
import numpy as np

from executorlib.standalone.select import FutureSelector

Expand DownExpand Up@@ -230,3 +232,76 @@ def plot_dependency_graph_function(
from IPython.display import SVG, display # noqa

display(SVG(nx.nx_agraph.to_agraph(graph).draw(prog="dot", format="svg")))


def export_dependency_graph_function(
node_lst: list, edge_lst: list, file_name: str = "workflow.json"
):
"""
Export the graph visualization of nodes and edges as a JSON dictionary.

Args:
node_lst (list): List of nodes.
edge_lst (list): List of edges.
file_name (str): Name of the file to store the exported graph in.
"""
pwd_nodes_lst = []
for n in node_lst:
if n["type"] == "function":
pwd_nodes_lst.append(
{"id": n["id"], "type": n["type"], "value": n["value"]}
)
elif n["type"] == "input" and isinstance(n["value"], np.ndarray):
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"].tolist(),
"name": n["name"],
}
)
else:
pwd_nodes_lst.append(
{
"id": n["id"],
"type": n["type"],
"value": n["value"],
"name": n["name"],
}
)

final_node = {"id": len(pwd_nodes_lst), "type": "output", "name": "result"}
pwd_nodes_lst.append(final_node)
pwd_edges_lst = [
(
{
"target": e["end"],
"targetPort": e["label"],
"source": e["start"],
"sourcePort": None,
}
if "start_label" not in e
else {
"target": e["end"],
"targetPort": e["end_label"],
"source": e["start"],
"sourcePort": e["start_label"],
}
)
for e in edge_lst
]
pwd_edges_lst.append(
{
"target": final_node["id"],
"targetPort": None,
"source": max([e["target"] for e in pwd_edges_lst]),
"sourcePort": None,
}
)
Comment on lines +293 to +300

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Handle empty edge list to prevent ValueError on max().

If edge_lst is empty, pwd_edges_lst will be empty, and max([e["target"] for e in pwd_edges_lst]) will raise ValueError: max() arg is an empty sequence. This can occur with single-node workflows or graphs without edges.

🔎 Proposed fix
- pwd_edges_lst.append(- {- "target": final_node["id"],- "targetPort": None,- "source": max([e["target"] for e in pwd_edges_lst]),- "sourcePort": None,- }- )+ if pwd_edges_lst:+ pwd_edges_lst.append(+ {+ "target": final_node["id"],+ "targetPort": None,+ "source": max(e["target"] for e in pwd_edges_lst),+ "sourcePort": None,+ }+ )
🤖 Prompt for AI Agents
In src/executorlib/task_scheduler/interactive/dependency_plot.py around lines
293-300, the code calls max() on pwd_edges_lst which raises ValueError when
pwd_edges_lst is empty; update the logic to handle an empty list by computing
source only if pwd_edges_lst has elements (e.g., source = max(e["target"] for e
in pwd_edges_lst)), otherwise set source to a safe fallback (for example
final_node["id"] or None) or skip adding the edge entirely; implement a short
conditional that selects the fallback and then append the dict using that source
to avoid the max() on an empty sequence.

pwd_dict = {
"version": "0.1.0",
"nodes": pwd_nodes_lst,
"edges": pwd_edges_lst,
}
with open(file_name, "w") as f:
json.dump(pwd_dict, f, indent=4)
47 changes: 47 additions & 0 deletions tests/test_singlenodeexecutor_pwd.py
Original file line numberDiff line numberDiff 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)