Skip to content

Commit d97d0f9

Browse files
committed
descripe flow methods, make all low-level xml methods private
1 parent 01ae559 commit d97d0f9

2 files changed

Lines changed: 56 additions & 13 deletions

File tree

openml/flows/flow.py

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@
66

77

88
class OpenMLFlow(object):
9+
"""OpenML Flow. Stores machine learning models.
10+
11+
Parameters
12+
----------
13+
model : scikit-learn compatible model
14+
The model the flow consists of. The model needs to have fit and predict methods.
15+
description : string
16+
Description of the flow (free text).
17+
creator : string
18+
FIXME
19+
contributor : string
20+
FIXME
21+
tag : string
22+
FIXME
23+
id : int, optional
24+
Flow ID. Assigned by the server (fixme shouldn't be here?)
25+
uploader : string, optional
26+
User uploading the model (fixme shouldn't be here?). Assigned by the server.
27+
28+
29+
"""
930
def __init__(self, model, id=None, uploader=None,
1031
description='Flow generated by run_task', creator=None,
1132
contributor=None, tag=None):
@@ -20,7 +41,14 @@ def __init__(self, model, id=None, uploader=None,
2041
model.__class__.__name__)
2142
self.external_version = 'Tsklearn_' + sklearn.__version__
2243

23-
def generate_flow_xml(self):
44+
def _generate_flow_xml(self):
45+
"""Generate xml representation of self for upload to server.
46+
47+
Returns
48+
-------
49+
flow_xml : string
50+
Flow represented as XML string.
51+
"""
2452
model = self.model
2553
flow_dict = OrderedDict()
2654
flow_dict['oml:flow'] = OrderedDict()
@@ -53,18 +81,22 @@ def publish(self):
5381
5482
(optional) file_path is the absolute path to the file that is the flow (eg. a script)
5583
"""
56-
xml_description = self.generate_flow_xml()
84+
xml_description = self._generate_flow_xml()
5785
data = {'description': xml_description, 'source': self.source}
5886
return_code, return_value = _perform_api_call(
5987
"/flow/", data=data)
6088
return return_code, return_value
6189

62-
def ensure_flow_exists(self):
63-
"""
64-
First checks if a flow exists for the given model.
65-
If it does, then it will return the corresponding flow id.
66-
If it does not, then it will create a flow, and return the flow id
67-
of the newly created flow.
90+
def _ensure_flow_exists(self):
91+
""" Checks if a flow exists for the given model and possibly creates it.
92+
93+
If the given flow exists on the server, the flow-id will simply
94+
be returned. Otherwise it will be uploaded to the server.
95+
96+
Returns
97+
-------
98+
flow_id : int
99+
Flow id on the server.
68100
"""
69101
import sklearn
70102
flow_version = 'Tsklearn_' + sklearn.__version__
@@ -83,9 +115,21 @@ def ensure_flow_exists(self):
83115
def _check_flow_exists(name, version):
84116
"""Retrieves the flow id of the flow uniquely identified by name+version.
85117
86-
Returns flow id if such a flow exists,
87-
returns -1 if flow does not exists,
88-
http://www.openml.org/api_docs/#!/flow/get_flow_exists_name_version
118+
Parameter
119+
---------
120+
name : string
121+
Name of the flow
122+
version : string
123+
Version information associated with flow.
124+
125+
Returns
126+
-------
127+
flow_exist : int
128+
Flow id or -1 if the flow doesn't exist.
129+
130+
Notes
131+
-----
132+
see http://www.openml.org/api_docs/#!/flow/get_flow_exists_name_version
89133
"""
90134
if not (type(name) is str and len(name) > 0):
91135
raise ValueError('Parameter \'name\' should be a non-empty string')

openml/runs/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def run_task(task, model):
119119
a dictionary with an 'attributes' and 'data' entry for an arff file
120120
"""
121121
flow = OpenMLFlow(model=model)
122-
flow_id = flow.ensure_flow_exists()
122+
flow_id = flow._ensure_flow_exists()
123123
if(flow_id < 0):
124124
print("No flow")
125125
return 0, 2
@@ -196,7 +196,6 @@ def _to_dict(taskid, flow_id, setup_string, parameter_settings, tags):
196196
description['oml:run'] = OrderedDict()
197197
description['oml:run']['@xmlns:oml'] = 'http://openml.org/openml'
198198
description['oml:run']['oml:task_id'] = taskid
199-
200199
description['oml:run']['oml:flow_id'] = flow_id
201200

202201
params = []

0 commit comments

Comments
 (0)