Skip to content

Commit b01e9ce

Browse files
committed
Merge branch 'release/4.3'
2 parents 9dfe25a + b5acb02 commit b01e9ce

File tree

9 files changed

+286
-42
lines changed

9 files changed

+286
-42
lines changed

HISTORY.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
Changelog
22
==========
33

4-
4.1.0 (2018-01-10)
4+
4.3.0 (2018-06-01)
5+
------------------
6+
7+
* Initial release for DSS 4.3
8+
9+
4.2.1 (2018-04-30)
10+
-------------------
11+
12+
* Initial release for DSS 4.2
13+
14+
4.1.0 (2017-11-10)
515
-------------------
616

717
* Initial release for DSS 4.1
818

9-
4.0.0 (2018-01-10)
19+
4.0.0 (2017-01-10)
1020
------------------
1121

1222
* Initial release for DSS 4.0

dataikuapi/dss/admin.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,143 @@ def set_definition(self, definition):
567567
return self.client._perform_empty(
568568
"PUT", "/admin/globalAPIKeys/%s" % self.key,
569569
body = definition)
570+
571+
class DSSCluster(object):
572+
"""
573+
A handle to interact with a cluster on the DSS instance
574+
"""
575+
def __init__(self, client, cluster_id):
576+
"""Do not call that directly, use :meth:`dataikuapi.dss.DSSClient.get_cluster`"""
577+
self.client = client
578+
self.cluster_id = cluster_id
579+
580+
########################################################
581+
# Cluster deletion
582+
########################################################
583+
584+
def delete(self):
585+
"""
586+
Deletes the cluster. This does not previously stop it.
587+
"""
588+
self.client._perform_empty(
589+
"DELETE", "/admin/clusters/%s" % (self.cluster_id))
590+
591+
592+
########################################################
593+
# Cluster description
594+
########################################################
595+
596+
def get_settings(self):
597+
"""
598+
Get the cluster's settings. This includes opaque data for the cluster if this is
599+
a started managed cluster.
600+
601+
The returned object can be used to save settings.
602+
603+
:returns: a :class:`DSSClusterSettings` object to interact with cluster settings
604+
:rtype: :class:`DSSClusterSettings`
605+
"""
606+
settings = self.client._perform_json(
607+
"GET", "/admin/clusters/%s" % (self.cluster_id))
608+
return DSSClusterSettings(self.client, self.cluster_id, settings)
609+
610+
def set_definition(self, cluster):
611+
"""
612+
Set the cluster's definition. The definition should come from a call to the get_definition()
613+
method.
614+
615+
616+
:param cluster: a cluster definition
617+
618+
Returns:
619+
the updated cluster definition, as a JSON object
620+
"""
621+
return self.client._perform_json(
622+
"PUT", "/admin/clusters/%s" % (self.cluster_id), body=cluster)
623+
624+
def get_status(self):
625+
"""
626+
Get the cluster's status and usage
627+
628+
:returns: The cluster status, as a :class:`DSSClusterStatus` object
629+
:rtype: :class:`DSSClusterStatus`
630+
"""
631+
status = self.client._perform_json("GET", "/admin/clusters/%s/status" % (self.cluster_id))
632+
return DSSClusterStatus(self.client, self.cluster_id, status)
633+
634+
########################################################
635+
# Cluster actions
636+
########################################################
637+
638+
def start(self):
639+
"""
640+
Starts or attaches the cluster.
641+
642+
This operation is only valid for a managed cluster.
643+
"""
644+
resp = self.client._perform_json(
645+
"POST", "/admin/clusters/%s/actions/start" % (self.cluster_id))
646+
if resp is None:
647+
raise Exception('Env update returned no data')
648+
if resp.get('messages', {}).get('error', False):
649+
raise Exception('Cluster operation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {}))))
650+
return resp
651+
652+
def stop(self):
653+
"""
654+
Stops or detaches the cluster
655+
656+
This operation is only valid for a managed cluster.
657+
"""
658+
resp = self.client._perform_json(
659+
"POST", "/admin/clusters/%s/actions/stop" % (self.cluster_id))
660+
if resp is None:
661+
raise Exception('Env update returned no data')
662+
if resp.get('messages', {}).get('error', False):
663+
raise Exception('Cluster operation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {}))))
664+
return resp
665+
666+
class DSSClusterSettings(object):
667+
def __init__(self, client, cluster_id, settings):
668+
"""Do not call directly, use :meth:`DSSCluster.get_settings`"""
669+
self.client = client
670+
self.cluster_id = cluster_id
671+
self.settings = settings
672+
673+
def get_raw(self):
674+
"""
675+
Gets all settings as a raw dictionary. This returns a reference to the raw settings, not a copy,
676+
so changes made to the returned object will be reflected when saving.
677+
678+
Fields that can be updated:
679+
- permissions, usableByAll, owner
680+
- params
681+
"""
682+
return self.settings
683+
684+
def get_plugin_data(self):
685+
"""
686+
If this is a managed attached cluster, returns the opaque data returned by the cluster's start
687+
operation. Else, returns None.
688+
689+
You should generally not modify this
690+
"""
691+
return self.settings.get("data", None)
692+
693+
def save(self):
694+
"""Saves back the settings to the cluster"""
695+
return self.client._perform_json(
696+
"PUT", "/admin/clusters/%s" % (self.cluster_id), body=self.settings)
697+
698+
class DSSClusterStatus(object):
699+
def __init__(self, client, cluster_id, settings):
700+
"""Do not call directly, use :meth:`DSSCluster.get_Status`"""
701+
self.client = client
702+
self.cluster_id = cluster_id
703+
self.status = status
704+
705+
def get_raw(self):
706+
"""
707+
Gets the whole status as a raw dictionary.
708+
"""
709+
return self.status

dataikuapi/dss/apideployer.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_deployment(self, deployment_id):
3737
def create_deployment(self, deployment_id, service_id, infra_id, version):
3838
"""
3939
Creates a deployment and returns the handle to interact with it. The returned deployment
40-
is not yet started and you need to call :meth:`~DSSAPIDeployerDeployment.update`
40+
is not yet started and you need to call :meth:`~DSSAPIDeployerDeployment.start_update`
4141
4242
:param str deployment_id: Identifier of the deployment to create
4343
:param str service_id: Identifier of the API Service to target
@@ -77,7 +77,7 @@ def get_infra(self, infra_id):
7777
:param str infra_id: Identifier of the infra to get
7878
:rtype: :class:`DSSAPIDeployerDeployment`
7979
"""
80-
return DSSAPIDeployerDeployment(self.client, infra_id)
80+
return DSSAPIDeployerInfra(self.client, infra_id)
8181

8282
def list_services(self, as_objects = True):
8383
"""
@@ -148,15 +148,6 @@ def get_settings(self):
148148

149149
return DSSAPIDeployerInfraSettings(self.client, self.infra_id, settings)
150150

151-
def delete(self):
152-
"""
153-
Deletes this infra
154-
155-
You may only delete a deployment if it is disabled and has been updated after disabling it.
156-
"""
157-
return self.client._perform_empty(
158-
"DELETE", "/api-deployer/infras/%s" % (self.infra_id))
159-
160151
class DSSAPIDeployerInfraSettings(object):
161152
"""The settings of an API Deployer Infra.
162153
@@ -194,7 +185,7 @@ def get_raw(self):
194185
def save(self):
195186
"""Saves back these settings to the infra"""
196187
self.client._perform_empty(
197-
"PUT", "/api-deployer/infra/%s/settings" % (self.infra_id),
188+
"PUT", "/api-deployer/infras/%s/settings" % (self.infra_id),
198189
body = self.settings)
199190

200191

@@ -240,7 +231,7 @@ def get_settings(self):
240231

241232
def start_update(self):
242233
"""
243-
Updates this deployment to try to match the actual state to the current settings
234+
Starts an asynchronous update of this deployment to try to match the actual state to the current settings
244235
245236
:returns: a :class:`dataikuapi.dss.future.DSSFuture` tracking the progress of the update. Call
246237
:meth:`~dataikuapi.dss.future.DSSFuture.wait_for_result` on the returned object
@@ -258,7 +249,7 @@ def delete(self):
258249
You may only delete a deployment if it is disabled and has been updated after disabling it.
259250
"""
260251
return self.client._perform_empty(
261-
"DELETE", "/api-deployer/deployments/%s/actions/update" % (self.deployment_id))
252+
"DELETE", "/api-deployer/deployments/%s" % (self.deployment_id))
262253

263254

264255
class DSSAPIDeployerDeploymentSettings(object):

dataikuapi/dss/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_metadata(self):
8888
8989
Returns:
9090
a dict object. For more information on available metadata, please see
91-
https://doc.dataiku.com/dss/api/latest
91+
https://doc.dataiku.com/dss/api/4.3/rest/
9292
"""
9393
return self.client._perform_json(
9494
"GET", "/projects/%s/datasets/%s/metadata" % (self.project_key, self.dataset_name))

dataikuapi/dss/ml.py

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def set_split_random(self, train_ratio = 0.8, selection = None, dataset_name=Non
1818
Sets the train/test split to random splitting of an extract of a single dataset
1919
2020
:param float train_ratio: Ratio of rows to use for train set. Must be between 0 and 1
21-
:param object selection: A :class:`DSSDatasetSelectionBuilder` to build the settings of the extract of the dataset. May be None (won't be changed)
22-
:param str dataset_name: Name of dataset to split. If None, the main dataset used to create the ML Task will be used.
21+
:param object selection: A :class:`~dataikuapi.dss.utils.DSSDatasetSelectionBuilder` to build the settings of the extract of the dataset. May be None (won't be changed)
22+
:param str dataset_name: Name of dataset to split. If None, the main dataset used to create the visual analysis will be used.
2323
"""
2424
sp = self.mltask_settings["splitParams"]
2525
sp["ttPolicy"] = "SPLIT_SINGLE_DATASET"
@@ -40,8 +40,8 @@ def set_split_kfold(self, n_folds = 5, selection = None, dataset_name=None):
4040
Sets the train/test split to k-fold splitting of an extract of a single dataset
4141
4242
:param int n_folds: number of folds. Must be greater than 0
43-
:param object selection: A :class:`DSSDatasetSelectionBuilder` to build the settings of the extract of the dataset. May be None (won't be changed)
44-
:param str dataset_name: Name of dataset to split. If None, the main dataset used to create the ML Task will be used.
43+
:param object selection: A :class:`~dataikuapi.dss.utils.DSSDatasetSelectionBuilder` to build the settings of the extract of the dataset. May be None (won't be changed)
44+
:param str dataset_name: Name of dataset to split. If None, the main dataset used to create the visual analysis will be used.
4545
"""
4646
sp = self.mltask_settings["splitParams"]
4747
sp["ttPolicy"] = "SPLIT_SINGLE_DATASET"
@@ -59,14 +59,14 @@ def set_split_kfold(self, n_folds = 5, selection = None, dataset_name=None):
5959

6060
def set_split_explicit(self, train_selection, test_selection, dataset_name=None, test_dataset_name=None, train_filter=None, test_filter=None):
6161
"""
62-
Sets the train/test split to explicit extract of one or two dataset
62+
Sets the train/test split to explicit extract of one or two dataset(s)
6363
64-
:param object train_selection: A :class:`DSSDatasetSelectionBuilder` to build the settings of the extract of the train dataset. May be None (won't be changed)
65-
:param object test_selection: A :class:`DSSDatasetSelectionBuilder` to build the settings of the extract of the test dataset. May be None (won't be changed)
64+
:param object train_selection: A :class:`~dataikuapi.dss.utils.DSSDatasetSelectionBuilder` to build the settings of the extract of the train dataset. May be None (won't be changed)
65+
:param object test_selection: A :class:`~dataikuapi.dss.utils.DSSDatasetSelectionBuilder` to build the settings of the extract of the test dataset. May be None (won't be changed)
6666
:param str dataset_name: Name of dataset to use for the extracts. If None, the main dataset used to create the ML Task will be used.
6767
:param str test_dataset_name: Name of a second dataset to use for the test data extract. If None, both extracts are done from dataset_name
68-
:param object train_filter: A :class:`DSSFilterBuilder` to build the settings of the filter of the train dataset. May be None (won't be changed)
69-
:param object test_filter: A :class:`DSSFilterBuilder` to build the settings of the filter of the test dataset. May be None (won't be changed)
68+
:param object train_filter: A :class:`~dataikuapi.dss.utils.DSSFilterBuilder` to build the settings of the filter of the train dataset. May be None (won't be changed)
69+
:param object test_filter: A :class:`~dataikuapi.dss.utils.DSSFilterBuilder` to build the settings of the filter of the test dataset. May be None (won't be changed)
7070
"""
7171
sp = self.mltask_settings["splitParams"]
7272
if dataset_name is None:
@@ -206,8 +206,15 @@ def get_algorithm_settings(self, algorithm_name):
206206
Gets the training settings for a particular algorithm. This returns a reference to the
207207
algorithm's settings, not a copy, so changes made to the returned object will be reflected when saving.
208208
209-
All algorithms have at least an "enabled" setting. Other settings are algorithm-dependent. You can print
210-
the returned object to learn more about the settings of each particular algorithm
209+
This method returns a dictionary of the settings for this algorithm.
210+
All algorithm dicts have at least an "enabled" key in the dictionary.
211+
The 'enabled' key indicates whether this algorithm will be trained
212+
213+
Other settings are algorithm-dependent and are the various hyperparameters of the
214+
algorithm. The precise keys for each algorithm are not all documented. You can print
215+
the returned dictionary to learn more about the settings of each particular algorithm
216+
217+
Please refer to the documentation for details on available algorithms.
211218
212219
:param str algorithm_name: Name (in capitals) of the algorithm.
213220
:return: A dict of the settings for an algorithm
@@ -220,17 +227,19 @@ def get_algorithm_settings(self, algorithm_name):
220227

221228
def set_algorithm_enabled(self, algorithm_name, enabled):
222229
"""
223-
Enables or disables an algorithm.
230+
Enables or disables an algorithm based on its name.
231+
232+
Please refer to the documentation for details on available algorithms.
224233
225234
:param str algorithm_name: Name (in capitals) of the algorithm.
226235
"""
227236
self.get_algorithm_settings(algorithm_name)["enabled"] = enabled
228237

229238
def set_metric(self, metric=None, custom_metric=None, custom_metric_greater_is_better=True, custom_metric_use_probas=False):
230239
"""
231-
Set a metric on a prediction ML task
240+
Sets the score metric to optimize for a prediction ML Task
232241
233-
:param str metric: metric to use. Leave empty for custom_metric
242+
:param str metric: metric to use. Leave empty to use a custom metric. You need to set the ``custom_metric`` value in that case
234243
:param str custom_metric: code of the custom metric
235244
:param bool custom_metric_greater_is_better: whether the custom metric is a score or a loss
236245
:param bool custom_metric_use_probas: whether to use the classes' probas or the predicted value (for classification)
@@ -778,7 +787,7 @@ def start_ensembling(self, model_ids=[], method=None):
778787
:param list model_ids: A list of model identifiers
779788
:param str method: the ensembling method (AVERAGE, PROBA_AVERAGE, MEDIAN, VOTE, LINEAR_MODEL, LOGISTIC_MODEL)
780789
781-
This returns immediately, before train is complete. To wait for train to complete, use ``wait_train_complete()``
790+
This returns immediately, before train is complete. To wait for train to complete, use :meth:`wait_train_complete`
782791
783792
:return: the model identifier of the ensemble
784793
:rtype: string
@@ -794,7 +803,7 @@ def start_ensembling(self, model_ids=[], method=None):
794803

795804
def wait_train_complete(self):
796805
"""
797-
Waits for train to be complete.
806+
Waits for train to be complete (if started with :meth:`start_train`)
798807
"""
799808
while True:
800809
status = self.get_status()
@@ -807,7 +816,7 @@ def get_trained_models_ids(self, session_id=None, algorithm=None):
807816
"""
808817
Gets the list of trained model identifiers for this ML task.
809818
810-
These identifiers can be used for ``get_trained_model_snippet`` and ``deploy_to_flow``
819+
These identifiers can be used for :meth:`get_trained_model_snippet` and :meth:`deploy_to_flow`
811820
812821
:return: A list of model identifiers
813822
:rtype: list of strings
@@ -824,7 +833,7 @@ def get_trained_models_ids(self, session_id=None, algorithm=None):
824833

825834
def get_trained_model_snippet(self, id=None, ids=None):
826835
"""
827-
Gets a quick summary of a trained model, as a dict. For complete information and a structured object, use :meth:get_trained_model_details
836+
Gets a quick summary of a trained model, as a dict. For complete information and a structured object, use :meth:`get_trained_model_detail`
828837
829838
:param str id: a model id
830839
:param list ids: a list of model ids
@@ -856,14 +865,13 @@ def get_trained_model_details(self, id):
856865
857866
:param str id: Identifier of the trained model, as returned by :meth:`get_trained_models_ids`
858867
859-
:return: A :class:`DSSTrainedModelDetails` representing the details of this trained model id
860-
:rtype: :class:`DSSTrainedModelDetails`
868+
:return: A :class:`DSSTrainedPredictionModelDetails` or :class:`DSSTrainedClusteringModelDetails` representing the details of this trained model id
869+
:rtype: :class:`DSSTrainedPredictionModelDetails` or :class:`DSSTrainedClusteringModelDetails`
861870
"""
862871
ret = self.client._perform_json(
863872
"GET", "/projects/%s/models/lab/%s/%s/models/%s/details" % (self.project_key, self.analysis_id, self.mltask_id,id))
864873
snippet = self.get_trained_model_snippet(id)
865874

866-
867875
if "facts" in ret:
868876
return DSSTrainedClusteringModelDetails(ret, snippet, mltask=self, mltask_model_id=id)
869877
else:

0 commit comments

Comments
 (0)