Skip to content

Sequence

This page describes how to manage sequences in Taipy. It explains how to create, submit and use sequences.

A Sequence in Taipy is an attribute of a scenario. It is a submittable entity that represents a subset of scenario tasks that can be executed together, independently of the other scenario's tasks.

The sequences can be created directly on scenario instances, at run time, but they can also be describes in the scenario configurations, so they are created along with the scenario creation.

Sequence creation

A sequence can be created directly on a scenario instance using the Scenario.add_sequence() method.

Example

The code below uses the monthly_scenario_cfg configuration imported from the my_config.py module to demonstrate how to create a sequence on a scenario.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import taipy as tp
import my_config

if __name__ == "__main__":
    # Create a scenario from the monthly scenario configuration
    scenario = tp.create_scenario(my_config.monthly_scenario_cfg)
    # Get the training task from the scenario
    training_task = scenario.training

    # Add a new sequence made of one single task: the training task
    sequence = scenario.add_sequence(name="training_sequence", tasks=[training_task])

Sequences can also be created along with the scenario creation by providing the sequences description in the scenario configuration. For more details, see the scenario configuration page.

Graphical User Interface

Taipy offers visual elements dedicated to scenario management. These elements are designed to help end-users select, visualize, and edit scenarios in an intuitive way.

In particular, the scenario visual element is designed to help end-users create, submit, and delete scenarios' sequences.

For more details and examples, see the scenario visual elements section.

Sequence attributes

A Sequence is identified by a unique identifier id that Taipy generates. It also holds various properties accessible as an attribute of the sequence:

  • subscribers: The list of Tuples (callback, params) representing the subscribers.
  • properties: The complete dictionary of the sequence properties. It includes a copy of the properties of the sequence configuration, in addition to the properties provided at the creation and runtime.
  • tasks: The dictionary holds the sequence's various tasks. The key corresponds to the config_id of the task while the value is the task itself.
  • data_nodes: The dictionary holding the various data nodes of the sequence. The key corresponds to the data node's config_id (while the value is the data node itself).
  • owner_id: The identifier of the owner, which can be a scenario, cycle, or None.
  • version: The string indicates the application version of the sequence to instantiate. If not provided, the current version is used. For more details, refer to version management.
  • Each property of the properties dictionary is also directly exposed as an attribute.
  • Each nested entity is also exposed as an attribute of the sequence. The attribute name corresponds to the config_id of the nested entity.

Example

The code below uses the monthly_scenario_cfg configuration imported from the my_config.py module to show the various attributes of a sequence.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import taipy as tp
import my_config

if __name__ == "__main__":
    # Create a scenario
    scenario = tp.create_scenario(my_config.monthly_scenario_cfg,
                                name="Monthly scenario")
    # Get the sequence created along with the scenario
    sales_sequence = scenario.sales_sequence
    sales_sequence.name = "Sequence for sales prediction"

    # There was no subscription, so subscribers is an empty list
    sales_sequence.subscribers # []

    # The properties dictionary equals {"name": "Sequence for sales prediction"}. It
    # contains all the properties, including the `name` provided at the creation
    sales_sequence.properties # {"name": "Sequence for sales prediction"}

    # The `name` property is also exposed directly as an attribute. It
    # equals "Sequence for sales prediction"
    sales_sequence.name

    # The training task entity is exposed as an attribute of the sequence
    training_task = sales_sequence.training

    # The predicting task entity as well
    predicting_task = sales_sequence.predicting

    # The data nodes are also exposed as attributes of the sequence.
    current_month_data_node = sales_sequence.current_month

Get Sequences

Get by id

The first method to get a sequence is from its id by using the taipy.get() method:

Example

The code below uses the monthly_scenario_cfg configuration imported from the my_config.py module to show how to get a sequence from its id.

1
2
3
4
5
6
7
8
import taipy as tp
import my_config

if __name__ == "__main__":
    scenario = tp.create_scenario(my_config.monthly_scenario_cfg)
    sequence = scenario.sales_sequence

    sequence_retrieved = tp.get(sequence.id)

Here, sequence_retrieved equals sequence.

Get from parents

All sequences that are part of a scenario can be directly accessed as attributes:

Example

The code below uses the monthly_scenario_cfg configuration imported from the my_config.py module to show how to get a sequence from its parent scenario.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import taipy as tp
import my_config

if __name__ == "__main__":
    # Create a scenario from the monthly scenario configuration
    scenario = tp.create_scenario(my_config.monthly_scenario_cfg)

    # Get the sequences from the scenario
    # sequences contains two sequences, as described in the monthly
    # scenario configuration
    sequences = scenario.sequences

Get all sequences

All the existing sequences can be retrieved using the method taipy.get_sequences(). This method returns the list of all existing sequences for all scenarios.

Example

The code below uses the monthly_scenario_cfg configuration imported from the my_config.py module to show how to retrieve all sequences.

1
2
3
4
import taipy as tp

# Retrieve all sequences
tasks = tp.get_sequences()

Delete a sequence

A sequence can be deleted by using taipy.delete() which takes the sequence id as a parameter. The deletion is also propagated to the nested tasks, data nodes, and jobs if they are not shared with any other sequence.

Get parent scenarios

To get the parent entities of a sequence (i.e., scenarios) you can use either the method Sequence.get_parents() or the static function taipy.get_parents(). Both return the parents of the sequence.

Example

The code below uses the monthly_scenario_cfg configuration imported from the my_config.py module to show how to get the parent scenarios of a sequence.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
import taipy as tp
import my_config

if __name__ == "__main__":
    # Create a scenario from a config
    scenario = tp.create_scenario(my_config.monthly_scenario_cfg,
                                name="Scenario 1")

    # Retrieve a sequence
    sequence = scenario.sales_sequence_cfg

    # Retrieve the parent entities of the sequence
    parent_entities = sequence.get_parents()  # {'scenarios': [Scenario 1]}

    # Retrieve the parent entities of the sequence
    tp.get_parents(sequence)  # {'scenarios': [Scenario 1]}