How to use the flytekit.models.interface.Variable 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 / tests / flytekit / unit / common_tests / tasks / test_sdk_runnable.py View on Github external
None,
        None,
        None,
        None,
        None,
        None,
        None,
        None,
        None,
        False,
        None,
        {},
        None,
    )
    t.add_inputs({'value_in': interface.Variable(primitives.Integer.to_flyte_literal_type(), "")})
    t.add_outputs({'value_out': interface.Variable(primitives.Integer.to_flyte_literal_type(), "")})
    out = t.unit_test(value_in=1)
    assert out['value_out'] == 2

    with _pytest.raises(_user_exceptions.FlyteAssertion) as e:
        t()

    assert "value_in" in str(e.value)
    assert "INTEGER" in str(e.value)
github lyft / flytekit / tests / flytekit / unit / common_tests / test_workflow_promote.py View on Github external
    @_sdk_workflow.workflow_class()
    class TestPromoteExampleWf(object):
        wf_input = _sdk_workflow.Input(_Types.Integer, required=True)
        my_task_node = demo_task_for_promote(a=wf_input)
        wf_output_b = _sdk_workflow.Output(my_task_node.outputs.b, sdk_type=_Types.Integer)
        wf_output_c = _sdk_workflow.Output(my_task_node.outputs.c, sdk_type=_Types.Integer)

    # This section uses the TaskTemplate stored in Admin to promote back to an Sdk Workflow
    int_type = _types.LiteralType(_types.SimpleType.INTEGER)
    task_interface = _interface.TypedInterface(
        # inputs
        {'a': _interface.Variable(int_type, "description1")},
        # outputs
        {
            'b': _interface.Variable(int_type, "description2"),
            'c': _interface.Variable(int_type, "description3")
        }
    )
    # Since the promotion of a workflow requires retrieving the task from Admin, we mock the SdkTask to return
    task_template = _task_model.TaskTemplate(
        _identifier.Identifier(_identifier.ResourceType.TASK, "project", "domain",
                               "tests.flytekit.unit.common_tests.test_workflow_promote.demo_task_for_promote",
                               "version"),
        "python_container",
        get_sample_task_metadata(),
        task_interface,
        custom={},
        container=get_sample_container()
    )
    sdk_promoted_task = _task.SdkTask.promote_from_model(task_template)
    mock_task_fetch.return_value = sdk_promoted_task
github lyft / flytekit / tests / flytekit / unit / common_tests / tasks / mixins / executable_traits / test_notebooks.py View on Github external
from flytekit.models import interface
from flytekit.sdk import types
import six


GOOD_INPUTS = {
    'a': types.Types.Integer,
    'name': types.Types.String,
}
GOOD_OUTPUTS = {
    'x': types.Types.Integer,
}
GOOD_NOTEBOOK = sdk_runnable.RunnableNotebookTask(
    notebook_path="notebooks/good.ipynb",
    inputs={
        k: interface.Variable(
            helpers.python_std_to_sdk_type(v).to_flyte_literal_type(),
            ''
        )
        for k, v in six.iteritems(GOOD_INPUTS)
    },
    outputs={
        k: interface.Variable(
            helpers.python_std_to_sdk_type(v).to_flyte_literal_type(),
            ''
        )
        for k, v in six.iteritems(GOOD_OUTPUTS)
    },
    task_type=constants.SdkTaskType.PYTHON_TASK,
)
github lyft / flytekit / tests / flytekit / unit / models / test_workflow_closure.py View on Github external
def test_workflow_closure():
    int_type = _types.LiteralType(_types.SimpleType.INTEGER)
    typed_interface = _interface.TypedInterface(
        {'a': _interface.Variable(int_type, "description1")},
        {
            'b': _interface.Variable(int_type, "description2"),
            'c': _interface.Variable(int_type, "description3")
        }
    )

    b0 = _literals.Binding('a', _literals.BindingData(
        scalar=_literals.Scalar(primitive=_literals.Primitive(integer=5))))
    b1 = _literals.Binding('b', _literals.BindingData(
        promise=_types.OutputReference('my_node', 'b')))
    b2 = _literals.Binding('c', _literals.BindingData(
        promise=_types.OutputReference('my_node', 'c')))

    node_metadata = _workflow.NodeMetadata(
        name='node1',
        timeout=timedelta(seconds=10),
github lyft / flytekit / tests / flytekit / unit / models / core / test_workflow.py View on Github external
def test_workflow_template():
    task = _workflow.TaskNode(reference_id=_generic_id)
    nm = _get_sample_node_metadata()
    int_type = _types.LiteralType(_types.SimpleType.INTEGER)
    wf_metadata = _workflow.WorkflowMetadata()
    wf_metadata_defaults = _workflow.WorkflowMetadataDefaults()
    typed_interface = _interface.TypedInterface(
        {'a': _interface.Variable(int_type, "description1")},
        {
            'b': _interface.Variable(int_type, "description2"),
            'c': _interface.Variable(int_type, "description3")
        }
    )
    wf_node = _workflow.Node(
        id='some:node:id',
        metadata=nm,
        inputs=[],
        upstream_node_ids=[],
        output_aliases=[],
        task_node=task
    )
    obj = _workflow.WorkflowTemplate(
        id=_generic_id,
        metadata=wf_metadata,
github lyft / flytekit / tests / flytekit / unit / models / core / test_workflow.py View on Github external
def test_workflow_template():
    task = _workflow.TaskNode(reference_id=_generic_id)
    nm = _get_sample_node_metadata()
    int_type = _types.LiteralType(_types.SimpleType.INTEGER)
    wf_metadata = _workflow.WorkflowMetadata()
    wf_metadata_defaults = _workflow.WorkflowMetadataDefaults()
    typed_interface = _interface.TypedInterface(
        {'a': _interface.Variable(int_type, "description1")},
        {
            'b': _interface.Variable(int_type, "description2"),
            'c': _interface.Variable(int_type, "description3")
        }
    )
    wf_node = _workflow.Node(
        id='some:node:id',
        metadata=nm,
        inputs=[],
        upstream_node_ids=[],
        output_aliases=[],
        task_node=task
    )
    obj = _workflow.WorkflowTemplate(
        id=_generic_id,
        metadata=wf_metadata, 
        metadata_defaults=wf_metadata_defaults,
        interface=typed_interface,
        nodes=[wf_node],
github lyft / flytekit / flytekit / common / tasks / raw_container.py View on Github external
def types_to_variable(t: Dict[str, FlyteSdkType]) -> Dict[str, Variable]:
    var = {}
    if t:
        for k, v in t.items():
            var[k] = Variable(v.to_flyte_literal_type(), "")
    return var
github lyft / flytekit / flytekit / common / tasks / sagemaker / hpo_job_task.py View on Github external
metadata=_task_models.TaskMetadata(
                runtime=_task_models.RuntimeMetadata(
                    type=_task_models.RuntimeMetadata.RuntimeType.FLYTE_SDK,
                    version=__version__,
                    flavor='sagemaker'
                ),
                discoverable=cacheable,
                timeout=timeout,
                retries=_literal_models.RetryStrategy(retries=retries),
                interruptible=interruptible,
                discovery_version=cache_version,
                deprecated_error_message="",
            ),
            interface=_interface.TypedInterface(
                inputs={
                    "hpo_job_config": _interface_model.Variable(
                        _sdk_types.Types.Proto(_hpo_job_pb2.HPOJobConfig).to_flyte_literal_type(), ""
                    ),
                },
                outputs={
                    "model": _interface_model.Variable(
                        type=_idl_types.LiteralType(
                            blob=_core_types.BlobType(
                                format="",
                                dimensionality=_core_types.BlobType.BlobDimensionality.SINGLE
                            )
                        ),
                        description=""
                    )
                }
            ),
            custom=MessageToDict(hpo_job),
github lyft / flytekit / flytekit / common / tasks / sagemaker / hpo_job_task.py View on Github external
),
                discoverable=cacheable,
                timeout=timeout,
                retries=_literal_models.RetryStrategy(retries=retries),
                interruptible=interruptible,
                discovery_version=cache_version,
                deprecated_error_message="",
            ),
            interface=_interface.TypedInterface(
                inputs={
                    "hpo_job_config": _interface_model.Variable(
                        _sdk_types.Types.Proto(_hpo_job_pb2.HPOJobConfig).to_flyte_literal_type(), ""
                    ),
                },
                outputs={
                    "model": _interface_model.Variable(
                        type=_idl_types.LiteralType(
                            blob=_core_types.BlobType(
                                format="",
                                dimensionality=_core_types.BlobType.BlobDimensionality.SINGLE
                            )
                        ),
                        description=""
                    )
                }
            ),
            custom=MessageToDict(hpo_job),
        )

        self.add_inputs(training_job.interface.inputs)
github lyft / flytekit / flytekit / common / workflow.py View on Github external
:param Text name:
        :param T value:
        :param U sdk_type: If specified, the value provided must cast to this type.  Normally should be an instance of
            flytekit.common.types.base_sdk_types.FlyteSdkType.  But could also be something like:

            list[flytekit.common.types.base_sdk_types.FlyteSdkType],
            dict[flytekit.common.types.base_sdk_types.FlyteSdkType,flytekit.common.types.base_sdk_types.FlyteSdkType],
            (flytekit.common.types.base_sdk_types.FlyteSdkType, flytekit.common.types.base_sdk_types.FlyteSdkType, ...)
        """
        if sdk_type is None:
            # This syntax didn't work for some reason: sdk_type = sdk_type or Output._infer_type(value)
            sdk_type = Output._infer_type(value)
        sdk_type = _type_helpers.python_std_to_sdk_type(sdk_type)

        self._binding_data = _interface.BindingData.from_python_std(sdk_type.to_flyte_literal_type(), value)
        self._var = _interface_models.Variable(sdk_type.to_flyte_literal_type(), help or '')
        self._name = name