Skip to content

taipy.core.Scenario

Bases: _Entity, Submittable, _Labeled

Instance of a Business case to solve.

A scenario holds a set of tasks (instances of Task class) to submit for execution in order to solve the Business case. It also holds a set of additional data nodes (instances of DataNode class) for extra data related to the scenario.

Attributes:

Name Type Description
config_id str

The identifier of the ScenarioConfig.

tasks Set[Task]

The set of tasks.

additional_data_nodes Set[DataNode]

The set of additional data nodes.

sequences Dict[str, Sequence]

The dictionary of sequences: subsets of tasks that can be submitted together independently of the rest of the scenario's tasks.

properties dict[str, Any]

A dictionary of additional properties.

scenario_id str

The unique identifier of this scenario.

creation_date datetime

The date and time of the scenario's creation.

is_primary bool

True if the scenario is the primary of its cycle. False otherwise.

cycle Cycle

The cycle of the scenario.

subscribers List[Callable]

The list of callbacks to be called on Job's status change.

tags Set[str]

The list of scenario's tags.

version str

The string indicates the application version of the scenario to instantiate. If not provided, the latest version is used.

add_sequence(name, tasks, properties=None, subscribers=None)

Add a sequence to the scenario.

Parameters:

Name Type Description Default
name str

The name of the sequence.

required
tasks Union[List[Task], List[TaskId]]

The list of scenario's tasks to add to the sequence.

required
properties Optional[Dict]

The optional properties of the sequence.

None
subscribers Optional[List[_Subscriber]]

The optional list of callbacks to be called on Job's status change.

None

Raises:

Type Description
SequenceTaskDoesNotExistInScenario

If a task in the sequence does not exist in the scenario.

SequenceAlreadyExists

If a sequence with the same name already exists in the scenario.

add_sequences(sequences)

Add multiple sequences to the scenario.

Note

To provide properties and subscribers for the sequences, use Scenario.add_sequence instead.

Parameters:

Name Type Description Default
sequences Dict[str, Union[List[Task], List[TaskId]]]

A dictionary containing sequences to add. Each key is a sequence name, and the value must be a list of the scenario tasks.

required

Raises:

Type Description
SequenceTaskDoesNotExistInScenario

If a task in the sequence does not exist in the scenario.

add_tag(tag)

Add a tag to this scenario.

If the scenario's cycle already have another scenario tagged with tag the other scenario will be untagged.

Parameters:

Name Type Description Default
tag str

The tag to add to this scenario.

required

export(folder_path)

Export all related entities of this scenario to a folder.

Parameters:

Name Type Description Default
folder_path Union[str, Path]

The folder path to export the scenario to.

required

get_label()

Returns the scenario simple label prefixed by its owner label.

Returns:

Type Description
str

The label of the scenario as a string.

get_simple_label()

Returns the scenario simple label.

Returns:

Type Description
str

The simple label of the scenario as a string.

has_tag(tag)

Indicate if the scenario has a given tag.

Parameters:

Name Type Description Default
tag str

The tag to search among the set of scenario's tags.

required

is_deletable()

Indicate if the scenario can be deleted.

Returns:

Type Description
bool

True if the scenario can be deleted. False otherwise.

remove_sequence(name)

Remove a sequence from the scenario.

Parameters:

Name Type Description Default
name str

The name of the sequence to remove.

required

remove_sequences(sequence_names)

Remove multiple sequences from the scenario.

Parameters:

Name Type Description Default
sequence_names List[str]

A list of sequence names to remove.

required

remove_tag(tag)

Remove a tag from this scenario.

Parameters:

Name Type Description Default
tag str

The tag to remove from the set of the scenario's tags.

required

rename_sequence(old_name, new_name)

Rename a sequence of the scenario.

Parameters:

Name Type Description Default
old_name str

The current name of the sequence to rename.

required
new_name str

The new name of the sequence.

required

Raises:

Type Description
SequenceAlreadyExists

If a sequence with the same name already exists in the scenario.

set_primary()

Promote the scenario as the primary scenario of its cycle.

If the cycle already has a primary scenario, it will be demoted, and it will no longer be primary for the cycle.

submit(callbacks=None, force=False, wait=False, timeout=None, **properties)

Submit this scenario for execution.

All the Tasks of the scenario will be submitted for execution.

Parameters:

Name Type Description Default
callbacks List[Callable]

The list of callable functions to be called on status change.

None
force bool

Force execution even if the data nodes are in cache.

False
wait bool

Wait for the orchestrated jobs created from the scenario submission to be finished in asynchronous mode.

False
timeout Union[float, int]

The optional maximum number of seconds to wait for the jobs to be finished before returning.

None
**properties dict[str, any]

A keyworded variable length list of additional arguments.

{}

subscribe(callback, params=None)

Subscribe a function to be called on Job status change.

The subscription is applied to all jobs created from the scenario's execution.

Parameters:

Name Type Description Default
callback Callable[[Scenario, Job], None]

The callable function to be called on status change.

required
params Optional[List[Any]]

The parameters to be passed to the callback.

None
Note

Notification will be available only for jobs created after this subscription.

unsubscribe(callback, params=None)

Unsubscribe a function that is called when the status of a Job changes.

Parameters:

Name Type Description Default
callback Callable[[Scenario, Job], None]

The callable function to unsubscribe.

required
params Optional[List[Any]]

The parameters to be passed to the callback.

None
Note

The function will continue to be called for ongoing jobs.

update_sequence(name, tasks, properties=None, subscribers=None)

Update an existing sequence.

Parameters:

Name Type Description Default
name str

The name of the sequence to update.

required
tasks Union[List[Task], List[TaskId]]

The new list of scenario's tasks.

required
properties Optional[Dict]

The new properties of the sequence.

None
subscribers Optional[List[_Subscriber]]

The new list of callbacks to be called on Job's status change.

None

Raises:

Type Description
SequenceTaskDoesNotExistInScenario

If a task in the list does not exist in the scenario.

SequenceAlreadyExists

If a sequence with the same name already exists in the scenario.