def setup_exists(flow, model=None): ''' Checks whether a hyperparameter configuration already exists on the server. Parameter --------- flow : flow The openml flow object. sklearn_model : BaseEstimator, optional If given, the parameters are parsed from this model instead of the model in the flow. If not given, parameters are parsed from ``flow.model``. Returns ------- setup_id : int setup id iff exists, False otherwise ''' # sadly, this api call relies on a run object openml.flows.functions._check_flow_for_server_id(flow) if model is None: model = flow.model else: 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, openml_param_settings), pretty=True) file_elements = {'description': ('description.arff', description)} result = openml._api_calls._perform_api_call('/setup/exists/', file_elements=file_elements) result_dict = xmltodict.parse(result) setup_id = int(result_dict['oml:setup_exists']['oml:id']) if setup_id > 0: return setup_id else: return False
def setup_exists(flow) -> int: """ Checks whether a hyperparameter configuration already exists on the server. Parameters ---------- flow : flow 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) Returns ------- setup_id : int setup id iff exists, False otherwise """ # sadly, this api call relies on a run object openml.flows.functions._check_flow_for_server_id(flow) if flow.model is None: raise ValueError( 'Flow should have model field set with the actual model.') if flow.extension is None: raise ValueError( 'Flow should have model field set with the correct extension.') # 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 = flow.extension.obtain_parameter_values(flow) description = xmltodict.unparse(_to_dict(flow.flow_id, openml_param_settings), pretty=True) file_elements = {'description': ('description.arff', description)} result = openml._api_calls._perform_api_call('/setup/exists/', 'post', file_elements=file_elements) result_dict = xmltodict.parse(result) setup_id = int(result_dict['oml:setup_exists']['oml:id']) if setup_id > 0: return setup_id else: return False
def setup_exists(flow): """ Checks whether a hyperparameter configuration already exists on the server. Parameters ---------- flow : flow 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) Returns ------- setup_id : int setup id iff exists, False otherwise """ # sadly, this api call relies on a run object openml.flows.functions._check_flow_for_server_id(flow) if flow.model is None: raise ValueError('Flow should have model field set with the actual ' '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!') # TODO: currently hard-coded sklearn assumption openml_param_settings = openml.flows.obtain_parameter_values(flow) description = xmltodict.unparse(_to_dict(flow.flow_id, openml_param_settings), pretty=True) file_elements = {'description': ('description.arff', description)} result = openml._api_calls._perform_api_call('/setup/exists/', file_elements=file_elements) result_dict = xmltodict.parse(result) setup_id = int(result_dict['oml:setup_exists']['oml:id']) if setup_id > 0: return setup_id else: return False