How to use the flytekit.models.common.FlyteIdlEntity function in flytekit

To help you get started, we’ve selected a few flytekit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lyft / flytekit / flytekit / models / sagemaker / parameter_ranges.py View on Github external
def to_flyte_idl(self):
        """
        :return: _idl_parameter_ranges.CategoricalParameterRange
        """
        return _idl_parameter_ranges.CategoricalParameterRange(
            values=self._values
        )

    @classmethod
    def from_flyte_idl(cls, pb2_object):
        return cls(
            values=pb2_object.values
        )


class ParameterRanges(_common.FlyteIdlEntity):
    def __init__(
            self,
            parameter_range_map,
    ):
        self._parameter_range_map = parameter_range_map

    def to_flyte_idl(self):
        return _idl_parameter_ranges.ParameterRanges(
            parameter_range_map=self._parameter_range_map,
        )

    @classmethod
    def from_flyte_idl(cls, pb2_object):
        return cls(
            parameter_range_map=pb2_object.parameter_range_map
        )
github lyft / flytekit / flytekit / models / common.py View on Github external
return _common_pb2.NamedEntityIdentifier(
            project=self.project,
            domain=self.domain,
            name=self.name
        )

    @classmethod
    def from_flyte_idl(cls, idl_object):
        """
        :param flyteidl.admin.common_pb2.NamedEntityIdentifier idl_object:
        :rtype: NamedEntityIdentifier
        """
        return cls(idl_object.project, idl_object.domain, idl_object.name)


class EmailNotification(FlyteIdlEntity):

    def __init__(self, recipients_email):
        """
        :param list[Text] recipients_email:
        """
        self._recipients_email = recipients_email

    @property
    def recipients_email(self):
        """
        :rtype: list[Text]
        """
        return self._recipients_email

    def to_flyte_idl(self):
        """
github lyft / flytekit / flytekit / models / core / workflow.py View on Github external
sub_workflow_ref=self.sub_workflow_ref.to_flyte_idl() if self.sub_workflow_ref else None
        )

    @classmethod
    def from_flyte_idl(cls, pb2_object):
        """
        :param flyteidl.core.workflow_pb2.WorkflowNode pb2_object:
        :rtype: WorkflowNode
        """
        if pb2_object.HasField('launchplan_ref'):
            return cls(launchplan_ref=_identifier.Identifier.from_flyte_idl(pb2_object.launchplan_ref))
        else:
            return cls(sub_workflow_ref=_identifier.Identifier.from_flyte_idl(pb2_object.sub_workflow_ref))


class WorkflowMetadata(_common.FlyteIdlEntity):

    class OnFailurePolicy(object):
        """
        Defines the execution behavior of the workflow when a failure is detected.

        Attributes:
            FAIL_IMMEDIATELY                        Instructs the system to fail as soon as a node fails in the
                                                    workflow. It'll automatically abort all currently running nodes and
                                                    clean up resources before finally marking the workflow executions as failed.

            FAIL_AFTER_EXECUTABLE_NODES_COMPLETE    Instructs the system to make as much progress as it can. The system
                                                    will not alter the dependencies of the execution graph so any node 
                                                    that depend on the failed node will not be run. Other nodes that will
                                                    be executed to completion before cleaning up resources and marking
                                                    the workflow execution as failed.
        """
github lyft / flytekit / flytekit / models / task.py View on Github external
return _admin_task.TaskClosure(
            compiled_task=self.compiled_task.to_flyte_idl()
        )

    @classmethod
    def from_flyte_idl(cls, pb2_object):
        """
        :param flyteidl.admin.task_pb2.TaskClosure pb2_object:
        :rtype: TaskClosure
        """
        return cls(
            compiled_task=CompiledTask.from_flyte_idl(pb2_object.compiled_task)
        )


class CompiledTask(_common.FlyteIdlEntity):

    def __init__(self, template):
        """
        :param TaskTemplate template:
        """
        self._template = template

    @property
    def template(self):
        """
        :rtype: TaskTemplate
        """
        return self._template

    def to_flyte_idl(self):
        """
github lyft / flytekit / flytekit / models / common.py View on Github external
return _json_format.Parse(_json.dumps(self.to_dict()), _struct.Struct())

    @_abc.abstractmethod
    def from_dict(self, idl_dict):
        pass

    @_abc.abstractmethod
    def to_dict(self):
        """
        Converts self to a dictionary.
        :rtype: dict[Text, T]
        """
        pass


class NamedEntityIdentifier(FlyteIdlEntity):

    def __init__(self, project, domain, name=None):
        """
        :param Text project: The name of the project in which this entity lives.
        :param Text domain: The name of the domain within the project.
        :param Text name: [Optional] The name of the entity within the namespace of the project and domain.
        """
        self._project = project
        self._domain = domain
        self._name = name

    @property
    def project(self):
        """
        The name of the project in which this entity lives.
        :rtype: Text
github lyft / flytekit / flytekit / models / core / workflow.py View on Github external
from __future__ import absolute_import

from flyteidl.core import workflow_pb2 as _core_workflow

from flytekit.models import common as _common, interface as _interface
from flytekit.models.core import identifier as _identifier, errors as _errors, condition as _condition
from flytekit.models.literals import RetryStrategy as _RetryStrategy, Binding as _Binding


class IfBlock(_common.FlyteIdlEntity):
    def __init__(self, condition, then_node):
        """
        Defines a condition and the execution unit that should be executed if the condition is satisfied.
        :param flytekit.models.core.condition.BooleanExpression condition:
        :param Node then_node:
        """

        self._condition = condition
        self._then_node = then_node

    @property
    def condition(self):
        """
        :rtype: flytekit.models.core.condition.BooleanExpression
        """
        return self._condition
github lyft / flytekit / flytekit / models / core / workflow.py View on Github external
:rtype: flyteidl.core.workflow_pb2.NodeMetadata
        """
        node_metadata = _core_workflow.NodeMetadata(name=self.name, retries=self.retries.to_flyte_idl(), interruptible=self.interruptible)
        node_metadata.timeout.FromTimedelta(self.timeout)
        return node_metadata

    @classmethod
    def from_flyte_idl(cls, pb2_object):
        return cls(
            pb2_object.name,
            pb2_object.timeout.ToTimedelta(),
            _RetryStrategy.from_flyte_idl(pb2_object.retries)
        )


class Node(_common.FlyteIdlEntity):

    def __init__(self, id, metadata, inputs, upstream_node_ids, output_aliases, task_node=None,
                 workflow_node=None, branch_node=None):
        """
        A Workflow graph Node. One unit of execution in the graph. Each node can be linked to a Task,
        a Workflow or a branch node.  One of the nodes must be specified.

        :param Text id: A workflow-level unique identifier that identifies this node in the workflow. "inputs" and
            "outputs" are reserved node ids that cannot be used by other nodes.
        :param NodeMetadata metadata: Extra metadata about the node.
        :param list[flytekit.models.literals.Binding] inputs: Specifies how to bind the underlying
            interface's inputs.  All required inputs specified in the underlying interface must be fulfilled.
        :param list[Text] upstream_node_ids: Specifies execution depdendency for this node ensuring it will
            only get scheduled to run after all its upstream nodes have completed. This node will have
            an implicit dependency on any node that appears in inputs field.
        :param list[Alias] output_aliases: A node can define aliases for a subset of its outputs. This
github lyft / flytekit / flytekit / models / admin / workflow.py View on Github external
from __future__ import absolute_import
from flytekit.models import common as _common
from flytekit.models.core import compiler as _compiler_models, identifier as _identifier, workflow as _core_workflow
from flyteidl.admin import workflow_pb2 as _admin_workflow


class WorkflowSpec(_common.FlyteIdlEntity):

    def __init__(self, template, sub_workflows):
        """
        This object fully encapsulates the specification of a workflow
        :param flytekit.models.core.workflow.WorkflowTemplate template:
        :param list[flytekit.models.core.workflow.WorkflowTemplate] sub_workflows:
        """
        self._template = template
        self._sub_workflows = sub_workflows

    @property
    def template(self):
        """
        :rtype: flytekit.models.core.workflow.WorkflowTemplate.WorkflowTemplate
        """
        return self._template
github lyft / flytekit / flytekit / models / sagemaker / hpo_job.py View on Github external
sdk_strategy = _sdk_sagemaker_types.HyperparameterTuningStrategy.RANDOM

        sdk_training_early_stopping_type = _sdk_sagemaker_types.TrainingJobEarlyStoppingType.OFF
        if pb2_object.training_job_early_stopping_type == _idl_hpo_job.HPOJobConfig.TrainingJobEarlyStoppingType.AUTO:
            sdk_training_early_stopping_type = _sdk_sagemaker_types.TrainingJobEarlyStoppingType.AUTO

        return cls(
            hyperparameter_ranges=(
                _model_parameter_ranges.ParameterRanges.from_flyte_idl(pb2_object.hyperparameter_ranges)),
            tuning_strategy=sdk_strategy,
            tuning_objective=HyperparameterTuningObjective.from_flyte_idl(pb2_object.tuning_objective),
            training_job_early_stopping_type=sdk_training_early_stopping_type,
        )


class HPOJob(_common.FlyteIdlEntity):

    def __init__(
            self,
            max_number_of_training_jobs,
            max_parallel_training_jobs,
            training_job,
    ):
        self._max_number_of_training_jobs = max_number_of_training_jobs
        self._max_parallel_training_jobs = max_parallel_training_jobs
        self._training_job = training_job

    @property
    def max_number_of_training_jobs(self):
        return self._max_number_of_training_jobs

    @property