Skip to content

Commit

Permalink
The ref man scope page (#1289)
Browse files Browse the repository at this point in the history
* Move scope concept to ref man

* Improve Scenario ref man

* Scope ref man

* Scope ref man
  • Loading branch information
jrobinAV authored May 16, 2024
1 parent faddd95 commit 6d21c4e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
50 changes: 48 additions & 2 deletions taipy/config/common/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,59 @@ def __lt__(self, other):


class Scope(_OrderedEnum):
"""Scope of a `DataNode^`.
"""Scope of a `DataNodeConfig^` or a `DataNode^`.
This enumeration can have the following values:
- `GLOBAL`
- `CYCLE`
- `SCENARIO`
- `SCENARIO` (Default value)
Each data node config has a scope. It is an attribute propagated to the `DataNode^` when instantiated from
a `DataNodeConfig^`. The scope is used to determine the _visibility_ of the data node, and which scenarios can
access it.
In other words :
- There can be only one data node instantiated from a `DataNodeConfig^` with a `GLOBAL` scope. All the
scenarios share the unique data node. When a new scenario is created, the data node is also created if
and only if it does not exist yet.
- Only one data node instantiated from a `DataNodeConfig^` with a `CYCLE` scope is created for each cycle.
All the scenarios of the same cycle share the same data node. When a new scenario is created within a
cycle, Taipy instantiates a new data node if and only if there is no data node for the cycle yet.
- A data node that has the scope set to `SCENARIO` belongs to a unique scenario and cannot be used by others
When creating a new scenario, data nodes with a `SCENARIO` scope are systematically created along with
the new scenario.
!!! example
Let's consider a simple example where a company wants to predict its sales for the next month. The company
has a trained model that predicts the sales based on the current month and the historical sales. Based on
the sales forecasts the company wants to plan its production orders. The company wants to simulate two
scenarios every month: one with low capacity and one with high capacity.
We can create the `DataNodeConfig^`s with the following scopes:
- One data node for the historical sales with a `GLOBAL` scope.
- Three data nodes with a `CYCLE` scope, for the trained model, the current month, and the sales predictions.
- Two data nodes with a `SCENARIO` scope, for the capacity and the production orders.
The code snippet below shows how to configure the data nodes with the different scopes:
```python
from taipy import Config, Scope
hist_cfg = Config.configure_csv_data_node("sales_history", scope=Scope.GLOBAL)
model_cfg = Config.configure_data_node("trained_model", scope=Scope.CYCLE)
month_cfg = Config.configure_data_node("current_month", scope=Scope.CYCLE)
predictions_cfg = Config.configure_data_node("sales_predictions", scope=Scope.CYCLE)
capacity_cfg = Config.configure_data_node("capacity", scope=Scope.SCENARIO)
orders_cfg = Config.configure_sql_data_node("production_orders",
scope=Scope.SCENARIO,
db_name="taipy",
db_engine="sqlite",
table_name="sales")
```
"""

GLOBAL = 3
Expand Down
2 changes: 1 addition & 1 deletion taipy/core/data/data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _recompute_is_ready_for_reading(dn: "DataNode", *args, **kwargs):
class DataNode(_Entity, _Labeled):
"""Reference to a dataset.
A Data Node is an abstract class that holds metadata related to the dataset it refers to.
A Data Node is an abstract class that holds metadata related to the data it refers to.
In particular, a data node holds the name, the scope, the owner identifier, the last
edit date, and some additional properties of the data.<br/>
A Data Node also contains information and methods needed to access the dataset. This
Expand Down

0 comments on commit 6d21c4e

Please sign in to comment.