Skip to content

Commit

Permalink
Feature/#709 user man (#1285)
Browse files Browse the repository at this point in the history
* Improve Data node ref man

* Improve Task ref man

* Improve Scenario ref man

* Apply suggestions from code review

Co-authored-by: Đỗ Trường Giang <[email protected]>

* linter

* formatting

---------

Co-authored-by: Đỗ Trường Giang <[email protected]>
  • Loading branch information
jrobinAV and trgiangdo authored May 14, 2024
1 parent 24fc8fe commit 4ce61b1
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 5 deletions.
41 changes: 36 additions & 5 deletions taipy/core/data/data_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,37 @@ class DataNode(_Entity, _Labeled):
SQL Data Node, CSV Data Node, ...).
!!! note
It is recommended not to instantiate subclasses of `DataNode` directly.
It is not recommended to instantiate subclasses of `DataNode` directly. Instead,
you have two ways:
1. Create a Scenario using the `create_scenario()^` function. Related data nodes
will be created automatically. Please refer to the `Scenario^` class for more
information.
2. Configure a `DataNodeConfig^` with the various configuration methods form `Config^`
and use the `create_global_data_node()^` function as illustrated in the following
example.
!!! Example
```python
import taipy as tp
from taipy import Config
# Configure a global data node
dataset_cfg = Config.configure_data_node("my_dataset", scope=tp.Scope.GLOBAL)
# Instantiate a global data node
dataset = tp.create_global_data_node(dataset_cfg)
# Retrieve the list of all data nodes
all_data_nodes = tp.get_data_nodes()
# Write the data
dataset.write("Hello, World!")
# Read the data
print(dataset.read())
```
Attributes:
config_id (str): Identifier of the data node configuration. It must be a valid Python
Expand All @@ -78,10 +108,11 @@ class DataNode(_Entity, _Labeled):
parent_ids (Optional[Set[str]]): The set of identifiers of the parent tasks.
last_edit_date (datetime): The date and time of the last modification.
edits (List[Edit^]): The list of Edits (an alias for dict) containing metadata about each
data edition including but not limited to timestamp, comments, job_id:
timestamp: The time instant of the writing
comments: Representation of a free text to explain or comment on a data change
job_id: Only populated when the data node is written by a task execution and corresponds to the job's id.
data edition including but not limited to:
<ul><li>timestamp: The time instant of the writing </li>
<li>comments: Representation of a free text to explain or comment on a data change</li>
<li>job_id: Only populated when the data node is written by a task execution and
corresponds to the job's id.</li></ul>
Additional metadata related to the edition made to the data node can also be provided in Edits.
version (str): The string indicates the application version of the data node to
instantiate. If not provided, the current version is used.
Expand Down
34 changes: 34 additions & 0 deletions taipy/core/scenario/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,40 @@ class Scenario(_Entity, Submittable, _Labeled):
solve the Business case. It also holds a set of additional data nodes (instances of `DataNode` class)
for extra data related to the scenario.
!!! note
It is not recommended to instantiate a `Scenario` directly. Instead, it should be
created with the `create_scenario()^` function.
!!! Example
```python
import taipy as tp
from taipy import Config
def by_two(x: int):
return x * 2
# Configure scenarios
input_cfg = Config.configure_data_node("my_input")
result_cfg = Config.configure_data_node("my_result")
task_cfg = Config.configure_task("my_double", function=by_two, input=input_cfg, output=result_cfg)
scenario_cfg = Config.configure_scenario("my_scenario", task_configs=[task_cfg])
# Create a new scenario from the configuration
scenario = tp.create_scenario(scenario_cfg)
# Write the input data and submit the scenario
scenario.my_input.write(3)
scenario.submit()
# Read the result
print(scenario.my_result.read()) # Output: 6
# Retrieve all scenarios
all_scenarios = tp.get_scenarios()
```
Attributes:
config_id (str): The identifier of the `ScenarioConfig^`.
tasks (Set[Task^]): The set of tasks.
Expand Down
40 changes: 40 additions & 0 deletions taipy/core/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,46 @@ class Task(_Entity, _Labeled):
A `Task` brings together the user code as function, the inputs and the outputs as data nodes
(instances of the `DataNode^` class).
!!! note
It is not recommended to instantiate a `Task` directly. Instead, it should be
created with the `create_scenario()^` function. When creating a `Scenario^`,
the related data nodes and tasks are created automatically. Please refer to
the `Scenario^` class for more information.
!!! Example
```python
import taipy as tp
from taipy import Config
def by_two(x: int):
return x * 2
# Configure data nodes, tasks and scenarios
input_cfg = Config.configure_data_node("my_input", default_data=2)
result_cfg = Config.configure_data_node("my_result")
task_cfg = Config.configure_task("my_double", function=by_two, input=input_cfg, output=result_cfg)
scenario_cfg = Config.configure_scenario("my_scenario", task_configs=[task_cfg])
# Instantiate a task along with a scenario
sc = tp.create_scenario(scenario_cfg)
# Retrieve task and data nodes from scenario
task_input = sc.my_input
double_task = sc.my_double
task_result = sc.my_result
# Write the input data and submit the task
task_input.write(3)
double_task.submit()
# Read the result
print(task_result.read()) # Output: 6
# Retrieve the list of all tasks
all_tasks = tp.get_tasks()
```
Attributes:
config_id (str): The identifier of the `TaskConfig^`.
properties (dict[str, Any]): A dictionary of additional properties.
Expand Down

0 comments on commit 4ce61b1

Please sign in to comment.