flytekit.core.array_node_map_task
| Method |
Description |
array_node_map_task() |
Map task that uses the ArrayNode construct. |
map_task() |
Wrapper that creates a map task utilizing either the existing ArrayNodeMapTask. |
| Property |
Type |
Description |
TYPE_CHECKING |
bool |
|
def array_node_map_task(
task_function: flytekit.core.python_function_task.PythonFunctionTask,
concurrency: typing.Optional[int],
min_success_ratio: float,
kwargs,
)
Map task that uses the ArrayNode construct..
This is an experimental drop-in replacement for flytekit.map_task.
| Parameter |
Type |
Description |
task_function |
flytekit.core.python_function_task.PythonFunctionTask |
This argument is implicitly passed and represents the repeatable function |
concurrency |
typing.Optional[int] |
If specified, this limits the number of mapped tasks than can run in parallel to the given batch size. If the size of the input exceeds the concurrency value, then multiple batches will be run serially until all inputs are processed. If set to 0, this means unbounded concurrency. If left unspecified, this means the array node will inherit parallelism from the workflow |
min_success_ratio |
float |
If specified, this determines the minimum fraction of total jobs which can complete successfully before terminating this task and marking it successful. |
kwargs |
**kwargs |
|
def map_task(
target: typing.Union[flytekit.core.launch_plan.LaunchPlan, flytekit.core.python_function_task.PythonFunctionTask, ForwardRef('FlyteLaunchPlan')],
concurrency: typing.Optional[int],
min_successes: typing.Optional[int],
min_success_ratio: float,
kwargs,
)
Wrapper that creates a map task utilizing either the existing ArrayNodeMapTask
or the drop in replacement ArrayNode implementation
| Parameter |
Type |
Description |
target |
typing.Union[flytekit.core.launch_plan.LaunchPlan, flytekit.core.python_function_task.PythonFunctionTask, ForwardRef('FlyteLaunchPlan')] |
The Flyte entity of which will be mapped over |
concurrency |
typing.Optional[int] |
If specified, this limits the number of mapped tasks than can run in parallel to the given batch size. If the size of the input exceeds the concurrency value, then multiple batches will be run serially until all inputs are processed. If set to 0, this means unbounded concurrency. If left unspecified, this means the array node will inherit parallelism from the workflow |
min_successes |
typing.Optional[int] |
The minimum number of successful executions |
min_success_ratio |
float |
The minimum ratio of successful executions |
kwargs |
**kwargs |
|
class ArrayNodeMapTask(
python_function_task: typing.Union[flytekit.core.python_function_task.PythonFunctionTask, flytekit.core.python_function_task.PythonInstanceTask, functools.partial],
concurrency: typing.Optional[int],
min_successes: typing.Optional[int],
min_success_ratio: typing.Optional[float],
bound_inputs: typing.Optional[typing.Set[str]],
bound_inputs_values: typing.Optional[typing.Dict[str, typing.Any]],
kwargs,
)
| Parameter |
Type |
Description |
python_function_task |
typing.Union[flytekit.core.python_function_task.PythonFunctionTask, flytekit.core.python_function_task.PythonInstanceTask, functools.partial] |
The task to be executed in parallel |
concurrency |
typing.Optional[int] |
The number of parallel executions to run |
min_successes |
typing.Optional[int] |
The minimum number of successful executions |
min_success_ratio |
typing.Optional[float] |
The minimum ratio of successful executions |
bound_inputs |
typing.Optional[typing.Set[str]] |
The set of inputs that should be bound to the map task |
bound_inputs_values |
typing.Optional[typing.Dict[str, typing.Any]] |
Inputs that are bound to the array node and will not be mapped over |
kwargs |
**kwargs |
Additional keyword arguments to pass to the base class |
| Property |
Type |
Description |
bound_inputs |
None |
|
concurrency |
None |
|
deck_fields |
None |
If not empty, this task will output deck html file for the specified decks |
disable_deck |
None |
If true, this task will not output deck html file |
docs |
None |
|
enable_deck |
None |
If true, this task will output deck html file |
environment |
None |
Any environment variables that supplied during the execution of the task. |
execution_mode |
None |
|
instantiated_in |
None |
|
interface |
None |
|
is_original_sub_node_interface |
None |
|
lhs |
None |
|
location |
None |
|
metadata |
None |
|
min_success_ratio |
None |
|
min_successes |
None |
|
name |
None |
|
python_function_task |
None |
|
python_interface |
None |
Returns this task’s python interface. |
security_context |
None |
|
task_config |
None |
Returns the user-specified task config which is used for plugin-specific handling of the task. |
task_type |
None |
|
task_type_version |
None |
|
| Method |
Description |
compile() |
Generates a node that encapsulates this task in a workflow definition. |
construct_node_metadata() |
This returns metadata for the parent ArrayNode, not the sub-node getting mapped over. |
dispatch_execute() |
This method translates Flyte’s Type system based input values and invokes the actual call to the executor. |
execute() |
This method will be invoked to execute the task. |
find_lhs() |
|
get_command() |
TODO ADD bound variables to the resolver. |
get_config() |
Returns the task config as a serializable dictionary. |
get_container() |
Returns the container definition (if any) that is used to run the task on hosted Flyte. |
get_custom() |
Return additional plugin-specific custom data (if any) as a serializable dictionary. |
get_extended_resources() |
Returns the extended resources to allocate to the task on hosted Flyte. |
get_input_types() |
Returns the names and python types as a dictionary for the inputs of this task. |
get_k8s_pod() |
Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte. |
get_sql() |
Returns the Sql definition (if any) that is used to run the task on hosted Flyte. |
get_type_for_input_var() |
Returns the python type for an input variable by name. |
get_type_for_output_var() |
We override this method from flytekit. |
local_execute() |
This function is used only in the local execution path and is responsible for calling dispatch execute. |
local_execution_mode() |
|
post_execute() |
Post execute is called after the execution has completed, with the user_params and can be used to clean-up,. |
pre_execute() |
This is the method that will be invoked directly before executing the task method and before all the inputs. |
prepare_target() |
Alters the underlying run_task command to modify it for map task execution and then resets it after. |
sandbox_execute() |
Call dispatch_execute, in the context of a local sandbox execution. |
set_command_prefix() |
|
def compile(
ctx: flytekit.core.context_manager.FlyteContext,
args,
kwargs,
) -> typing.Union[typing.Tuple[flytekit.core.promise.Promise], flytekit.core.promise.Promise, flytekit.core.promise.VoidPromise, NoneType]
Generates a node that encapsulates this task in a workflow definition.
| Parameter |
Type |
Description |
ctx |
flytekit.core.context_manager.FlyteContext |
|
args |
*args |
|
kwargs |
**kwargs |
|
def construct_node_metadata()
This returns metadata for the parent ArrayNode, not the sub-node getting mapped over
def dispatch_execute(
ctx: flytekit.core.context_manager.FlyteContext,
input_literal_map: flytekit.models.literals.LiteralMap,
) -> typing.Union[flytekit.models.literals.LiteralMap, flytekit.models.dynamic_job.DynamicJobSpec, typing.Coroutine]
This method translates Flyte’s Type system based input values and invokes the actual call to the executor
This method is also invoked during runtime.
VoidPromise is returned in the case when the task itself declares no outputs.
Literal Map is returned when the task returns either one more outputs in the declaration. Individual outputs
may be none
DynamicJobSpec is returned when a dynamic workflow is executed
| Parameter |
Type |
Description |
ctx |
flytekit.core.context_manager.FlyteContext |
|
input_literal_map |
flytekit.models.literals.LiteralMap |
|
def execute(
kwargs,
) -> typing.Any
This method will be invoked to execute the task.
| Parameter |
Type |
Description |
kwargs |
**kwargs |
|
def get_command(
settings: flytekit.configuration.SerializationSettings,
) -> typing.List[str]
TODO ADD bound variables to the resolver. Maybe we need a different resolver?
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
def get_config(
settings: flytekit.configuration.SerializationSettings,
) -> typing.Optional[typing.Dict[str, str]]
Returns the task config as a serializable dictionary. This task config consists of metadata about the custom
defined for this task.
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
def get_container(
settings: flytekit.configuration.SerializationSettings,
) -> flytekit.models.task.Container
Returns the container definition (if any) that is used to run the task on hosted Flyte.
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
def get_custom(
settings: flytekit.configuration.SerializationSettings,
) -> typing.Dict[str, typing.Any]
Return additional plugin-specific custom data (if any) as a serializable dictionary.
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
def get_extended_resources(
settings: flytekit.configuration.SerializationSettings,
) -> typing.Optional[flyteidl.core.tasks_pb2.ExtendedResources]
Returns the extended resources to allocate to the task on hosted Flyte.
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
Returns the names and python types as a dictionary for the inputs of this task.
def get_k8s_pod(
settings: flytekit.configuration.SerializationSettings,
) -> flytekit.models.task.K8sPod
Returns the kubernetes pod definition (if any) that is used to run the task on hosted Flyte.
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
def get_sql(
settings: flytekit.configuration.SerializationSettings,
) -> flytekit.models.task.Sql
Returns the Sql definition (if any) that is used to run the task on hosted Flyte.
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
def get_type_for_input_var(
k: str,
v: typing.Any,
) -> typing.Type[typing.Any]
Returns the python type for an input variable by name.
| Parameter |
Type |
Description |
k |
str |
|
v |
typing.Any |
|
def get_type_for_output_var(
k: str,
v: typing.Any,
) -> type
We override this method from flytekit.core.base_task Task because the dispatch_execute method uses this
interface to construct outputs. Each instance of an container_array task will however produce outputs
according to the underlying run_task interface and the array plugin handler will actually create a collection
from these individual outputs as the final output value.
| Parameter |
Type |
Description |
k |
str |
|
v |
typing.Any |
|
def local_execute(
ctx: flytekit.core.context_manager.FlyteContext,
kwargs,
) -> typing.Union[typing.Tuple[flytekit.core.promise.Promise], flytekit.core.promise.Promise, flytekit.core.promise.VoidPromise, typing.Coroutine, NoneType]
This function is used only in the local execution path and is responsible for calling dispatch execute.
Use this function when calling a task with native values (or Promises containing Flyte literals derived from
Python native values).
| Parameter |
Type |
Description |
ctx |
flytekit.core.context_manager.FlyteContext |
|
kwargs |
**kwargs |
|
def local_execution_mode()
def post_execute(
user_params: typing.Optional[flytekit.core.context_manager.ExecutionParameters],
rval: typing.Any,
) -> typing.Any
Post execute is called after the execution has completed, with the user_params and can be used to clean-up,
or alter the outputs to match the intended tasks outputs. If not overridden, then this function is a No-op
| Parameter |
Type |
Description |
user_params |
typing.Optional[flytekit.core.context_manager.ExecutionParameters] |
are the modified user params as created during the pre_execute step |
rval |
typing.Any |
|
def pre_execute(
user_params: typing.Optional[flytekit.core.context_manager.ExecutionParameters],
) -> typing.Optional[flytekit.core.context_manager.ExecutionParameters]
This is the method that will be invoked directly before executing the task method and before all the inputs
are converted. One particular case where this is useful is if the context is to be modified for the user process
to get some user space parameters. This also ensures that things like SparkSession are already correctly
setup before the type transformers are called
This should return either the same context of the mutated context
| Parameter |
Type |
Description |
user_params |
typing.Optional[flytekit.core.context_manager.ExecutionParameters] |
|
Alters the underlying run_task command to modify it for map task execution and then resets it after.
def sandbox_execute(
ctx: flytekit.core.context_manager.FlyteContext,
input_literal_map: flytekit.models.literals.LiteralMap,
) -> flytekit.models.literals.LiteralMap
Call dispatch_execute, in the context of a local sandbox execution. Not invoked during runtime.
| Parameter |
Type |
Description |
ctx |
flytekit.core.context_manager.FlyteContext |
|
input_literal_map |
flytekit.models.literals.LiteralMap |
|
def set_command_prefix(
cmd: typing.Optional[typing.List[str]],
)
| Parameter |
Type |
Description |
cmd |
typing.Optional[typing.List[str]] |
|
Special resolver that is used for ArrayNodeMapTasks.
This exists because it is possible that ArrayNodeMapTasks are created using nested “partial” subtasks.
When a maptask is created its interface is interpolated from the interface of the subtask - the interpolation,
simply converts every input into a list/collection input.
For example:
interface -> (i: int, j: str) -> str => map_task interface -> (i: List[int], j: List[str]) -> List[str]
But in cases in which j is bound to a fixed value by using functools.partial we need a way to ensure that
the interface is not simply interpolated, but only the unbound inputs are interpolated.
def foo((i: int, j: str) -> str:
...
mt = map_task(functools.partial(foo, j=10))
print(mt.interface)
```
output:
(i: List[int], j: str) -> List[str]
But, at runtime this information is lost. To reconstruct this, we use ArrayNodeMapTaskResolver that records the "bound vars"
and then at runtime reconstructs the interface with this knowledge
```python
class ArrayNodeMapTaskResolver(
args,
kwargs,
)
| Parameter |
Type |
Description |
args |
*args |
|
kwargs |
**kwargs |
|
| Property |
Type |
Description |
instantiated_in |
None |
|
lhs |
None |
|
location |
None |
|
Future proof method. Just making it easy to access all tasks (Not required today as we auto register them)
def load_task(
loader_args: typing.List[str],
max_concurrency: int,
) -> flytekit.core.array_node_map_task.ArrayNodeMapTask
Loader args should be of the form
vars “var1,var2,..” resolver “resolver” [resolver_args]
| Parameter |
Type |
Description |
loader_args |
typing.List[str] |
|
max_concurrency |
int |
|
def loader_args(
settings: flytekit.configuration.SerializationSettings,
t: flytekit.core.array_node_map_task.ArrayNodeMapTask,
) -> typing.List[str]
Return a list of strings that can help identify the parameter Task
| Parameter |
Type |
Description |
settings |
flytekit.configuration.SerializationSettings |
|
t |
flytekit.core.array_node_map_task.ArrayNodeMapTask |
|
def task_name(
t: flytekit.core.base_task.Task,
) -> typing.Optional[str]
Overridable function that can optionally return a custom name for a given task
| Parameter |
Type |
Description |
t |
flytekit.core.base_task.Task |
|