Skip to content

Commit 22408e9

Browse files
committed
Fixed bugs in dot-file handling in the Workflow class
Added testing
1 parent dbfe032 commit 22408e9

File tree

14 files changed

+51
-12
lines changed

14 files changed

+51
-12
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jobs:
2727
run: |
2828
sudo apt-get update
2929
sudo apt-get install stress-ng
30+
sudo apt-get install graphviz libgraphviz-dev
3031
pip install docker
32+
pip install graphviz
3133
3234
- name: Check package install
3335
run: |

tests/unit/common/test_workflow.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,37 @@ def test_workflow_json_generation(self):
140140
# Compare the two jsons!
141141
assert(original_json == written_json)
142142

143+
@pytest.mark.unit
144+
def test_workflow_dot_file(self):
145+
146+
# Put a JSON file in /tmp
147+
url = "https://raw.githubusercontent.com/wfcommons/WfInstances/refs/heads/main/makeflow/blast/blast-chameleon-small-001.json"
148+
response = requests.get(url)
149+
local_file_name = url.split("/")[-1]
150+
with open("/tmp/" + local_file_name, 'wb') as f:
151+
f.write(response.content)
152+
153+
# Create an instance from the JSON File and write it back to a JSON
154+
instance = Instance(pathlib.Path("/tmp") / local_file_name)
143155

156+
# Capture some metrics
157+
num_tasks = len(instance.workflow.tasks)
158+
num_dependencies = len(instance.workflow.edges)
159+
160+
# # Create a dot file
161+
dot_path = pathlib.Path("/tmp/written_workflow.dot")
162+
instance.workflow.write_dot(dot_path)
163+
assert dot_path.exists()
164+
with open(str(dot_path), "r", encoding="utf-8") as f:
165+
content = f.read()
166+
assert(num_tasks == content.count("label") - 1) # Extra "label" in file for \N
167+
assert(num_dependencies == content.count("->")) # Extra "label" in file for \N
168+
169+
# Read it back
170+
instance.workflow.read_dot(dot_path)
171+
assert(num_tasks == len(instance.workflow.tasks))
172+
assert(num_tasks == len(instance.workflow.nodes))
173+
assert(num_dependencies == len(instance.workflow.edges))
144174

145175

146176

wfcommons/common/workflow.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,14 @@ def read_dot(self, dot_file_path: Optional[pathlib.Path] = None) -> None:
236236
raise ModuleNotFoundError(
237237
f"\'pydot\' package not found: call to {type(self).__name__}.read_dot() failed.")
238238

239-
graph = nx.drawing.nx_pydot.read_dot(dot_file_path)
239+
# graph = nx.drawing.nx_pydot.read_dot(str(dot_file_path))
240+
graph = nx.nx_agraph.read_dot(str(dot_file_path))
241+
242+
# clear everything
243+
self.tasks.clear()
244+
self.tasks_parents.clear()
245+
self.tasks_children.clear()
246+
self.clear()
240247

241248
tasks_map = {}
242249
for node in graph.nodes(data=True):

wfcommons/wfchef/recipes/blast/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BlastRecipe(WfChefWorkflowRecipe):
3939
def __init__(self,
4040
data_footprint: Optional[int] = 0,
4141
num_tasks: Optional[int] = 3,
42-
exclude_graphs: Set[str] = None,
42+
exclude_graphs: Set[str]|None = None,
4343
runtime_factor: Optional[float] = 1.0,
4444
input_file_size_factor: Optional[float] = 1.0,
4545
output_file_size_factor: Optional[float] = 1.0,

wfcommons/wfchef/recipes/bwa/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class BwaRecipe(WfChefWorkflowRecipe):
3939
def __init__(self,
4040
data_footprint: Optional[int] = 0,
4141
num_tasks: Optional[int] = 3,
42-
exclude_graphs: Set[str] = None,
42+
exclude_graphs: Set[str]|None = None,
4343
runtime_factor: Optional[float] = 1.0,
4444
input_file_size_factor: Optional[float] = 1.0,
4545
output_file_size_factor: Optional[float] = 1.0,

wfcommons/wfchef/recipes/cycles/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CyclesRecipe(WfChefWorkflowRecipe):
3939
def __init__(self,
4040
data_footprint: Optional[int] = 0,
4141
num_tasks: Optional[int] = 3,
42-
exclude_graphs: Set[str] = None,
42+
exclude_graphs: Set[str]|None = None,
4343
runtime_factor: Optional[float] = 1.0,
4444
input_file_size_factor: Optional[float] = 1.0,
4545
output_file_size_factor: Optional[float] = 1.0,

wfcommons/wfchef/recipes/epigenomics/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class EpigenomicsRecipe(WfChefWorkflowRecipe):
3939
def __init__(self,
4040
data_footprint: Optional[int] = 0,
4141
num_tasks: Optional[int] = 3,
42-
exclude_graphs: Set[str] = None,
42+
exclude_graphs: Set[str]|None = None,
4343
runtime_factor: Optional[float] = 1.0,
4444
input_file_size_factor: Optional[float] = 1.0,
4545
output_file_size_factor: Optional[float] = 1.0,

wfcommons/wfchef/recipes/genome/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class GenomeRecipe(WfChefWorkflowRecipe):
3939
def __init__(self,
4040
data_footprint: Optional[int] = 0,
4141
num_tasks: Optional[int] = 3,
42-
exclude_graphs: Set[str] = None,
42+
exclude_graphs: Set[str]|None = None,
4343
runtime_factor: Optional[float] = 1.0,
4444
input_file_size_factor: Optional[float] = 1.0,
4545
output_file_size_factor: Optional[float] = 1.0,

wfcommons/wfchef/recipes/montage/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class MontageRecipe(WfChefWorkflowRecipe):
3939
def __init__(self,
4040
data_footprint: Optional[int] = 0,
4141
num_tasks: Optional[int] = 3,
42-
exclude_graphs: Set[str] = None,
42+
exclude_graphs: Set[str]|None = None,
4343
runtime_factor: Optional[float] = 1.0,
4444
input_file_size_factor: Optional[float] = 1.0,
4545
output_file_size_factor: Optional[float] = 1.0,

wfcommons/wfchef/recipes/rnaseq/recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class RnaseqRecipe(WfChefWorkflowRecipe):
3939
def __init__(self,
4040
data_footprint: Optional[int] = 0,
4141
num_tasks: Optional[int] = 3,
42-
exclude_graphs: Set[str] = None,
42+
exclude_graphs: Set[str]|None = None,
4343
runtime_factor: Optional[float] = 1.0,
4444
input_file_size_factor: Optional[float] = 1.0,
4545
output_file_size_factor: Optional[float] = 1.0,

0 commit comments

Comments
 (0)