Skip to content

Commit 421c416

Browse files
committed
renaming generator to wfgen
1 parent 6720425 commit 421c416

18 files changed

Lines changed: 478 additions & 781 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ jobs:
2323
- name: Check package install
2424
run: |
2525
pip install .
26+
- name: Build documentation
27+
run: |
28+
cd docs
29+
make html

docs/source/generating_workflows.rst

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,9 @@ workflow instances for every size defined in the array :code:`num_tasks`: ::
110110
for i, workflow in enumerate(workflows):
111111
workflow.write_json(f'blast-workflow-{task}-{i}.json')
112112

113-
114-
115-
116-
117-
Examples
118-
--------
119-
120113
The following example generates 10 *Epigenomics* synthetic workflow instances
121-
based on the number of tasks entered by the user (1000), builds the synthetic workflow instances, and writes the
122-
synthetic instances to JSON files. ::
114+
based on the number of tasks entered by the user (1000), builds the synthetic
115+
workflow instances, and writes the synthetic instances to JSON files. ::
123116

124117
from wfcommons.wfchef.recipes import EpigenomicsRecipe
125118
from wfcommons.generator import WorkflowGenerator
@@ -128,9 +121,9 @@ synthetic instances to JSON files. ::
128121
for i, workflow in enumerate(generator.build_workflows(10)):
129122
workflow.write_json(f'epigenomics-workflow-{i}.json')
130123

131-
The example below generates a *Cycles* (agroecosystem) synthetic workflow instance based on the number
132-
of tasks entered by the user (250), builds the synthetic workflow instance, and writes the synthetic
133-
instance to a JSON file. ::
124+
The example below generates a *Cycles* (agroecosystem) synthetic workflow instance
125+
based on the number of tasks entered by the user (250), builds the synthetic workflow
126+
instance, and writes the synthetic instance to a JSON file. ::
134127

135128
from wfcommons.wfchef.recipes import CyclesRecipe
136129
from wfcommons.generator import WorkflowGenerator
@@ -139,5 +132,3 @@ instance to a JSON file. ::
139132
workflow = generator.build_workflow()
140133
workflow.write_json(f'cycles-workflow.json')
141134

142-
..
143-
maybe we should pout examples only on generator, because we need it

wfcommons/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import logging
1818

19-
from .generator import WorkflowGenerator
19+
from .wfgen import WorkflowGenerator
2020
from .trace import Trace, TraceAnalyzer, TraceElement
2121

2222
logging.getLogger('wfcommons').addHandler(logging.NullHandler())

wfcommons/generator/workflow/__init__.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

wfcommons/wfchef/chef.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import traceback
2222

2323
from typing import Dict, Optional, Union
24-
from stringcase import snakecase, capitalcase
24+
from stringcase import capitalcase
2525

2626
from .duplicate import duplicate, NoMicrostructuresError
2727
from .find_microstructures import save_microstructures
2828
from .utils import create_graph
29-
from ..generator.workflow.abstract_recipe import WorkflowRecipe
29+
from ..wfgen.abstract_recipe import WorkflowRecipe
3030
from ..trace.trace import Trace
3131
from ..trace.trace_analyzer import TraceAnalyzer
3232

@@ -176,7 +176,6 @@ def ls_recipe():
176176
Inspired by UNIX `ls` command, it lists the recipes already installed into the system and
177177
how to import it to use.
178178
"""
179-
import inspect
180179
rows = []
181180
for entry_point in pkg_resources.iter_entry_points('workflow_recipes'):
182181
try:

wfcommons/wfchef/recipes/blast/recipe.py

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

11-
from typing import Dict, Optional, Set
12-
13-
from wfcommons.common.workflow import Workflow
11+
import json
12+
import pathlib
1413

15-
from wfcommons.generator.workflow.abstract_recipe import WorkflowRecipe
16-
from wfcommons.wfchef.duplicate import duplicate
14+
from logging import Logger
15+
from typing import Dict, Optional, Set
1716

18-
import pathlib
19-
import pickle
20-
import networkx as nx
21-
import numpy as np
22-
import pandas as pd
23-
import json
17+
from wfcommons.wfgen.abstract_recipe import WorkflowRecipe
2418

2519
this_dir = pathlib.Path(__file__).resolve().parent
2620

2721

2822
class BlastRecipe(WorkflowRecipe):
2923
"""A Blast workflow recipe class for creating synthetic workflow traces.
3024
31-
:param num_pairs: The number of pair of signals to estimate earthquake STFs.
32-
:type num_pairs: int
3325
:param data_footprint: The upper bound for the workflow total data footprint (in bytes).
3426
:type data_footprint: int
3527
:param num_tasks: The upper bound for the total number of tasks in the workflow.
3628
:type num_tasks: int
29+
:param exclude_graphs:
30+
:type exclude_graphs: Set
31+
:param runtime_factor: The factor of which tasks runtime will be increased/decreased.
32+
:type runtime_factor: float
33+
:param input_file_size_factor: The factor of which tasks input files size will be increased/decreased.
34+
:type input_file_size_factor: float
35+
:param output_file_size_factor: The factor of which tasks output files size will be increased/decreased.
36+
:type output_file_size_factor: float
37+
:param logger: The logger where to log information/warning or errors (optional).
38+
:type logger: Logger
3739
"""
3840

3941
def __init__(self,
4042
data_footprint: Optional[int] = 0,
4143
num_tasks: Optional[int] = 3,
4244
exclude_graphs: Set[str] = set(),
45+
runtime_factor: Optional[float] = 1.0,
46+
input_file_size_factor: Optional[float] = 1.0,
47+
output_file_size_factor: Optional[float] = 1.0,
48+
logger: Optional[Logger] = None,
4349
**kwargs) -> None:
44-
super().__init__("Blast", data_footprint, num_tasks)
45-
self.exclude_graphs = exclude_graphs
46-
47-
def generate_nx_graph(self) -> nx.DiGraph:
48-
summary_path = this_dir.joinpath("microstructures", "summary.json")
49-
summary = json.loads(summary_path.read_text())
50-
51-
metric_path = this_dir.joinpath("microstructures", "metric", "err.csv")
52-
df = pd.read_csv(str(metric_path), index_col=0)
53-
df = df.drop(self.exclude_graphs, axis=0, errors="ignore")
54-
df = df.drop(self.exclude_graphs, axis=1, errors="ignore")
55-
for col in df.columns:
56-
df.loc[col, col] = np.nan
57-
58-
reference_orders = [summary["base_graphs"][col]["order"] for col in df.columns]
59-
idx = np.argmin([abs(self.num_tasks - ref_num_tasks) for ref_num_tasks in reference_orders])
60-
reference = df.columns[idx]
61-
62-
base = df.index[df[reference].argmin()]
63-
graph = duplicate(this_dir.joinpath("microstructures"), base, self.num_tasks)
64-
return graph
50+
super().__init__("Blast", data_footprint, num_tasks, exclude_graphs, runtime_factor, input_file_size_factor,
51+
output_file_size_factor, logger, this_dir)
6552

6653
@classmethod
67-
def from_num_tasks(cls, num_tasks: int, exclude_graphs: Set[str] = set()) -> 'BlastRecipe':
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':
6861
"""
6962
Instantiate a Blast workflow recipe that will generate synthetic workflows up to
7063
the total number of tasks provided.
7164
7265
:param num_tasks: The upper bound for the total number of tasks in the workflow (at least 3).
7366
: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
7475
7576
:return: A Blast workflow recipe object that will generate synthetic workflows up
7677
to the total number of tasks provided.
7778
:rtype: BlastRecipe
7879
"""
79-
return BlastRecipe(num_tasks=num_tasks, exclude_graphs=exclude_graphs)
80-
81-
def _load_base_graph(self) -> nx.DiGraph:
82-
return pickle.loads(this_dir.joinpath("base_graph.pickle").read_bytes())
83-
84-
def _load_microstructures(self) -> Dict:
85-
return json.loads(this_dir.joinpath("microstructures.json").read_text())
86-
87-
def build_workflow(self, workflow_name: Optional[str] = None) -> Workflow:
88-
"""Generate a synthetic workflow trace of a Blast workflow.
89-
90-
:param workflow_name: The workflow name
91-
:type workflow_name: int
92-
93-
:return: A synthetic workflow trace object.
94-
:rtype: Workflow
95-
"""
96-
workflow = Workflow(name=self.name + "-synthetic-trace" if not workflow_name else workflow_name, makespan=None)
97-
graph = self.generate_nx_graph()
98-
99-
task_names = {}
100-
for node in graph.nodes:
101-
if node in ["SRC", "DST"]:
102-
continue
103-
node_type = graph.nodes[node]["type"]
104-
task_name = self._generate_task_name(node_type)
105-
task = self._generate_task(node_type, task_name)
106-
workflow.add_node(task_name, task=task)
107-
108-
task_names[node] = task_name
109-
110-
for (src, dst) in graph.edges:
111-
if src in ["SRC", "DST"] or dst in ["SRC", "DST"]:
112-
continue
113-
workflow.add_edge(task_names[src], task_names[dst])
114-
115-
workflow.nxgraph = graph
116-
self.workflows.append(workflow)
117-
return workflow
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)
11883

11984
def _workflow_recipe(self) -> Dict:
12085
"""

wfcommons/wfchef/recipes/bwa/recipe.py

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

11-
from typing import Dict, Optional, Set
12-
13-
from wfcommons.common.workflow import Workflow
11+
import json
12+
import pathlib
1413

15-
from wfcommons.generator.workflow.abstract_recipe import WorkflowRecipe
16-
from wfcommons.wfchef.duplicate import duplicate
14+
from logging import Logger
15+
from typing import Dict, Optional, Set
1716

18-
import pathlib
19-
import pickle
20-
import networkx as nx
21-
import numpy as np
22-
import pandas as pd
23-
import json
17+
from wfcommons.wfgen.abstract_recipe import WorkflowRecipe
2418

2519
this_dir = pathlib.Path(__file__).resolve().parent
2620

2721

2822
class BwaRecipe(WorkflowRecipe):
2923
"""A Bwa workflow recipe class for creating synthetic workflow traces.
3024
31-
:param num_pairs: The number of pair of signals to estimate earthquake STFs.
32-
:type num_pairs: int
3325
:param data_footprint: The upper bound for the workflow total data footprint (in bytes).
3426
:type data_footprint: int
3527
:param num_tasks: The upper bound for the total number of tasks in the workflow.
3628
:type num_tasks: int
29+
:param exclude_graphs:
30+
:type exclude_graphs: Set
31+
:param runtime_factor: The factor of which tasks runtime will be increased/decreased.
32+
:type runtime_factor: float
33+
:param input_file_size_factor: The factor of which tasks input files size will be increased/decreased.
34+
:type input_file_size_factor: float
35+
:param output_file_size_factor: The factor of which tasks output files size will be increased/decreased.
36+
:type output_file_size_factor: float
37+
:param logger: The logger where to log information/warning or errors (optional).
38+
:type logger: Logger
3739
"""
3840

3941
def __init__(self,
4042
data_footprint: Optional[int] = 0,
4143
num_tasks: Optional[int] = 3,
4244
exclude_graphs: Set[str] = set(),
45+
runtime_factor: Optional[float] = 1.0,
46+
input_file_size_factor: Optional[float] = 1.0,
47+
output_file_size_factor: Optional[float] = 1.0,
48+
logger: Optional[Logger] = None,
4349
**kwargs) -> None:
44-
super().__init__("Bwa", data_footprint, num_tasks)
45-
self.exclude_graphs = exclude_graphs
46-
47-
def generate_nx_graph(self) -> nx.DiGraph:
48-
summary_path = this_dir.joinpath("microstructures", "summary.json")
49-
summary = json.loads(summary_path.read_text())
50-
51-
metric_path = this_dir.joinpath("microstructures", "metric", "err.csv")
52-
df = pd.read_csv(str(metric_path), index_col=0)
53-
df = df.drop(self.exclude_graphs, axis=0, errors="ignore")
54-
df = df.drop(self.exclude_graphs, axis=1, errors="ignore")
55-
for col in df.columns:
56-
df.loc[col, col] = np.nan
57-
58-
reference_orders = [summary["base_graphs"][col]["order"] for col in df.columns]
59-
idx = np.argmin([abs(self.num_tasks - ref_num_tasks) for ref_num_tasks in reference_orders])
60-
reference = df.columns[idx]
61-
62-
base = df.index[df[reference].argmin()]
63-
graph = duplicate(this_dir.joinpath("microstructures"), base, self.num_tasks)
64-
return graph
50+
super().__init__("Bwa", data_footprint, num_tasks, exclude_graphs, runtime_factor, input_file_size_factor,
51+
output_file_size_factor, logger, this_dir)
6552

6653
@classmethod
67-
def from_num_tasks(cls, num_tasks: int, exclude_graphs: Set[str] = set()) -> 'BwaRecipe':
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':
6861
"""
6962
Instantiate a Bwa workflow recipe that will generate synthetic workflows up to
7063
the total number of tasks provided.
7164
7265
:param num_tasks: The upper bound for the total number of tasks in the workflow (at least 3).
7366
: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
7475
7576
:return: A Bwa workflow recipe object that will generate synthetic workflows up
7677
to the total number of tasks provided.
7778
:rtype: BwaRecipe
7879
"""
79-
return BwaRecipe(num_tasks=num_tasks, exclude_graphs=exclude_graphs)
80-
81-
def _load_base_graph(self) -> nx.DiGraph:
82-
return pickle.loads(this_dir.joinpath("base_graph.pickle").read_bytes())
83-
84-
def _load_microstructures(self) -> Dict:
85-
return json.loads(this_dir.joinpath("microstructures.json").read_text())
86-
87-
def build_workflow(self, workflow_name: Optional[str] = None) -> Workflow:
88-
"""Generate a synthetic workflow trace of a Bwa workflow.
89-
90-
:param workflow_name: The workflow name
91-
:type workflow_name: int
92-
93-
:return: A synthetic workflow trace object.
94-
:rtype: Workflow
95-
"""
96-
workflow = Workflow(name=self.name + "-synthetic-trace" if not workflow_name else workflow_name, makespan=None)
97-
graph = self.generate_nx_graph()
98-
99-
task_names = {}
100-
for node in graph.nodes:
101-
if node in ["SRC", "DST"]:
102-
continue
103-
node_type = graph.nodes[node]["type"]
104-
task_name = self._generate_task_name(node_type)
105-
task = self._generate_task(node_type, task_name)
106-
workflow.add_node(task_name, task=task)
107-
108-
task_names[node] = task_name
109-
110-
for (src, dst) in graph.edges:
111-
if src in ["SRC", "DST"] or dst in ["SRC", "DST"]:
112-
continue
113-
workflow.add_edge(task_names[src], task_names[dst])
114-
115-
workflow.nxgraph = graph
116-
self.workflows.append(workflow)
117-
return workflow
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)
11883

11984
def _workflow_recipe(self) -> Dict:
12085
"""

0 commit comments

Comments
 (0)