Spaces:
Running
Running
Aryasomayajula, Sai Anirudh [External]
commited on
Commit
·
c31e194
1
Parent(s):
7c0e6e8
removes storage of 'self.params' and renames self.params to 'generator_params'
Browse files- gedi/generator.py +15 -13
gedi/generator.py
CHANGED
@@ -25,6 +25,7 @@ from gedi.utils.param_keys.generator import GENERATOR_PARAMS, EXPERIMENT, CONFIG
|
|
25 |
import xml.etree.ElementTree as ET
|
26 |
import re
|
27 |
from xml.dom import minidom
|
|
|
28 |
|
29 |
"""
|
30 |
Parameters
|
@@ -153,8 +154,8 @@ class GenerateEventLogs():
|
|
153 |
self.log_config = pd.read_csv(self.output_path)
|
154 |
return
|
155 |
|
156 |
-
|
157 |
-
experiment =
|
158 |
|
159 |
if experiment is not None:
|
160 |
tasks, output_path = get_tasks(experiment, self.output_path)
|
@@ -169,7 +170,8 @@ class GenerateEventLogs():
|
|
169 |
with multiprocessing.Pool(num_cores) as p:
|
170 |
print(f"INFO: Generator starting at {start.strftime('%H:%M:%S')} using {num_cores} cores for {len(tasks)} tasks...")
|
171 |
random.seed(RANDOM_SEED)
|
172 |
-
|
|
|
173 |
# TODO: Split log and metafeatures into separate object attributes
|
174 |
# TODO: Access not storing log in memory
|
175 |
# TODO: identify why log is needed in self.log_config
|
@@ -181,12 +183,12 @@ class GenerateEventLogs():
|
|
181 |
|
182 |
else:
|
183 |
random.seed(RANDOM_SEED)
|
184 |
-
configs = self.optimize()
|
185 |
if type(configs) is not list:
|
186 |
configs = [configs]
|
187 |
temp = self.generate_optimized_log(configs[0])
|
188 |
self.log_config = [temp['metafeatures']] if 'metafeatures' in temp else []
|
189 |
-
save_path = get_output_key_value_location(
|
190 |
self.output_path, "genEL")+".xes"
|
191 |
write_xes(temp['log'], save_path)
|
192 |
add_extension_before_traces(save_path)
|
@@ -200,12 +202,12 @@ class GenerateEventLogs():
|
|
200 |
print("Clearing parameters...")
|
201 |
self.log_config = None
|
202 |
# self.configs = None
|
203 |
-
self.params = None
|
204 |
self.output_path = None
|
205 |
self.feature_keys = None
|
206 |
|
207 |
|
208 |
-
def generator_wrapper(self, task):
|
209 |
try:
|
210 |
identifier = [x for x in task[1] if isinstance(x, str)][0]
|
211 |
except IndexError:
|
@@ -215,7 +217,7 @@ class GenerateEventLogs():
|
|
215 |
task = task[1].drop('log', errors='ignore')
|
216 |
self.objectives = task.dropna().to_dict()
|
217 |
random.seed(RANDOM_SEED)
|
218 |
-
configs = self.optimize()
|
219 |
|
220 |
random.seed(RANDOM_SEED)
|
221 |
if isinstance(configs, list):
|
@@ -313,8 +315,8 @@ class GenerateEventLogs():
|
|
313 |
log_evaluation[key] = abs(self.objectives[key] - metafeatures[key])
|
314 |
return log_evaluation
|
315 |
|
316 |
-
def optimize(self):
|
317 |
-
if
|
318 |
configspace = ConfigurationSpace({
|
319 |
"mode": (5, 40),
|
320 |
"sequence": (0.01, 1),
|
@@ -329,7 +331,7 @@ class GenerateEventLogs():
|
|
329 |
})
|
330 |
print(f"WARNING: No config_space specified in config file. Continuing with {configspace}")
|
331 |
else:
|
332 |
-
configspace_lists =
|
333 |
configspace_tuples = {}
|
334 |
for k, v in configspace_lists.items():
|
335 |
if len(v) == 1:
|
@@ -338,11 +340,11 @@ class GenerateEventLogs():
|
|
338 |
configspace_tuples[k] = tuple(v)
|
339 |
configspace = ConfigurationSpace(configspace_tuples)
|
340 |
|
341 |
-
if
|
342 |
n_trials = 20
|
343 |
print(f"INFO: Running with n_trials={n_trials}")
|
344 |
else:
|
345 |
-
n_trials =
|
346 |
|
347 |
objectives = [*self.objectives.keys()]
|
348 |
|
|
|
25 |
import xml.etree.ElementTree as ET
|
26 |
import re
|
27 |
from xml.dom import minidom
|
28 |
+
from functools import partial
|
29 |
|
30 |
"""
|
31 |
Parameters
|
|
|
154 |
self.log_config = pd.read_csv(self.output_path)
|
155 |
return
|
156 |
|
157 |
+
generator_params = params.get(GENERATOR_PARAMS)
|
158 |
+
experiment = generator_params.get(EXPERIMENT)
|
159 |
|
160 |
if experiment is not None:
|
161 |
tasks, output_path = get_tasks(experiment, self.output_path)
|
|
|
170 |
with multiprocessing.Pool(num_cores) as p:
|
171 |
print(f"INFO: Generator starting at {start.strftime('%H:%M:%S')} using {num_cores} cores for {len(tasks)} tasks...")
|
172 |
random.seed(RANDOM_SEED)
|
173 |
+
partial_wrapper = partial(self.generator_wrapper, generator_params=generator_params)
|
174 |
+
log_config = p.map(partial_wrapper, [(index, row) for index, row in tasks.iterrows()])
|
175 |
# TODO: Split log and metafeatures into separate object attributes
|
176 |
# TODO: Access not storing log in memory
|
177 |
# TODO: identify why log is needed in self.log_config
|
|
|
183 |
|
184 |
else:
|
185 |
random.seed(RANDOM_SEED)
|
186 |
+
configs = self.optimize(generator_params=generator_params)
|
187 |
if type(configs) is not list:
|
188 |
configs = [configs]
|
189 |
temp = self.generate_optimized_log(configs[0])
|
190 |
self.log_config = [temp['metafeatures']] if 'metafeatures' in temp else []
|
191 |
+
save_path = get_output_key_value_location(generator_params[EXPERIMENT],
|
192 |
self.output_path, "genEL")+".xes"
|
193 |
write_xes(temp['log'], save_path)
|
194 |
add_extension_before_traces(save_path)
|
|
|
202 |
print("Clearing parameters...")
|
203 |
self.log_config = None
|
204 |
# self.configs = None
|
205 |
+
# self.params = None
|
206 |
self.output_path = None
|
207 |
self.feature_keys = None
|
208 |
|
209 |
|
210 |
+
def generator_wrapper(self, task, generator_params=None):
|
211 |
try:
|
212 |
identifier = [x for x in task[1] if isinstance(x, str)][0]
|
213 |
except IndexError:
|
|
|
217 |
task = task[1].drop('log', errors='ignore')
|
218 |
self.objectives = task.dropna().to_dict()
|
219 |
random.seed(RANDOM_SEED)
|
220 |
+
configs = self.optimize(generator_params = generator_params)
|
221 |
|
222 |
random.seed(RANDOM_SEED)
|
223 |
if isinstance(configs, list):
|
|
|
315 |
log_evaluation[key] = abs(self.objectives[key] - metafeatures[key])
|
316 |
return log_evaluation
|
317 |
|
318 |
+
def optimize(self, generator_params):
|
319 |
+
if generator_params.get(CONFIG_SPACE) is None:
|
320 |
configspace = ConfigurationSpace({
|
321 |
"mode": (5, 40),
|
322 |
"sequence": (0.01, 1),
|
|
|
331 |
})
|
332 |
print(f"WARNING: No config_space specified in config file. Continuing with {configspace}")
|
333 |
else:
|
334 |
+
configspace_lists = generator_params[CONFIG_SPACE]
|
335 |
configspace_tuples = {}
|
336 |
for k, v in configspace_lists.items():
|
337 |
if len(v) == 1:
|
|
|
340 |
configspace_tuples[k] = tuple(v)
|
341 |
configspace = ConfigurationSpace(configspace_tuples)
|
342 |
|
343 |
+
if generator_params.get(N_TRIALS) is None:
|
344 |
n_trials = 20
|
345 |
print(f"INFO: Running with n_trials={n_trials}")
|
346 |
else:
|
347 |
+
n_trials = generator_params[N_TRIALS]
|
348 |
|
349 |
objectives = [*self.objectives.keys()]
|
350 |
|