99
1010from ..exceptions import PyOpenMLError
1111from .. import config
12- from ..flows import sklearn_to_flow , get_flow
12+ from ..flows import sklearn_to_flow , get_flow , flow_exists
1313from ..setups import setup_exists
1414from ..exceptions import OpenMLCacheException , OpenMLServerException
1515from ..util import URLError
@@ -47,11 +47,11 @@ def run_task(task, model):
4747 flow = sklearn_to_flow (model )
4848
4949 # returns flow id if the flow exists on the server, -1 otherwise
50- _ , flow_id = openml . flows . _check_flow_exists (flow .name , flow .external_version )
50+ flow_id = flow_exists (flow .name , flow .external_version )
5151
5252 # skips the run if it already exists and the user opts for this in the config file.
5353 # also, if the flow is not present on the server, the check is not needed.
54- if config .avoid_duplicate_runs and flow_id > 0 :
54+ if config .avoid_duplicate_runs and flow_id :
5555 flow = get_flow (flow_id )
5656 setup_id = setup_exists (flow , model )
5757 ids = _run_exists (task .task_id , setup_id )
@@ -70,13 +70,17 @@ def run_task(task, model):
7070 run = OpenMLRun (task_id = task .task_id , flow_id = None , dataset_id = dataset .dataset_id , model = model )
7171 run .data_content , run .trace_content = _run_task_get_arffcontent (model , task , class_labels )
7272
73- if flow_id < 0 :
74- flow .publish ()
75- config .logger .info (flow_id )
76-
77- # attach the flow to the run
78- run .flow_id = flow_id
73+ if flow_id == False :
74+ # means the flow did not exists.
75+ # As we could run it, publish it now
76+ flow = flow .publish ()
77+ else :
78+ # flow already existed, download it from server
79+ # TODO (neccessary? is this a post condition of this function)
80+ flow = get_flow (flow_id )
7981
82+ run .flow_id = flow .flow_id
83+ config .logger .info ('Executed Task %d with Flow id: %d' % (task .task_id , run .flow_id ))
8084
8185 return run
8286
@@ -311,27 +315,28 @@ def _create_run_from_xml(xml):
311315 evaluations = dict ()
312316 detailed_evaluations = defaultdict (lambda : defaultdict (dict ))
313317 evaluation_flows = dict ()
314- for evaluation_dict in run ['oml:output_data' ]['oml:evaluation' ]:
315- key = evaluation_dict ['oml:name' ]
316- if 'oml:value' in evaluation_dict :
317- value = float (evaluation_dict ['oml:value' ])
318- elif 'oml:array_data' in evaluation_dict :
319- value = evaluation_dict ['oml:array_data' ]
320- else :
321- raise ValueError ('Could not find keys "value" or "array_data" '
322- 'in %s' % str (evaluation_dict .keys ()))
323-
324- if '@repeat' in evaluation_dict and '@fold' in evaluation_dict :
325- repeat = int (evaluation_dict ['@repeat' ])
326- fold = int (evaluation_dict ['@fold' ])
327- repeat_dict = detailed_evaluations [key ]
328- fold_dict = repeat_dict [repeat ]
329- fold_dict [fold ] = value
330- else :
331- evaluations [key ] = value
332- evaluation_flows [key ] = flow_id
318+ if 'oml:output_data' in run and 'oml:evaluation' in run ['oml:output_data' ]:
319+ for evaluation_dict in run ['oml:output_data' ]['oml:evaluation' ]:
320+ key = evaluation_dict ['oml:name' ]
321+ if 'oml:value' in evaluation_dict :
322+ value = float (evaluation_dict ['oml:value' ])
323+ elif 'oml:array_data' in evaluation_dict :
324+ value = evaluation_dict ['oml:array_data' ]
325+ else :
326+ raise ValueError ('Could not find keys "value" or "array_data" '
327+ 'in %s' % str (evaluation_dict .keys ()))
328+
329+ if '@repeat' in evaluation_dict and '@fold' in evaluation_dict :
330+ repeat = int (evaluation_dict ['@repeat' ])
331+ fold = int (evaluation_dict ['@fold' ])
332+ repeat_dict = detailed_evaluations [key ]
333+ fold_dict = repeat_dict [repeat ]
334+ fold_dict [fold ] = value
335+ else :
336+ evaluations [key ] = value
337+ evaluation_flows [key ] = flow_id
333338
334- evaluation_flows [key ] = flow_id
339+ evaluation_flows [key ] = flow_id
335340
336341 return OpenMLRun (run_id = run_id , uploader = uploader ,
337342 uploader_name = uploader_name , task_id = task_id ,
0 commit comments