@@ -74,6 +74,76 @@ def get_setup(setup_id):
7474 return _create_setup_from_xml (result_dict )
7575
7676
77+ def setup_list (flow = None , tag = None , offset = None , size = None ):
78+ """List all setups matching all of the given filters.
79+
80+ Perform API call `/setup/list/{filters}
81+
82+ Parameters
83+ ----------
84+ flow : int, optional
85+
86+ tag : str, optional
87+
88+ offset : int, optional
89+
90+ size : int, optional
91+
92+ Returns
93+ -------
94+ list
95+ List of found setups.
96+ """
97+
98+ api_call = "setup/list"
99+ if offset is not None :
100+ api_call += "/offset/%d" % int (offset )
101+ if size is not None :
102+ api_call += "/limit/%d" % int (size )
103+ if flow is not None :
104+ api_call += "/flow/%s" % flow
105+ if tag is not None :
106+ api_call += "/tag/%s" % tag
107+
108+ return _list_setups (api_call )
109+
110+
111+ def _list_setups (api_call ):
112+ """Helper function to parse API calls which are lists of setups"""
113+
114+ xml_string = openml ._api_calls ._perform_api_call (api_call )
115+
116+ setups_dict = xmltodict .parse (xml_string )
117+ # Minimalistic check if the XML is useful
118+ if 'oml:setups' not in setups_dict :
119+ raise ValueError ('Error in return XML, does not contain "oml:setups": %s'
120+ % str (setups_dict ))
121+ elif '@xmlns:oml' not in setups_dict ['oml:setups' ]:
122+ raise ValueError ('Error in return XML, does not contain '
123+ '"oml:runs"/@xmlns:oml: %s'
124+ % str (setups_dict ))
125+ elif setups_dict ['oml:setups' ]['@xmlns:oml' ] != 'http://openml.org/openml' :
126+ raise ValueError ('Error in return XML, value of '
127+ '"oml:runs"/@xmlns:oml is not '
128+ '"http://openml.org/openml": %s'
129+ % str (setups_dict ))
130+
131+ if isinstance (setups_dict ['oml:setups' ]['oml:setup' ], list ):
132+ setups_list = setups_dict ['oml:setups' ]['oml:setup' ]
133+ elif isinstance (setups_dict ['oml:setups' ]['oml:setup' ], dict ):
134+ setups_list = [setups_dict ['oml:setups' ]['oml:setup' ]]
135+ else :
136+ raise TypeError ()
137+
138+ setups = dict ()
139+ for setup_ in setups_list :
140+ # making it a dict to give it the right format
141+ current = _create_setup_from_xml ({'oml:setup_parameters' : setup_ })
142+ setups [current .setup_id ] = current
143+
144+ return setups
145+
146+
77147def initialize_model (setup_id ):
78148 '''
79149 Initialized a model based on a setup_id (i.e., using the exact
@@ -147,6 +217,7 @@ def _create_setup_from_xml(result_dict):
147217 '''
148218 Turns an API xml result into a OpenMLSetup object
149219 '''
220+ setup_id = int (result_dict ['oml:setup_parameters' ]['oml:setup_id' ])
150221 flow_id = int (result_dict ['oml:setup_parameters' ]['oml:flow_id' ])
151222 parameters = {}
152223 if 'oml:parameter' not in result_dict ['oml:setup_parameters' ]:
@@ -164,7 +235,7 @@ def _create_setup_from_xml(result_dict):
164235 else :
165236 raise ValueError ('Expected None, list or dict, received someting else: %s' % str (type (xml_parameters )))
166237
167- return OpenMLSetup (flow_id , parameters )
238+ return OpenMLSetup (setup_id , flow_id , parameters )
168239
169240def _create_setup_parameter_from_xml (result_dict ):
170241 return OpenMLParameter (int (result_dict ['oml:id' ]),
@@ -173,4 +244,4 @@ def _create_setup_parameter_from_xml(result_dict):
173244 result_dict ['oml:parameter_name' ],
174245 result_dict ['oml:data_type' ],
175246 result_dict ['oml:default_value' ],
176- result_dict ['oml:value' ])
247+ result_dict ['oml:value' ])
0 commit comments