Пример #1
0
    def delete_experiment(self, name, namespace=None):
        """Delete the Katib Experiment.

        :param name: Experiment name.
        :param namespace: Experiment namespace.
        If the namespace is None, it takes namespace from the Experiment object or "default".

        :return: Deleted Experiment object.
        :rtype: dict
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        try:
            return self.api_instance.delete_namespaced_custom_object(
                constants.KUBEFLOW_GROUP,
                constants.KATIB_VERSION,
                namespace,
                constants.EXPERIMENT_PLURAL,
                name,
                body=client.V1DeleteOptions())
        except client.rest.ApiException as e:
            raise RuntimeError(
                "Exception when calling CustomObjectsApi->delete_namespaced_custom_object:\
         %s\n" % e)
Пример #2
0
    def get_suggestion(self, name=None, namespace=None):
        """
        Get experiment's suggestion.
        If name is empty returns all suggestion in requested namespace.
        :param name: existing suggestion name optional
        :param namespace: defaults to current or default namespace
        :return: suggestion dict
        """

        if namespace is None:
            namespace = utils.get_default_target_namespace()

        if name:
            thread = self.api_instance.get_namespaced_custom_object(
                constants.KUBEFLOW_GROUP,
                constants.KATIB_VERSION,
                namespace,
                constants.SUGGESTION_PLURAL,
                name,
                async_req=True)

            katib_suggestion = None
            try:
                katib_suggestion = thread.get(constants.APISERVER_TIMEOUT)
            except multiprocessing.TimeoutError:
                raise RuntimeError("Timeout trying to get Katib suggestion")
            except client.rest.ApiException as e:
                raise RuntimeError(
                    "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\
          %s\n" % e)
            except Exception as e:
                raise RuntimeError(
                    "There was a problem to get suggestion {0} in namespace {1}. Exception: \
          {2} ".format(name, namespace, e))

        else:
            thread = self.api_instance.list_namespaced_custom_object(
                constants.KUBEFLOW_GROUP,
                constants.KATIB_VERSION,
                namespace,
                constants.SUGGESTION_PLURAL,
                async_req=True)

            katib_suggestion = None
            try:
                katib_suggestion = thread.get(constants.APISERVER_TIMEOUT)
            except multiprocessing.TimeoutError:
                raise RuntimeError("Timeout trying to get Katib suggestion")
            except client.rest.ApiException as e:
                raise RuntimeError(
                    "Exception when calling CustomObjectsApi->list_namespaced_custom_object:\
          %s\n" % e)
            except Exception as e:
                raise RuntimeError(
                    "There was a problem to get suggestions in namespace {0}. \
          Exception: {1} ".format(namespace, e))

        return katib_suggestion
Пример #3
0
    def get_experiment(self, name=None, namespace=None):
        """
        Get single experiment or all experiment
        :param name: existing experiment name optional
        :param namespace: defaults to current or default namespace
        :return: experiment dict
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        if name:
            thread = self.api_instance.get_namespaced_custom_object(
                constants.KUBEFLOW_GROUP,
                constants.KATIB_VERSION,
                namespace,
                constants.EXPERIMENT_PLURAL,
                name,
                async_req=True)

            katibexp = None
            try:
                katibexp = thread.get(constants.APISERVER_TIMEOUT)
            except multiprocessing.TimeoutError:
                raise RuntimeError("Timeout trying to get katib experiment.")
            except client.rest.ApiException as e:
                raise RuntimeError(
                    "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\
          %s\n" % e)
            except Exception as e:
                raise RuntimeError(
                    "There was a problem to get experiment {0} in namespace {1}. Exception: \
          {2} ".format(name, namespace, e))

        else:
            thread = self.api_instance.list_namespaced_custom_object(
                constants.KUBEFLOW_GROUP,
                constants.KATIB_VERSION,
                namespace,
                constants.EXPERIMENT_PLURAL,
                async_req=True)

            katibexp = None
            try:
                katibexp = thread.get(constants.APISERVER_TIMEOUT)
            except multiprocessing.TimeoutError:
                raise RuntimeError("Timeout trying to get Experiment.")
            except client.rest.ApiException as e:
                raise RuntimeError(
                    "Exception when calling CustomObjectsApi->list_namespaced_custom_object:\
          %s\n" % e)
            except Exception as e:
                raise RuntimeError(
                    "There was a problem to get experiment in namespace {0}. \
          Exception: {1} ".format(namespace, e))

        return katibexp
Пример #4
0
    def get_experiment_status(self, name, namespace=None):
        """Returns experiment status, such as Running, Failed or Succeeded.
        Args:
          :param name: An experiment name. required
          :param namespace: defaults to current or default namespace.
          :return: status str
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        katibexp = self.get_experiment(name, namespace=namespace)
        last_condition = katibexp.get("status", {}).get("conditions", [])[-1]
        return last_condition.get("type", "")
Пример #5
0
    def get_success_trial_details(self, name=None, namespace=None):
        """Get the Trial details that have succeeded for an Experiment.

        :param name: Experiment name.
        :param namespace: Experiment namespace.
        If the namespace is None, it takes namespace from the Experiment or "default".

        :return: Trial names with the hyperparameters and metrics.
        :type: list[dict]
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        thread = self.api_instance.list_namespaced_custom_object(
            constants.KUBEFLOW_GROUP,
            constants.KATIB_VERSION,
            namespace=namespace,
            plural=constants.TRIAL_PLURAL,
            async_req=True)

        katibtrial = None
        try:
            katibtrial = thread.get(constants.APISERVER_TIMEOUT)
            result = []
            for i in katibtrial.get("items"):
                output = {}
                if i.get("metadata",
                         {}).get("ownerReferences")[0].get("name") == name:
                    status = i.get("status", {}).get("conditions",
                                                     [])[-1].get("type")
                    if status == "Succeeded":
                        output["name"] = i.get("metadata", {}).get("name")
                        output["hyperparameters"] = i.get("spec", {}).get(
                            "parameterAssignments", [])
                        output["metrics"] = (i.get("status", {}).get(
                            "observation", {}).get("metrics", []))
                        result.append(output)
        except multiprocessing.TimeoutError:
            raise RuntimeError("Timeout trying to getkatib experiment.")
        except client.rest.ApiException as e:
            raise RuntimeError(
                "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\
          %s\n" % e)
        except Exception as e:
            raise RuntimeError(
                "There was a problem to get experiment {0} in namespace {1}. Exception: \
          {2} ".format(name, namespace, e))
        return result
Пример #6
0
    def get_experiment_status(self, name, namespace=None):
        """Get the Experiment current status.

        :param name: Experiment name.
        :param namespace: Experiment namespace.
        If the namespace is None, it takes "default" namespace.

        :return: Current Experiment status.
        :rtype: str
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        katibexp = self.get_experiment(name, namespace=namespace)
        last_condition = katibexp.get("status", {}).get("conditions", [])[-1]
        return last_condition.get("type", "")
Пример #7
0
    def get_optimal_hyperparameters(self, name=None, namespace=None):
        """
        Get status, currentOptimalTrial with parameterAssignments
        :param name: existing experiment name
        :param namespace: defaults to current or default namespace
        :return: dict with status, currentOptimalTrial with parameterAssignments of an experiment
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        katibexp = self.get_experiment(name, namespace=namespace)
        result = {}
        result["currentOptimalTrial"] = katibexp.get(
            "status", {}).get("currentOptimalTrial")

        return result
Пример #8
0
    def get_optimal_hyperparameters(self, name=None, namespace=None):
        """Get the current optimal Trial from the Experiment.

        :param name: Experiment name.
        :param namespace: Experiment namespace.

        :return: Current optimal Trial for the Experiment.
        :rtype: dict
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        katibexp = self.get_experiment(name, namespace=namespace)
        result = {}
        result["currentOptimalTrial"] = katibexp.get(
            "status", {}).get("currentOptimalTrial")

        return result
Пример #9
0
    def list_trials(self, name=None, namespace=None):
        """List all Experiment's Trials.

        :param name: Experiment name.
        :param namespace: Experiments namespace.
        If the namespace is None, it takes "default" namespace.

        :return: List of Trial names with the statuses.
        :rtype: list[dict]
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        thread = self.api_instance.list_namespaced_custom_object(
            constants.KUBEFLOW_GROUP,
            constants.KATIB_VERSION,
            namespace=namespace,
            plural=constants.TRIAL_PLURAL,
            async_req=True)

        katibtrial = None
        try:
            katibtrial = thread.get(constants.APISERVER_TIMEOUT)
            result = []
            for i in katibtrial.get("items"):
                output = {}
                if i.get("metadata",
                         {}).get("ownerReferences")[0].get("name") == name:
                    output["name"] = i.get("metadata", {}).get("name")
                    output["status"] = i.get("status",
                                             {}).get("conditions",
                                                     [])[-1].get("type")
                    result.append(output)
        except multiprocessing.TimeoutError:
            raise RuntimeError("Timeout trying to getkatib experiment.")
        except client.rest.ApiException as e:
            raise RuntimeError(
                "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\
          %s\n" % e)
        except Exception as e:
            raise RuntimeError(
                "There was a problem to get experiment {0} in namespace {1}. Exception: \
          {2} ".format(name, namespace, e))
        return result
Пример #10
0
    def list_trials(self, name=None, namespace=None):
        """
    Get trials of an experiment
    :param name: existing experiment name
    :param namespace: defaults to current or default namespace
    :return: trials name with status as list
    """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        thread = self.api_instance.list_namespaced_custom_object(
            constants.EXPERIMENT_GROUP,
            constants.EXPERIMENT_VERSION,
            namespace=namespace,
            plural=constants.TRIAL_PLURAL,
            async_req=True)

        katibtrial = None
        try:
            katibtrial = thread.get(constants.APISERVER_TIMEOUT)
            result = []
            for i in katibtrial.get("items"):
                output = {}
                if i.get("metadata",
                         {}).get("ownerReferences")[0].get("name") == name:
                    output["name"] = i.get("metadata", {}).get("name")
                    output["status"] = i.get("status",
                                             {}).get("conditions",
                                                     [])[-1].get("type")
                    result.append(output)
        except multiprocessing.TimeoutError:
            raise RuntimeError("Timeout trying to getkatib experiment.")
        except client.rest.ApiException as e:
            raise RuntimeError(
                "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\
          %s\n" % e)
        except Exception as e:
            raise RuntimeError(
                "There was a problem to get experiment {0} in namespace {1}. Exception: \
          {2} ".format(name, namespace, e))
        return result
Пример #11
0
    def list_trials(self, name=None, namespace=None):
        """List all Experiment's Trials.

        :param name: Experiment name.
        :param namespace: Experiments namespace.
        If the namespace is None, it takes "default" namespace.

        :return: List of Trial objects
        :rtype: list[V1beta1Trial]
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        thread = self.api_instance.list_namespaced_custom_object(
            constants.KUBEFLOW_GROUP,
            constants.KATIB_VERSION,
            namespace=namespace,
            plural=constants.TRIAL_PLURAL,
            async_req=True)

        katibtrial = None
        try:
            katibtrial = thread.get(constants.APISERVER_TIMEOUT)
            result = [
                self.api_client.deserialize(utils.FakeResponse(item),
                                            V1beta1Trial)
                for item in katibtrial.get("items")
            ]
        except multiprocessing.TimeoutError:
            raise RuntimeError("Timeout trying to getkatib experiment.")
        except client.rest.ApiException as e:
            raise RuntimeError(
                "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\
          %s\n" % e)
        except Exception as e:
            raise RuntimeError(
                "There was a problem to get experiment {0} in namespace {1}. Exception: \
          {2} ".format(name, namespace, e))
        return result
Пример #12
0
    def delete_experiment(self, name, namespace=None):
        """
        Delete experiment
        :param name: experiment name required
        :param namespace: defaults to current or default namespace
        :return: status dict
        """
        if namespace is None:
            namespace = utils.get_default_target_namespace()

        try:
            return self.api_instance.delete_namespaced_custom_object(
                constants.KUBEFLOW_GROUP,
                constants.KATIB_VERSION,
                namespace,
                constants.EXPERIMENT_PLURAL,
                name,
                body=client.V1DeleteOptions())
        except client.rest.ApiException as e:
            raise RuntimeError(
                "Exception when calling CustomObjectsApi->delete_namespaced_custom_object:\
         %s\n" % e)
Пример #13
0
    def get_suggestion(self, name=None, namespace=None):
        """Get the Katib Suggestion.

        :param name: Suggestion name.
        If the name is None returns all Suggestion in the namespace.
        :param namespace: Suggestion namespace.
        If the namespace is None, it takes namespace from the Suggestion object or "default".

        :return: Suggestion object.
        :rtype: dict
        """

        if namespace is None:
            namespace = utils.get_default_target_namespace()

        if name:
            thread = self.api_instance.get_namespaced_custom_object(
                constants.KUBEFLOW_GROUP,
                constants.KATIB_VERSION,
                namespace,
                constants.SUGGESTION_PLURAL,
                name,
                async_req=True)

            katib_suggestion = None
            try:
                katib_suggestion = thread.get(constants.APISERVER_TIMEOUT)
            except multiprocessing.TimeoutError:
                raise RuntimeError("Timeout trying to get Katib suggestion")
            except client.rest.ApiException as e:
                raise RuntimeError(
                    "Exception when calling CustomObjectsApi->get_namespaced_custom_object:\
          %s\n" % e)
            except Exception as e:
                raise RuntimeError(
                    "There was a problem to get suggestion {0} in namespace {1}. Exception: \
          {2} ".format(name, namespace, e))

        else:
            thread = self.api_instance.list_namespaced_custom_object(
                constants.KUBEFLOW_GROUP,
                constants.KATIB_VERSION,
                namespace,
                constants.SUGGESTION_PLURAL,
                async_req=True)

            katib_suggestion = None
            try:
                katib_suggestion = thread.get(constants.APISERVER_TIMEOUT)
            except multiprocessing.TimeoutError:
                raise RuntimeError("Timeout trying to get Katib suggestion")
            except client.rest.ApiException as e:
                raise RuntimeError(
                    "Exception when calling CustomObjectsApi->list_namespaced_custom_object:\
          %s\n" % e)
            except Exception as e:
                raise RuntimeError(
                    "There was a problem to get suggestions in namespace {0}. \
          Exception: {1} ".format(namespace, e))

        return katib_suggestion