Skip to content

Cycle

This page describes how to manage cycles in Taipy.

A Scenario in Taipy represents an instance of a business case that an end-user wants to analyze, simulate, compare or solve. Some scenarios are recurrent and can be associated with a period of time called a Cycle. For example, a monthly scenario can model a sales forecast problem where some predictions must be published every month.

A Cycle represents a period of time associated with a scenario. Cycles are created and attached to scenarios at their creation.

Note

When creating multiple scenarios at the same time period, Taipy automatically re uses the existing cycle if it exists, and attaches the new scenario to it.

That means cycles are shared between multiple scenarios. For example, multiple sales forecast scenarios can be attached to the same monthly cycle. Each one forecasting sales under different conditions.

For more details on how recurrent scenarios, please refer to the recurrent scenarios page.

Cycle attributes

A cycle is identified by a unique identifier id that was generated by Taipy. A cycle also holds various attributes and properties, each accessible as an attribute of the cycle:

  • frequency corresponds to the cycle Frequency. It is populated at the cycle creation using the scenario frequency that triggered the cycle creation.
  • creation_date corresponds to the date-time of the creation of the cycle.
  • start_date corresponds to the date and time of the start of the cycle.
  • end_date corresponds to the date and time of the end of the cycle.
  • name corresponds to a human-readable name of the cycle.
  • Each property of the properties' dictionary is also directly exposed as an attribute.

Example

The code below uses the monthly_scenario_cfg configuration imported from the my_config.py module to show how to create a recurrent scenario attached to a cycle.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from datetime import datetime
import my_config
import taipy as tp

if __name__ == "__main__":
    # Create a scenario using the monthly scenario configuration.
    scenario = tp.create_scenario(my_config.monthly_scenario_cfg,
                                creation_date=datetime(2022, 1, 3))
    cycle = scenario.cycle

    # The frequency is an attribute of the cycle. In the example, it equals
    # Frequency.MONTHLY since my_config.monthly_scenario_cfg is used has been
    # used to instantiate scenario and cycle.
    cycle.frequency
    # The creation date is the date-time provided at the creation. It equals datetime(2022, 1, 3)
    cycle.creation_date
    # The start date is the date-time of the start of the cycle. It equals datetime(2022, 1, 1)
    cycle.start_date
    # The end date is the date-time of the end of the cycle. It equals datetime(2022, 1, 31)
    cycle.end_date
    # By default, the `name` is generated. It can be set manually to be displayed in a user interface.
    cycle.name = "January cycle"

The scenario configuration has a monthly frequency, so the scenario is associated with the monthly cycle corresponding to the month of the scenario creation date.

Get cycles

Get by id

The basic method to get a cycle is from its id by using the taipy.get() method.

Get by scenario

A parent Cycle can be retrieved from a scenario by using the Scenario.cycle property.

Example

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

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

if __name__ == "__main__":
    # Create a scenario and the related cycle
    scenario = tp.create_scenario(my_config.monthly_scenario_cfg)

    # Retrieve the parent cycle of the scenario
    cycle = scenario.cycle

    # Get the cycle by its id
    cycle_retrieved = tp.get(cycle.id)

Here, cycle_retrieved equals cycle.

Here, the two variables cycle and cycle_retrieved are equal.

Get all cycles

All the cycles can be retrieved using the method taipy.get_cycles(). This method returns the list of all existing cycles.

Delete a cycle

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