Skip to content

Commit 59536aa

Browse files
Updates wfchef abstract recipe interfaces
1 parent 5623be4 commit 59536aa

18 files changed

Lines changed: 827 additions & 640 deletions

File tree

wfcommons/wfchef/chef.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
# the Free Software Foundation, either version 3 of the License, or
99
# (at your option) any later version.
1010

11+
import pathlib
1112
import argparse
13+
from email.mime import base
1214
import json
13-
import math
14-
from modulefinder import Module
15-
from importlib_metadata import entry_points
15+
import traceback
16+
from typing import Dict, Optional, Union
17+
import argparse
1618
import networkx as nx
1719
import numpy as np
1820
import pandas as pd
@@ -21,16 +23,15 @@
2123
import pkg_resources
2224
import subprocess
2325
import traceback
24-
25-
from typing import Dict, List, Optional, Union
26+
from typing import Dict, Optional, Union
2627
from stringcase import capitalcase
27-
2828
from .duplicate import duplicate, NoMicrostructuresError
2929
from .find_microstructures import save_microstructures
3030
from .utils import create_graph
3131
from ..wfgen.abstract_recipe import WorkflowRecipe
3232
from ..wfinstances.instance import Instance
3333
from ..wfinstances.instance_analyzer import InstanceAnalyzer
34+
import math
3435

3536
this_dir = pathlib.Path(__file__).resolve().parent
3637
skeleton_path = this_dir.joinpath("skeletons")
@@ -172,8 +173,7 @@ def analyzer_summary(path_to_instances: pathlib.Path) -> Dict:
172173

173174
return stats_dict
174175

175-
def get_recipe(recipe: str) -> Module:
176-
modules = []
176+
def get_recipe(recipe: str) -> "Module":
177177
for entry_point in pkg_resources.iter_entry_points('workflow_recipes'):
178178
att = entry_point.attrs[0]
179179
if att == recipe:
@@ -219,7 +219,7 @@ def create_recipe(path_to_instances: Union[str, pathlib.Path],
219219
wf_name: str,
220220
cutoff: int = 4000,
221221
verbose: bool = False,
222-
runs: int = 1) -> WorkflowRecipe:
222+
runs: int = 1) -> "WorkflowRecipe":
223223
"""
224224
Creates a recipe for a workflow application by automatically replacing custom information
225225
from the recipe skeleton.
@@ -228,7 +228,7 @@ def create_recipe(path_to_instances: Union[str, pathlib.Path],
228228
:type path_to_instances: str or pathlib.Path
229229
:param savedir: path to save the recipe.
230230
:type savedir: pathlib.Path
231-
:param wf_name: name of the workflow apllication.
231+
:param wf_name: name of the workflow application.
232232
:type wf_name: str
233233
:param cutoff: when set, only consider instances of smaller or equal sizes.
234234
:type cutoff: int
@@ -252,8 +252,8 @@ def create_recipe(path_to_instances: Union[str, pathlib.Path],
252252
err_savepath = microstructures_path.joinpath("metric", "err.csv")
253253
err_savepath.parent.mkdir(exist_ok=True, parents=True)
254254
df = find_err(microstructures_path, runs=runs)
255-
256255
err_savepath.write_text(df.to_csv())
256+
257257
# Recipe
258258
with skeleton_path.joinpath("recipe.py").open() as fp:
259259
skeleton_str = fp.read()

wfcommons/wfchef/duplicate.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,10 @@
1212
import json
1313
import pickle
1414
import networkx as nx
15-
from typing import Set, Optional, List, Union, Dict
15+
from typing import Set, List, Union, Dict
1616
from uuid import uuid4
17-
1817
import numpy as np
19-
from .utils import draw
2018
import random
21-
import argparse
22-
import pandas as pd
23-
from functools import partial
2419

2520
this_dir = pathlib.Path(__file__).resolve().parent
2621

@@ -73,23 +68,24 @@ def duplicate(path: pathlib.Path,
7368
:param path: path to the summary JSON file.
7469
:type path: pathlib.Path.
7570
:param base: name (for samples available in WfCommons) or path to the specific
76-
graph to be used as base (if not set WfChef chooses the best fitting one).
71+
graph to be used as base (if not set WfChef chooses the best fitting one).
7772
:type base: str or pathlib.Path.
7873
:param num_nodes: total amount of nodes desired in the synthetic instance.
7974
:type num_nodes: int.
8075
81-
8276
:return: graph with the desired number of tasks.
8377
:rtype: networkX DiGraph.
8478
"""
8579
summary = json.loads(path.joinpath("summary.json").read_text())
80+
8681
if base:
8782
base_path = pathlib.Path(base)
8883
if not base_path.is_absolute():
8984
base_path = path.joinpath(base_path)
9085
else:
9186
base_path = path.joinpath(min(summary["base_graphs"].keys(), key=lambda k: summary["base_graphs"][k]["order"]))
92-
87+
88+
9389
graph = pickle.loads(base_path.joinpath("base_graph.pickle").read_bytes())
9490
if num_nodes < graph.order():
9591
raise ValueError(

wfcommons/wfchef/recipes/blast/recipe.py

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
# the Free Software Foundation, either version 3 of the License, or
99
# (at your option) any later version.
1010

11-
import json
1211
import pathlib
13-
1412
from logging import Logger
15-
from typing import Dict, Optional, Set
16-
17-
from wfcommons.wfgen.abstract_recipe import WorkflowRecipe
13+
from typing import Optional, Set
14+
import pathlib
15+
from wfcommons.wfchef.wfchef_abstract_recipe import BaseMethod, WfChefWorkflowRecipe
1816

1917
this_dir = pathlib.Path(__file__).resolve().parent
2018

2119

22-
class BlastRecipe(WorkflowRecipe):
20+
class BlastRecipe(WfChefWorkflowRecipe):
2321
"""A Blast workflow recipe class for creating synthetic workflow instances.
2422
2523
:param data_footprint: The upper bound for the workflow total data footprint (in bytes).
@@ -46,47 +44,18 @@ def __init__(self,
4644
input_file_size_factor: Optional[float] = 1.0,
4745
output_file_size_factor: Optional[float] = 1.0,
4846
logger: Optional[Logger] = None,
47+
base_method: BaseMethod = BaseMethod.ERROR_TABLE,
4948
**kwargs) -> None:
50-
super().__init__("Blast", data_footprint, num_tasks, exclude_graphs, runtime_factor, input_file_size_factor,
51-
output_file_size_factor, logger, this_dir)
52-
53-
@classmethod
54-
def from_num_tasks(cls,
55-
num_tasks: int,
56-
exclude_graphs: Set[str] = set(),
57-
runtime_factor: Optional[float] = 1.0,
58-
input_file_size_factor: Optional[float] = 1.0,
59-
output_file_size_factor: Optional[float] = 1.0
60-
) -> 'BlastRecipe':
61-
"""
62-
Instantiate a Blast workflow recipe that will generate synthetic workflows up to
63-
the total number of tasks provided.
64-
65-
:param num_tasks: The upper bound for the total number of tasks in the workflow (at least 3).
66-
:type num_tasks: int
67-
:param exclude_graphs:
68-
:type exclude_graphs: Set
69-
:param runtime_factor: The factor of which tasks runtime will be increased/decreased.
70-
:type runtime_factor: float
71-
:param input_file_size_factor: The factor of which tasks input files size will be increased/decreased.
72-
:type input_file_size_factor: float
73-
:param output_file_size_factor: The factor of which tasks output files size will be increased/decreased.
74-
:type output_file_size_factor: float
75-
76-
:return: A Blast workflow recipe object that will generate synthetic workflows up
77-
to the total number of tasks provided.
78-
:rtype: BlastRecipe
79-
"""
80-
return BlastRecipe(num_tasks=num_tasks, exclude_graphs=exclude_graphs, runtime_factor=runtime_factor,
81-
input_file_size_factor=input_file_size_factor,
82-
output_file_size_factor=output_file_size_factor)
83-
84-
def _workflow_recipe(self) -> Dict:
85-
"""
86-
Recipe for generating synthetic instances of the Blast workflow. Recipes can be
87-
generated by using the :class:`~wfcommons.wfinstances.instance_analyzer.InstanceAnalyzer`.
88-
89-
:return: A recipe in the form of a dictionary in which keys are task prefixes.
90-
:rtype: Dict[str, Any]
91-
"""
92-
return json.loads(this_dir.joinpath("task_type_stats.json").read_text())
49+
super().__init__(
50+
name="Blast",
51+
data_footprint=data_footprint,
52+
num_tasks=num_tasks,
53+
exclude_graphs=exclude_graphs,
54+
runtime_factor=runtime_factor,
55+
input_file_size_factor=input_file_size_factor,
56+
output_file_size_factor=output_file_size_factor,
57+
logger=logger,
58+
this_dir=this_dir,
59+
base_method=base_method,
60+
**kwargs
61+
)

wfcommons/wfchef/recipes/bwa/recipe.py

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
# the Free Software Foundation, either version 3 of the License, or
99
# (at your option) any later version.
1010

11-
import json
1211
import pathlib
13-
1412
from logging import Logger
15-
from typing import Dict, Optional, Set
16-
17-
from wfcommons.wfgen.abstract_recipe import WorkflowRecipe
13+
from typing import Optional, Set
14+
import pathlib
15+
from wfcommons.wfchef.wfchef_abstract_recipe import BaseMethod, WfChefWorkflowRecipe
1816

1917
this_dir = pathlib.Path(__file__).resolve().parent
2018

2119

22-
class BwaRecipe(WorkflowRecipe):
20+
class BwaRecipe(WfChefWorkflowRecipe):
2321
"""A Bwa workflow recipe class for creating synthetic workflow instances.
2422
2523
:param data_footprint: The upper bound for the workflow total data footprint (in bytes).
@@ -46,47 +44,18 @@ def __init__(self,
4644
input_file_size_factor: Optional[float] = 1.0,
4745
output_file_size_factor: Optional[float] = 1.0,
4846
logger: Optional[Logger] = None,
47+
base_method: BaseMethod = BaseMethod.ERROR_TABLE,
4948
**kwargs) -> None:
50-
super().__init__("Bwa", data_footprint, num_tasks, exclude_graphs, runtime_factor, input_file_size_factor,
51-
output_file_size_factor, logger, this_dir)
52-
53-
@classmethod
54-
def from_num_tasks(cls,
55-
num_tasks: int,
56-
exclude_graphs: Set[str] = set(),
57-
runtime_factor: Optional[float] = 1.0,
58-
input_file_size_factor: Optional[float] = 1.0,
59-
output_file_size_factor: Optional[float] = 1.0
60-
) -> 'BwaRecipe':
61-
"""
62-
Instantiate a Bwa workflow recipe that will generate synthetic workflows up to
63-
the total number of tasks provided.
64-
65-
:param num_tasks: The upper bound for the total number of tasks in the workflow (at least 3).
66-
:type num_tasks: int
67-
:param exclude_graphs:
68-
:type exclude_graphs: Set
69-
:param runtime_factor: The factor of which tasks runtime will be increased/decreased.
70-
:type runtime_factor: float
71-
:param input_file_size_factor: The factor of which tasks input files size will be increased/decreased.
72-
:type input_file_size_factor: float
73-
:param output_file_size_factor: The factor of which tasks output files size will be increased/decreased.
74-
:type output_file_size_factor: float
75-
76-
:return: A Bwa workflow recipe object that will generate synthetic workflows up
77-
to the total number of tasks provided.
78-
:rtype: BwaRecipe
79-
"""
80-
return BwaRecipe(num_tasks=num_tasks, exclude_graphs=exclude_graphs, runtime_factor=runtime_factor,
81-
input_file_size_factor=input_file_size_factor,
82-
output_file_size_factor=output_file_size_factor)
83-
84-
def _workflow_recipe(self) -> Dict:
85-
"""
86-
Recipe for generating synthetic instances of the Bwa workflow. Recipes can be
87-
generated by using the :class:`~wfcommons.wfinstances.instance_analyzer.InstanceAnalyzer`.
88-
89-
:return: A recipe in the form of a dictionary in which keys are task prefixes.
90-
:rtype: Dict[str, Any]
91-
"""
92-
return json.loads(this_dir.joinpath("task_type_stats.json").read_text())
49+
super().__init__(
50+
name="Bwa",
51+
data_footprint=data_footprint,
52+
num_tasks=num_tasks,
53+
exclude_graphs=exclude_graphs,
54+
runtime_factor=runtime_factor,
55+
input_file_size_factor=input_file_size_factor,
56+
output_file_size_factor=output_file_size_factor,
57+
logger=logger,
58+
this_dir=this_dir,
59+
base_method=base_method,
60+
**kwargs
61+
)

wfcommons/wfchef/recipes/cycles/recipe.py

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
# the Free Software Foundation, either version 3 of the License, or
99
# (at your option) any later version.
1010

11-
import json
1211
import pathlib
13-
1412
from logging import Logger
15-
from typing import Dict, Optional, Set
16-
17-
from wfcommons.wfgen.abstract_recipe import WorkflowRecipe
13+
from typing import Optional, Set
14+
import pathlib
15+
from wfcommons.wfchef.wfchef_abstract_recipe import BaseMethod, WfChefWorkflowRecipe
1816

1917
this_dir = pathlib.Path(__file__).resolve().parent
2018

2119

22-
class CyclesRecipe(WorkflowRecipe):
20+
class CyclesRecipe(WfChefWorkflowRecipe):
2321
"""A Cycles workflow recipe class for creating synthetic workflow instances.
2422
2523
:param data_footprint: The upper bound for the workflow total data footprint (in bytes).
@@ -46,47 +44,18 @@ def __init__(self,
4644
input_file_size_factor: Optional[float] = 1.0,
4745
output_file_size_factor: Optional[float] = 1.0,
4846
logger: Optional[Logger] = None,
47+
base_method: BaseMethod = BaseMethod.ERROR_TABLE,
4948
**kwargs) -> None:
50-
super().__init__("Cycles", data_footprint, num_tasks, exclude_graphs, runtime_factor, input_file_size_factor,
51-
output_file_size_factor, logger, this_dir)
52-
53-
@classmethod
54-
def from_num_tasks(cls,
55-
num_tasks: int,
56-
exclude_graphs: Set[str] = set(),
57-
runtime_factor: Optional[float] = 1.0,
58-
input_file_size_factor: Optional[float] = 1.0,
59-
output_file_size_factor: Optional[float] = 1.0
60-
) -> 'CyclesRecipe':
61-
"""
62-
Instantiate a Cycles workflow recipe that will generate synthetic workflows up to
63-
the total number of tasks provided.
64-
65-
:param num_tasks: The upper bound for the total number of tasks in the workflow (at least 3).
66-
:type num_tasks: int
67-
:param exclude_graphs:
68-
:type exclude_graphs: Set
69-
:param runtime_factor: The factor of which tasks runtime will be increased/decreased.
70-
:type runtime_factor: float
71-
:param input_file_size_factor: The factor of which tasks input files size will be increased/decreased.
72-
:type input_file_size_factor: float
73-
:param output_file_size_factor: The factor of which tasks output files size will be increased/decreased.
74-
:type output_file_size_factor: float
75-
76-
:return: A Cycles workflow recipe object that will generate synthetic workflows up
77-
to the total number of tasks provided.
78-
:rtype: CyclesRecipe
79-
"""
80-
return CyclesRecipe(num_tasks=num_tasks, exclude_graphs=exclude_graphs, runtime_factor=runtime_factor,
81-
input_file_size_factor=input_file_size_factor,
82-
output_file_size_factor=output_file_size_factor)
83-
84-
def _workflow_recipe(self) -> Dict:
85-
"""
86-
Recipe for generating synthetic instances of the Cycles workflow. Recipes can be
87-
generated by using the :class:`~wfcommons.wfinstances.instance_analyzer.InstanceAnalyzer`.
88-
89-
:return: A recipe in the form of a dictionary in which keys are task prefixes.
90-
:rtype: Dict[str, Any]
91-
"""
92-
return json.loads(this_dir.joinpath("task_type_stats.json").read_text())
49+
super().__init__(
50+
name="Cycles",
51+
data_footprint=data_footprint,
52+
num_tasks=num_tasks,
53+
exclude_graphs=exclude_graphs,
54+
runtime_factor=runtime_factor,
55+
input_file_size_factor=input_file_size_factor,
56+
output_file_size_factor=output_file_size_factor,
57+
logger=logger,
58+
this_dir=this_dir,
59+
base_method=base_method,
60+
**kwargs
61+
)

0 commit comments

Comments
 (0)