Task configs

A task configuration is necessary to instantiate a Task. To create a TaskConfig, you can use the Config.configure_task() method with the following parameters:

  • id: The id of the task configuration to be created. This id is mandatory and must be a unique and valid Python identifier.
  • function: The function to execute.
  • inputs: The input data nodes referring to the function's parameter(s) data to be executed.
  • outputs: The output data nodes referring to the result(s) data of the function to be executed.
  • skippable: Boolean attribute indicating if the task execution can be skipped if all output data nodes are up-to-date (see the validity_period attribute in the Data node configs page for more details). The default value of skippable is False.

Here is a simple example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from taipy import Config


def double(nb):
    return nb * 2


input_data_node_cfg = Config.configure_data_node("input",
                                                 default_data=21)
output_data_node_cfg = Config.configure_data_node("output")

double_task_cfg = Config.configure_task("double_task",
                                        double,
                                        input_data_node_cfg,
                                        output_data_node_cfg,
                                        skippable=True)

In the example above, we created a TaskConfig named double_task_cfg.

In lines 4-5, we define a function double(), to be used in a Task instantiated from the task config. It takes a single parameter and returns a single value.

In lines 8-9, two data node configurations are created. They will be used respectively as argument and result of the function double().

Finally, on line 12-16, we create the task configuration with the id double_task. It represents the function double() that expects an input data node as a parameter and returns an output data node. On line 13, the Task configuration has been set as skippable. That means when submitting a Task entity instantiated from this TaskConfig, Taipy will skip its execution if its input data nodes haven't changed since the previous execution.

Because a Task can have several inputs and outputs, Config.configure_task() can receive lists of DataNodeConfig objects.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from taipy import Config


def multiply_and_add(nb1, nb2):
    return nb1 * nb2, nb1 + nb2


nb_1_cfg = Config.configure_data_node("nb_1", default_data=21)
nb_2_cfg = Config.configure_data_node("nb_2", default_data=2)

multiplication_cfg = Config.configure_data_node("multiplication")
addition_cfg = Config.configure_data_node("addition")

task_cfg = Config.configure_task("foo",
                                 multiply_and_add,
                                 [nb_1_cfg, nb_2_cfg],
                                 [multiplication_cfg, addition_cfg])

In lines 4-5, we define a function with two parameters and two return values.

In lines 8-9, two data nodes configurations are created. They will be used as the function arguments.

In lines 11-12, two data nodes are configured. They will be used as the function results.

Finally, in lines 14-17, we create the task configuration with the id foo representing the function multiply_and_add. It expects two input data nodes and two output data nodes.

The next section introduces the scenario configuration.