Scenario creation
In this section, we provide details on how to instantiate Scenario
entities from a
ScenarioConfig
. They are created from the taipy.create_scenario()
function.
This function creates and returns a new scenario from the scenario configuration provided as a parameter. The scenario's creation also triggers the creation of the related entities that do not exist yet (data nodes, tasks, sequences). These entities are created according to the configuration provided, and particularly on the scope of the data nodes. For more details on scopes, see the recurrent scenario page.
Three parameters can be given to the scenario creation method :
config
is a mandatory parameter of typeScenarioConfig
. It corresponds to a scenario configuration (created in the module my_config.py)creation_date
is an optional parameter of type datetime.datetime. It corresponds to the creation date of the scenario. If the parameter is not provided, the current date-time is used by default.- The
name
parameter is optional as well. Any string can be provided as aname
. It can be used to display the scenario in a user interface.
Example
In this example, only the mandatory parameter config is provided. The creation_date
is set by default to the current datetime and the name is None
.
import taipy as tp
from taipy import Config
def double(nb):
return nb * 2
if __name__ == "__main__":
# Configuring a scenario with a single task that doubles the input data node
input_data_node_cfg = Config.configure_data_node("my_input", default_data=21)
output_data_node_cfg = Config.configure_data_node("my_output")
double_task_cfg = Config.configure_task(id="double_task",
function=double,
input=input_data_node_cfg,
output=output_data_node_cfg)
scenario_cfg = Config.configure_scenario(id="double_scenario",
task_configs=[double_task_cfg])
# Instantiating a scenario
scenario = tp.create_scenario(scenario_cfg)
In this example, all the parameters are provided. The mandatory scenario config, the creation_date and the name.
import datetime
import taipy as tp
from taipy import Config
def double(nb):
return nb * 2
if __name__ == "__main__":
# Configuring a scenario with a single task that doubles the input data node
input_data_node_cfg = Config.configure_data_node("my_input", default_data=21)
output_data_node_cfg = Config.configure_data_node("my_output")
double_task_cfg = Config.configure_task(id="double_task",
function=double,
input=input_data_node_cfg,
output=output_data_node_cfg)
scenario_cfg = Config.configure_scenario(id="double_scenario",
task_configs=[double_task_cfg])
# Instantiating a scenario
scenario = tp.create_scenario(scenario_cfg, datetime.datetime(1998, 7, 12), "My first scenario")