diff --git a/openml/setups/functions.py b/openml/setups/functions.py index 7e7c296f8..fb58dc1ab 100644 --- a/openml/setups/functions.py +++ b/openml/setups/functions.py @@ -20,7 +20,9 @@ def setup_exists(flow, model=None): ---------- flow : flow - The openml flow object. + The openml flow object. Should have flow id present for the main flow + and all subflows (i.e., it should be downloaded from the server by + means of flow.get, and not instantiated locally) sklearn_model : BaseEstimator, optional If given, the parameters are parsed from this model instead of the @@ -36,11 +38,16 @@ def setup_exists(flow, model=None): openml.flows.functions._check_flow_for_server_id(flow) if model is None: + # model is left empty. We take the model from the flow. model = flow.model - else: - exists = flow_exists(flow.name, flow.external_version) - if exists != flow.flow_id: - raise ValueError('This should not happen!') + if flow.model is None: + raise ValueError('Could not locate model (neither given as' + 'argument nor available as flow.model)') + + # checks whether the flow exists on the server and flow ids align + exists = flow_exists(flow.name, flow.external_version) + if exists != flow.flow_id: + raise ValueError('This should not happen!') openml_param_settings = openml.runs.OpenMLRun._parse_parameters(flow, model) description = xmltodict.unparse(_to_dict(flow.flow_id, diff --git a/tests/test_runs/test_run_functions.py b/tests/test_runs/test_run_functions.py index f622ea269..6fabac8d9 100644 --- a/tests/test_runs/test_run_functions.py +++ b/tests/test_runs/test_run_functions.py @@ -596,22 +596,21 @@ def test_get_run_trace(self): task = openml.tasks.get_task(task_id) # IMPORTANT! Do not sentinel this flow. is faster if we don't wait on openml server - clf = RandomizedSearchCV(RandomForestClassifier(random_state=42), + clf = RandomizedSearchCV(RandomForestClassifier(random_state=42, + n_estimators=5), {"max_depth": [3, None], "max_features": [1, 2, 3, 4], "bootstrap": [True, False], "criterion": ["gini", "entropy"]}, - num_iterations, random_state=42) + num_iterations, random_state=42, cv=3) # [SPEED] make unit test faster by exploiting run information from the past try: # in case the run did not exists yet - run = openml.runs.run_model_on_task(task, clf, avoid_duplicate_runs=True) - trace = openml.runs.functions._create_trace_from_arff( - run._generate_trace_arff_dict() - ) + run = openml.runs.run_model_on_task(clf, task, + avoid_duplicate_runs=True) self.assertEqual( - len(trace.trace_iterations), + len(run.trace.trace_iterations), num_iterations * num_folds, ) run = run.publish()