Skip to content

Commit e0e52b8

Browse files
Finishing the refactoring
1 parent 6f85df7 commit e0e52b8

27 files changed

Lines changed: 316 additions & 290 deletions

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@ pip install learning-orchestra-client
1919

2020
# Usage
2121

22-
Each functionality in learningOrchestra is contained in its own class. Check the [python client docs](https://learningorchestra.github.io/pythonClient/) for all the available.
22+
Each interoperable REST API service described in Learning Orchestra is translated
23+
into Python. Details at [python client docs](https://learningorchestra.github.io/pythonClient/).
24+
Furthermore, some extra method calls are included into Python client API to simplify
25+
even more the Machine Learning services. For instance, the REST API is asynchronous,
26+
except for GET HTTP requests, but the Python client enables also the synchronous API calls.
27+
The wait API method, useful to receive notifications from ML pipes, is another important
28+
example to ilustrate an extension of the original REST API.
29+
2330

2431
# Example
2532

learning_orchestra_client/builder/builder.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from learning_orchestra_client.observe import Observer
1+
from learning_orchestra_client.observe.observe import Observer
22
from learning_orchestra_client.util._response_treat import ResponseTreat
33
from learning_orchestra_client.util._entity_reader import EntityReader
44
import requests
@@ -27,9 +27,10 @@ def run_spark_ml_sync(self,
2727
pretty_response: bool = False) -> Union[dict, str]:
2828
"""
2929
description: This method call runs several steps of a machine
30-
learning pipeline (transform, tune, train and evaluate, for instance) using
31-
a model code and several classifiers. It represents a way to run an entire pipeline.
32-
The caller waits until the method execution ends, since it is a synchronous method.
30+
learning pipeline (transform, tune, train and evaluate, for instance)
31+
using a model code and several classifiers. It represents a way to run
32+
an entire pipeline. The caller waits until the method execution ends,
33+
since it is a synchronous method.
3334
3435
train_dataset_name: Represent final train dataset.
3536
test_dataset_name: Represent final test dataset.
@@ -62,9 +63,10 @@ def run_spark_ml_async(self,
6263
pretty_response: bool = False) -> Union[dict, str]:
6364
"""
6465
description: This method call runs several steps of a machine
65-
learning pipeline (transform, tune, train and evaluate, for instance) using
66-
a model code and several classifiers. It represents a way to run an entire pipeline.
67-
The caller does not wait until the method execution ends, since it is an asynchronous method.
66+
learning pipeline (transform, tune, train and evaluate, for instance)
67+
using a model code and several classifiers. It represents a way to run
68+
an entire pipeline. The caller does not wait until the method execution
69+
ends, since it is an asynchronous method.
6870
6971
train_dataset_name: Represent final train dataset.
7072
test_dataset_name: Represent final test dataset.
@@ -120,9 +122,9 @@ def search_builder_register_predictions(self,
120122
set at 20 rows per request)
121123
skip: Number of rows to skip in pagination(default: 0)
122124
123-
return: A page with some tuples or registers inside or an error if the pipeline runs
124-
incorrectly. The current page is also returned to be used in
125-
future content requests.
125+
return: A page with some tuples or registers inside or an error if the
126+
pipeline runs incorrectly. The current page is also returned to be used
127+
in future content requests.
126128
"""
127129

128130
response = self.__entity_reader.read_entity_content(
@@ -171,17 +173,16 @@ def delete_builder(self, builder_name: str, pretty_response: bool = False) \
171173

172174
return self.__response_treat.treatment(response, pretty_response)
173175

174-
def wait(self, dataset_name: str, timeout: str) -> dict:
176+
def wait(self, dataset_name: str, timeout: int = None) -> dict:
175177
"""
176178
description: This method is responsible to create a synchronization
177179
barrier for the run_spark_ml_async method.
178180
179181
dataset_name: Represents the pipeline name.
180-
timeout: Represents the time in seconds to wait for a builder to finish its run. The -1 value
181-
waits until the builder finishes.
182+
timeout: Represents the time in seconds to wait for a builder to
183+
finish its run.
182184
183185
return: JSON object with an error message, a warning message or a
184186
correct execution of a pipeline
185187
"""
186188
return self.__observer.wait(dataset_name, timeout)
187-

learning_orchestra_client/dataset/_dataset.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..observe import Observer
1+
from learning_orchestra_client.observe.observe import Observer
22
from learning_orchestra_client.util._response_treat import ResponseTreat
33
from learning_orchestra_client.util._entity_reader import EntityReader
44
import requests
@@ -59,7 +59,8 @@ def insert_dataset_async(self,
5959
6060
return: A JSON object with an error or warning message or a URL
6161
indicating the correct operation (the caller must use such an URL to
62-
proceed future checks to verify if the dataset is inserted - using wait method).
62+
proceed future checks to verify if the dataset is inserted - using wait
63+
method).
6364
"""
6465
request_body = {self.__DATASET_NAME: dataset_name,
6566
self.__URL: url}
@@ -122,7 +123,7 @@ def search_dataset_content(self,
122123
set at 20 rows per request)
123124
skip: Number of rows to skip in pagination(default: 0)
124125
125-
return A page with some tuples or registers inside or an error if there
126+
return: A page with some tuples or registers inside or an error if there
126127
is no such dataset. The current page is also returned to be used in
127128
future content requests.
128129
"""
@@ -132,14 +133,14 @@ def search_dataset_content(self,
132133

133134
return self.__response_treat.treatment(response, pretty_response)
134135

135-
def wait(self, dataset_name: str, timeout: str) -> dict:
136+
def wait(self, dataset_name: str, timeout: int = None) -> dict:
136137
"""
137138
description: This method is responsible to create a synchronization
138139
barrier for the insert_dataset_async method.
139140
140141
dataset_name: Represents the dataset name.
141-
timeout: Represents the time in seconds to wait for a dataset download to finish its run. The -1 value
142-
waits until the download finishes.
142+
timeout: Represents the time in seconds to wait for a dataset
143+
download to finish its run.
143144
144145
return: JSON object with an error message, a warning message or a
145146
correct execution of a pipeline

learning_orchestra_client/evaluate/_evaluate.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..observe import Observer
1+
from learning_orchestra_client.observe.observe import Observer
22
from learning_orchestra_client.util._response_treat import ResponseTreat
33
from learning_orchestra_client.util._entity_reader import EntityReader
44
import requests
@@ -93,8 +93,8 @@ def create_evaluate_async(self,
9393
def search_all_evaluates(self, pretty_response: bool = False) \
9494
-> Union[dict, str]:
9595
"""
96-
description: This method retrieves all created evaluations, i.e., it does
97-
not retrieve the specific evaluation content.
96+
description: This method retrieves all created evaluations, i.e., it
97+
does not retrieve the specific evaluation content.
9898
9999
pretty_response: If true it returns a string, otherwise a dictionary.
100100
@@ -107,12 +107,12 @@ def search_all_evaluates(self, pretty_response: bool = False) \
107107
def delete_evaluate(self, name: str, pretty_response=False) \
108108
-> Union[dict, str]:
109109
"""
110-
description: This method is responsible for deleting an evaluation result.
111-
This delete operation is asynchronous, so it does not lock the caller
112-
until the deletion finished. Instead, it returns a JSON object with a
113-
URL for a future use. The caller uses the wait method for delete checks. If a
114-
dataset was used by another task (Ex. projection, histogram, pca, tune
115-
and so forth), it cannot be deleted.
110+
description: This method is responsible for deleting an evaluation
111+
result. This delete operation is asynchronous, so it does not lock the
112+
caller until the deletion finished. Instead, it returns a JSON object
113+
with a URL for a future use. The caller uses the wait method for delete
114+
checks. If a dataset was used by another task (Ex. projection,
115+
histogram, tune, and so forth), it cannot be deleted.
116116
117117
pretty_response: If true it returns a string, otherwise a dictionary.
118118
name: Represents the model name.
@@ -144,7 +144,7 @@ def search_evaluate_content(self,
144144
set at 20 rows per request)
145145
skip: Number of rows to skip in pagination(default: 0)
146146
147-
return A page with some metadata inside or an error if there
147+
return: A page with some metadata inside or an error if there
148148
is no such dataset. The current page is also returned to be used in
149149
future content requests.
150150
"""
@@ -154,14 +154,15 @@ def search_evaluate_content(self,
154154

155155
return self.__response_treat.treatment(response, pretty_response)
156156

157-
def wait(self, name: str, timeout: str) -> dict:
157+
def wait(self, name: str, timeout: int = None) -> dict:
158158
"""
159159
description: This method is responsible to create a synchronization
160-
barrier for the create_evaluate_async method and delete_evaluate_async method.
160+
barrier for the create_evaluate_async method and
161+
delete_evaluate_async method.
161162
162163
name: Represents the model name.
163-
timeout: Represents the time in seconds to wait for an evaluation to finish its run. The -1 value
164-
waits until the evaluation finishes.
164+
timeout: Represents the time in seconds to wait for an evaluation to
165+
finish its run.
165166
166167
return: JSON object with an error message, a warning message or a
167168
correct evaluation result

learning_orchestra_client/evaluate/scikitlearn.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33

44
class EvaluateScikitLearn(Evaluate):
5-
__PARENT_NAME_FIELD = "parentName"
6-
__METHOD_NAME_FIELD = "method"
7-
__ClASS_PARAMETERS_FIELD = "methodParameters"
8-
__NAME_FIELD = "name"
9-
__DESCRIPTION_FIELD = "description"
10-
115
def __init__(self, cluster_ip: str):
126
self.__api_path = "/api/learningOrchestra/v1/evaluate/scikitlearn"
137
self.__cluster_ip = cluster_ip

learning_orchestra_client/evaluate/tensorflow.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22

33

44
class EvaluateTensorflow(Evaluate):
5-
__PARENT_NAME_FIELD = "parentName"
6-
__METHOD_NAME_FIELD = "method"
7-
__ClASS_PARAMETERS_FIELD = "methodParameters"
8-
__NAME_FIELD = "name"
9-
__DESCRIPTION_FIELD = "description"
10-
115
def __init__(self, cluster_ip: str):
126
self.__api_path = "/api/learningOrchestra/v1/evaluate/tensorflow"
137
self.__cluster_ip = cluster_ip
14-
super().__init__(cluster_ip, self.__api_path)
8+
super().__init__(cluster_ip, self.__api_path)

learning_orchestra_client/explore/_explore.py

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..observe import Observer
1+
from learning_orchestra_client.observe.observe import Observer
22
from learning_orchestra_client.util._response_treat import ResponseTreat
33
from learning_orchestra_client.util._entity_reader import EntityReader
44
import requests
@@ -21,13 +21,13 @@ def __init__(self, cluster_ip: str, api_path: str):
2121
self.__observer = Observer(self.__cluster_ip)
2222

2323
def create_explore_sync(self,
24-
name: str,
25-
model_name: str,
26-
parent_name: str,
27-
method_name: str,
28-
parameters: dict,
29-
description: str = "",
30-
pretty_response: bool = False) -> \
24+
name: str,
25+
model_name: str,
26+
parent_name: str,
27+
method_name: str,
28+
parameters: dict,
29+
description: str = "",
30+
pretty_response: bool = False) -> \
3131
Union[dict, str]:
3232
"""
3333
description: This method runs an evaluation about a model in sync mode
@@ -57,16 +57,17 @@ def create_explore_sync(self,
5757
return self.__response_treat.treatment(response, pretty_response)
5858

5959
def create_explore_async(self,
60-
name: str,
61-
model_name: str,
62-
parent_name: str,
63-
method_name: str,
64-
parameters: dict,
65-
description: str = "",
66-
pretty_response: bool = False) -> \
60+
name: str,
61+
model_name: str,
62+
parent_name: str,
63+
method_name: str,
64+
parameters: dict,
65+
description: str = "",
66+
pretty_response: bool = False) -> \
6767
Union[dict, str]:
6868
"""
69-
description: This method runs an explore service about a model in async mode
69+
description: This method runs an explore service about a model in async
70+
mode
7071
7172
pretty_response: If true it returns a string, otherwise a dictionary.
7273
name: Is the name of the model that will be explored.
@@ -93,8 +94,8 @@ def create_explore_async(self,
9394
def search_all_explores(self, pretty_response: bool = False) \
9495
-> Union[dict, str]:
9596
"""
96-
description: This method retrieves all created explorations, i.e., it does
97-
not retrieve the specific explore content.
97+
description: This method retrieves all created explorations, i.e., it
98+
does not retrieve the specific explore content.
9899
99100
pretty_response: If true it returns a string, otherwise a dictionary.
100101
@@ -110,9 +111,9 @@ def delete_explore(self, name: str, pretty_response=False) \
110111
description: This method is responsible for deleting an explore result.
111112
This delete operation is asynchronous, so it does not lock the caller
112113
until the deletion finished. Instead, it returns a JSON object with a
113-
URL for a future use. The caller uses the wait method for delete checks. If a
114-
dataset was used by another task (Ex. projection, histogram, pca, tune
115-
and so forth), it cannot be deleted.
114+
URL for a future use. The caller uses the wait method for delete
115+
checks. If a dataset was used by another task (Ex. projection,
116+
histogram, tune and so forth), it cannot be deleted.
116117
117118
pretty_response: If true it returns a string, otherwise a dictionary.
118119
name: Represents the model name.
@@ -127,17 +128,17 @@ def delete_explore(self, name: str, pretty_response=False) \
127128
return self.__response_treat.treatment(response, pretty_response)
128129

129130
def search_explore_image(self,
130-
name: str,
131-
pretty_response: bool = False) \
131+
name: str,
132+
pretty_response: bool = False) \
132133
-> Union[dict, str]:
133134
"""
134135
description: This method is responsible for retrieving the explore
135136
image to be plotted
136137
137138
pretty_response: If true it returns a string, otherwise a dictionary.
138-
name: Is the name of the model.
139+
name: Is the name of the explore instance.
139140
140-
return An URL with a link for an image or an error if there
141+
return: An URL with a link for an image or an error if there
141142
is no such result.
142143
"""
143144

@@ -146,16 +147,37 @@ def search_explore_image(self,
146147

147148
return self.__response_treat.treatment(response, pretty_response)
148149

149-
def wait(self, name: str, timeout: str) -> dict:
150+
def search_explore_metadata(self,
151+
name: str,
152+
pretty_response: bool = False) \
153+
-> Union[dict, str]:
154+
"""
155+
description: This method is responsible for retrieving the explore
156+
metadata image.
157+
158+
pretty_response: If true it returns a string, otherwise a dictionary.
159+
name: Is the name of the explore instance.
160+
161+
return: A page with some metadata inside or an error if there
162+
is no such dataset. The current page is also returned to be used in
163+
future content requests.
164+
"""
165+
166+
response = self.__entity_reader.read_explore_image_metadata(name)
167+
168+
return self.__response_treat.treatment(response, pretty_response)
169+
170+
def wait(self, name: str, timeout: int = None) -> dict:
150171
"""
151-
description: This method is responsible to create a synchronization
152-
barrier for the create_explore_async method, delete_explore_async method.
172+
description: This method is responsible to create a synchronization
173+
barrier for the create_explore_async method, delete_explore_async
174+
method.
153175
154-
name: Represents the model name.
155-
timeout: Represents the time in seconds to wait for an explore to finish its run. The -1 value
156-
waits until the explore finishes.
176+
name: Represents the model name.
177+
timeout: Represents the time in seconds to wait for an explore to
178+
finish its run.
157179
158-
return: JSON object with an error message, a warning message or a
159-
correct explore result (the image URL as an explore result)
180+
return: JSON object with an error message, a warning message or a
181+
correct explore result (the image URL as an explore result)
160182
"""
161183
return self.__observer.wait(name, timeout)

0 commit comments

Comments
 (0)