88# the Free Software Foundation, either version 3 of the License, or
99# (at your option) any later version.
1010
11- import pathlib
12- import argparse
13- from email .mime import base
1411import json
15- import traceback
16- from typing import Dict , Optional , Union
1712import argparse
13+ import math
1814import networkx as nx
1915import numpy as np
2016import pandas as pd
2319import pkg_resources
2420import subprocess
2521import traceback
22+
2623from typing import Dict , Optional , Union
2724from stringcase import capitalcase
25+
2826from .duplicate import duplicate , NoMicrostructuresError
2927from .find_microstructures import save_microstructures
3028from .utils import create_graph
31- from ..wfgen .abstract_recipe import WorkflowRecipe
3229from ..wfinstances .instance import Instance
3330from ..wfinstances .instance_analyzer import InstanceAnalyzer
34- import math
3531
3632this_dir = pathlib .Path (__file__ ).resolve ().parent
3733skeleton_path = this_dir .joinpath ("skeletons" )
3834
3935
40- def compare_rmse (synth_graph : nx .DiGraph , real_graph : nx .DiGraph ):
36+ def compare_rmse (synth_graph : nx .DiGraph , real_graph : nx .DiGraph ) -> float :
4137 """
42- Calculates the Root Mean Square Error of a synthetic instance created
38+ Calculate the Root Mean Square Error of a synthetic instance created
4339 based on the correspondent (in number of tasks) real-world sample.
4440
4541 :param synth_graph: a synthetic instance created by WfCommons.
46- :type synth_graph: networkX DiGraph
42+ :type synth_graph: networkX. DiGraph
4743 :param real_graph: the correspondent (in number of tasks) real-world workflow instance.
48- :type real_graph: networkX DiGraph
44+ :type real_graph: networkX. DiGraph
4945
5046 :return: The RMSE between the synthetic instance and the real instance.
5147 :rtype: float
@@ -72,10 +68,10 @@ def compare_rmse(synth_graph: nx.DiGraph, real_graph: nx.DiGraph):
7268 return mse / real_graph .order ()
7369
7470
75- def find_err (workflow : Union [ str , pathlib .Path ] ,
76- err_savepath : Optional [Union [ str , pathlib .Path ] ] = None ,
77- always_update : bool = False ,
78- runs : int = 1 ) -> pd .DataFrame :
71+ def find_err (workflow : pathlib .Path ,
72+ err_savepath : Optional [pathlib .Path ] = None ,
73+ always_update : Optional [ bool ] = False ,
74+ runs : Optional [ int ] = 1 ) -> pd .DataFrame :
7975 """
8076 Creates a dataframe with the Root Mean Square Error of the synthetic instances created
8177 based on the correspondent, w.r.t. number of tasks, real-world samples available at
@@ -84,13 +80,13 @@ def find_err(workflow: Union[str, pathlib.Path],
8480 repositories.
8581
8682 :param workflow: name (for samples available in WfCommons) or path to the real workflow instances.
87- :type workflow: str or pathlib.Path
83+ :type workflow: pathlib.Path
8884 :param err_savepath: path to save the err (rmse) of all instances available into a csv.
89- :type real_graph: str or pathlib.Path
85+ :type real_graph: Optional[ pathlib.Path]
9086 :param always_update: flag to set if the err needs to be updated or not (True: if new instances are added, False: otherwise).
91- :type real_graph: bool
87+ :type real_graph: Optional[ bool]
9288 :param runs: number of times to repeat the err calculation process (due to randomization).
93- :type runs: bool
89+ :type runs: Optional[ bool]
9490
9591 :return: dataframe with RMSE of all available instances.
9692 :rtype: pd.DataFrame
@@ -100,7 +96,6 @@ def find_err(workflow: Union[str, pathlib.Path],
10096 key = lambda name : summary ["base_graphs" ][name ]["order" ])
10197
10298 if err_savepath :
103- err_savepath = pathlib .Path (err_savepath )
10499 err_savepath .parent .mkdir (exist_ok = True , parents = True )
105100
106101 labels = [graph for graph in sorted_graphs ]
@@ -147,17 +142,11 @@ def analyzer_summary(path_to_instances: pathlib.Path) -> Dict:
147142 and from Makeflow WMS GitHub <https://github.com/wfcommons/makeflow-instances>`_
148143 repositories.
149144
150- :param workflow: name (for samples available in WfCommons) or path to the real workflow instances.
151- :type workflow: str or pathlib.Path
152- :param err_savepath: path to save the err (rmse) of all instances available into a csv.
153- :type real_graph: str or pathlib.Path
154- :param always_update: flag to set if the err needs to be updated or not (True: if new instances are added, False: otherwise).
155- :type real_graph: bool
156- :param runs: number of times to repeat the err calculation process (due to randomization).
157- :type runs:bool
145+ :param path_to_instances:
146+ :type path_to_instances: pathlib.Path
158147
159- :return: dataframe with RMSE of all available instances.
160- :rtype: pd.DataFrame
148+ :return:
149+ :rtype: Dict
161150 """
162151 analyzer = InstanceAnalyzer ()
163152 task_types = set ()
@@ -173,12 +162,14 @@ def analyzer_summary(path_to_instances: pathlib.Path) -> Dict:
173162
174163 return stats_dict
175164
165+
176166def get_recipe (recipe : str ) -> "Module" :
177167 for entry_point in pkg_resources .iter_entry_points ('workflow_recipes' ):
178- att = entry_point .attrs [0 ]
168+ att = entry_point .attrs [0 ]
179169 if att == recipe :
180170 return entry_point .load ()
181171
172+
182173def get_recipes () -> pd .DataFrame :
183174 rows = []
184175 for entry_point in pkg_resources .iter_entry_points ('workflow_recipes' ):
@@ -191,6 +182,7 @@ def get_recipes() -> pd.DataFrame:
191182 print (f"Could not load { entry_point .module_name } " )
192183 return pd .DataFrame (rows , columns = ["name" , "module" , "import command" ])
193184
185+
194186def ls_recipe ():
195187 """
196188 Inspired by UNIX `ls` command, it lists the recipes already installed into the system and
@@ -219,7 +211,7 @@ def create_recipe(path_to_instances: Union[str, pathlib.Path],
219211 wf_name : str ,
220212 cutoff : int = 4000 ,
221213 verbose : bool = False ,
222- runs : int = 1 ) -> "WorkflowRecipe" :
214+ runs : int = 1 ):
223215 """
224216 Creates a recipe for a workflow application by automatically replacing custom information
225217 from the recipe skeleton.
@@ -253,7 +245,7 @@ def create_recipe(path_to_instances: Union[str, pathlib.Path],
253245 err_savepath .parent .mkdir (exist_ok = True , parents = True )
254246 df = find_err (microstructures_path , runs = runs )
255247 err_savepath .write_text (df .to_csv ())
256-
248+
257249 # Recipe
258250 with skeleton_path .joinpath ("recipe.py" ).open () as fp :
259251 skeleton_str = fp .read ()
0 commit comments