Skip to content

Commit

Permalink
Merge pull request #653 from Avaiga/doc/update-compare-scenario
Browse files Browse the repository at this point in the history
Update compare scenarios
  • Loading branch information
jrobinAV authored Oct 12, 2023
2 parents 373a6f9 + 520bd4f commit 61d7e7c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 58 deletions.

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.

## 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()

0 comments on commit 61d7e7c

Please sign in to comment.