The Scenarios

In today’s fast-paced business environment, decision-makers must quickly adapt to changing conditions and explore various scenarios to make informed choices. Taipy scenarios provide a a powerful way to execute and store runs of pipelines. It can instantiate different versions of a business problem with different assumptions. It enables users to perform impact analysis and what-if analysis, essential for strategic decision-making.

In this article, we’ll look closer at Taipy scenarios, their features, and their utility in decision-making.

Just as a reminder, Taipy scenarios are one the basic concepts of Taipy Core.

 

Taipy Scenarios: An Overview

A Taipy scenario represents a run that can be an instance of a business problem to solve on data and parameter sets.

Users can create, store, edit, and execute various scenarios within the same application, allowing for seamless analysis of different business problem instances. This flexibility is crucial for businesses that must analyze multiple scenarios with different assumptions to determine the best course of action.

Example: Monthly Production Planning

Consider a manufacturing company that needs to plan its monthly production based on sales forecasts. The end-user creates a scenario for January containing all the necessary data, and algorithms to compute predictions, make production decisions, and publish the January production orders.

Then, the end-user creates another scenario for February using the new information provided for that period. This process can be repeated monthly, allowing the company to adapt its production plans based on changing conditions and assumptions.

import taipy as tp
from datetime import datetime
import my_config

# Creating a scenario for January
january_scenario = tp.create_scenario(my_config.monthly_scenario_cfg,
                   creation_date=datetime(2023, 1, 1),
                   name="Scenario for January")

# Creating a scenario for February
february_scenario = tp.create_scenario(my_config.monthly_scenario_cfg,
                   creation_date=datetime(2023, 2, 1),
                   name="Scenario for February")

Scenarios

Taipy scenarios consist of one or more sets of tasks designed to perform a set of functions. These tasks and pipelines can run independently and even in parallel.

Scenario Configuration and Creation

To instantiate a Taipy scenario, users need to create a scenario configuration using the Config.configure_scenario_from_tasks() method with specific parameters like id, pipelines, frequency, comparators, and properties. Scenarios can also be created from task configurations directly when the scenario configuration contains only one single pipeline configuration.

from taipy import Config

# Creation of Data Nodes, Tasks, ...
...


# Creating a scenario configuration from task configurations
scenario_cfg_from_tasks = Config.configure_scenario_from_tasks("multiply_scenario",
                                     [task_cfg])

Accessing and Managing Scenarios

Taipy provides various methods for working with scenarios, such as retrieving a scenario by its ID, getting all scenarios, promoting a scenario as primary, and comparing scenarios.

Users can also tag scenarios for easy organization and export scenarios in JSON format for further analysis or sharing.

# Get a scenario by id
scenario_retrieved = tp.get(scenario.id)

# Get all scenarios
all_scenarios = tp.get_scenarios()

# Get primary scenarios
all_primary_scenarios = tp.get_primary_scenarios()

# Promote a scenario as primary
tp.set_primary(scenario)

# Compare scenarios (use the compare function defined in the configuration)
comparison_results = tp.compare_scenarios(january_scenario, february_scenario, data_node_config_id="sales_predictions")

# Tag a scenario
tp.tag(scenario, "my_tag")

# Export a scenario
tp.export(scenario.id, folder_path="./monthly_scenario")

Of course, the main advantage of having a scenario is to read the Data Nodes of the various scenarios created. Thanks to the data created for each scenario, we will be able to analyze a scenario. The generic syntax is <scenario>.<Data Node name>.read()

Core visual elements

The Core visual elements let you add visual elements for the Taipy backend. This way, creating a web application corresponding to your backend has never been simpler.

You can add these few lines to the code of your script configuring your scenario. This creates a web application to:

    • select scenarios you created,
    • create new ones,
    • submit them,
    • see the configuration used by the scenario.

from taipy import Gui

...

scenario = None

scenario_md = ""
<|{scenario}|scenario_selector|>
<|{scenario}|scenario|>
<|{scenario}|scenario_dag|>
"""

Gui(scenario_md).run()


Conclusion

Taipy scenarios offer a powerful and flexible way for businesses to explore different problem instances with varying assumptions, enabling effective decision-making and impact analysis. By leveraging the capabilities of Taipy scenarios, companies can better understand the potential outcomes of their choices and make informed decisions that drive business success.

Florian Jacta
Florian Jacta

Taipy Customer Success Engineer