Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compare scenarios #653

Merged
merged 5 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
> You can download the code for
<a href="./../src/step_08.py" download>Step 8</a>
or all the steps <a href="./../src/src.zip" download>here</a>.

# Comparing scenarios
> You can download the code
<a href="/scenario_comparison.py" download>here</a>.

*Estimated Time for Completion: 15 minutes; Difficulty Level: Advanced*

![](config_08.svg){ width=700 style="margin:auto;display:block;border: 4px solid rgb(210,210,210);border-radius:7px" }
![Configuration](config.svg){ width=700 style="margin:auto;display:block;border: 4px solid rgb(210,210,210);border-radius:7px" }

Taipy offers a way to compare data nodes across scenarios by including a function directly in the configuration of the scenario.

FlorianJacta marked this conversation as resolved.
Show resolved Hide resolved
## Step 1: The first step consists in declaring on which data nodes to apply the comparison functions:
# Comparing scenarios

**Step 1:** Declare data nodes on which the comparison functions are applied.

In this example, we want to apply a comparison to the '_output_' Data Node. It is indicated in the comparators parameter of the `configure_scenario()`.
In this example, we want to apply a comparison to the '_output_' Data Node. It is indicated in the comparators parameter of the `configure_scenario`.

```python
scenario_cfg = Config.configure_scenario(id="multiply_scenario",
name="my_scenario",
tasks_configs=[first_task_cfg,
second_task_cfg],
comparators={output_data_node_cfg.id: compare_function},)
name="my_scenario",
tasks_configs=[first_task_cfg,
second_task_cfg],
comparators={output_data_node_cfg.id: compare_function},)
```
## Step 2: Implement the comparison function (`compare_function()`) used above.

**Step 2:** Implement the comparison function (`compare_function()`) used above.

_data_node_results_ is the list of the Output Data Nodes from all scenarios passed in the comparator. We iterate through it to compare scenarios.

Expand All @@ -40,7 +40,7 @@ def compare_function(*data_node_results):
return compare_result
```

Now, the `compare_scenarios()` can be used within Taipy.
Now, the `compare_scenarios` can be used within Taipy.

```python
tp.Core().run()
Expand All @@ -63,7 +63,6 @@ Results:

# Entire code


```python
from taipy.core.config import Config, Frequency
import taipy as tp
Expand Down Expand Up @@ -111,9 +110,9 @@ def compare_function(*data_node_results):


scenario_cfg = Config.configure_scenario(id="multiply_scenario",
name="my_scenario",
task_configs=[first_task_cfg, second_task_cfg],
comparators={output_cfg.id: compare_function})
name="my_scenario",
task_configs=[first_task_cfg, second_task_cfg],
comparators={output_cfg.id: compare_function})


if __name__=="__main__":
Expand All @@ -129,6 +128,4 @@ if __name__=="__main__":
scenario_2.submit()

print(tp.compare_scenarios(scenario_1, scenario_2))

tp.Rest().run()
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def add(nb):

# Configuration of tasks
first_task_cfg = Config.configure_task("double",
double,
input_cfg,
intermediate_cfg)
double,
input_cfg,
intermediate_cfg)

second_task_cfg = Config.configure_task("add",
add,
intermediate_cfg,
output_cfg)
add,
intermediate_cfg,
output_cfg)



Expand Down Expand Up @@ -63,5 +63,4 @@ def compare_function(*data_node_results):
scenario_2.submit()

print(tp.compare_scenarios(scenario_1, scenario_2))

tp.Rest().run()