-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feature/#397 scenario duplication #2373
base: develop
Are you sure you want to change the base?
Conversation
658f02f
to
2644479
Compare
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
2644479
to
f79d591
Compare
cloned_scenario_id = cloned_scenario._new_id(cloned_scenario.config_id) | ||
cloned_scenario.id = cloned_scenario_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cloned_scenario_id = cloned_scenario._new_id(cloned_scenario.config_id) | |
cloned_scenario.id = cloned_scenario_id | |
cloned_scenario.id = cloned_scenario._new_id(cloned_scenario.config_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should implement a can_duplicate method, returning reasons, just like we have a can_create method.
taipy/core/data/_data_manager.py
Outdated
cloned_dn = cls._get(dn) | ||
|
||
cloned_dn.id = cloned_dn._new_id(cloned_dn._config_id) | ||
cloned_dn._owner_id = cls._get_owner_id(cloned_dn._scope, cycle_id, scenario_id) | ||
cloned_dn._parent_ids = set() | ||
|
||
cls._set(cloned_dn) | ||
|
||
cloned_dn._clone_data() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the data node has a cycle scope, and if the new scenario is from the same cycle, then we want to share the same data node between scenarios.
If the scope is global it always already exists, and we also want to share the existing one.
if os.path.exists(self.path): | ||
folder_path, base_name = os.path.split(self.path) | ||
new_base_path = os.path.join(folder_path, f"TAIPY_CLONE_{id}_{base_name}") | ||
if os.path.isdir(self.path): | ||
shutil.copytree(self.path, new_base_path) | ||
else: | ||
shutil.copy(self.path, new_base_path) | ||
return new_base_path | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to differentiate the cases where the initial path is generated by Taipy or provided by the user?
I believe it would be better. If it is Taipy generated, we can just replace the old id by the new one. otherwise, adding a prefix or a suffix as you did make sense.
|
||
cloned_additional_data_nodes = set() | ||
for data_node in cloned_scenario.additional_data_nodes.values(): | ||
cloned_additional_data_nodes.add(_data_manager._clone(data_node, None, cloned_scenario_id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicating data nodes should depend on its scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should implement a can_duplicate method, returning reasons, just like we have a can_create method.
@@ -521,3 +521,47 @@ def _get_by_config_id(cls, config_id: str, version_number: Optional[str] = None) | |||
for fil in filters: | |||
fil.update({"config_id": config_id}) | |||
return cls._repository._load_all(filters) | |||
|
|||
@classmethod | |||
def _clone(cls, scenario: Scenario) -> Scenario: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should accept an optional name and an optional date in the method signature. It does not change much for the name but it does for the creation date. This has an impact on the potential cycle as the new scenario might be on a different cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm? I can understand the name, but the creation date?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say I have a January scenario I am happy with. I want to start with a duplicate of this one to compute my February scenario. So beginning of February I duplicate my January scenario passing the current date so the new scenario is in the February cycle.
Does it make sense for you? And @FlorianJacta any opinion on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree; duplication for me was not about the creation date. Your use case is a real use case from CFM
@@ -521,3 +521,47 @@ def _get_by_config_id(cls, config_id: str, version_number: Optional[str] = None) | |||
for fil in filters: | |||
fil.update({"config_id": config_id}) | |||
return cls._repository._load_all(filters) | |||
|
|||
@classmethod | |||
def _clone(cls, scenario: Scenario) -> Scenario: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the issue, we should also pass an optional list of data nodes or data node IDs. Without any list; we should copy all the data. If the list is provided, only the files of the data nodes in the list should be copied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave it as the next step for now
@@ -226,3 +231,22 @@ def _get_by_config_id(cls, config_id: str, version_number: Optional[str] = None) | |||
for fil in filters: | |||
fil.update({"config_id": config_id}) | |||
return cls._repository._load_all(filters) | |||
|
|||
@classmethod | |||
def _clone(cls, task: Task, cycle_id: Optional[CycleId] = None, scenario_id: Optional[ScenarioId] = None) -> Task: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename _clone method to _duplicate as it does not return another instance of the same object. It returns a similar object with a few differences (ids, sub-entities' ids, paths, etc...)
taipy/core/data/csv.py
Outdated
def _clone_data(self): | ||
new_data_path = self._clone_data_file(self.id) | ||
self._properties[self._PATH_KEY] = new_data_path | ||
return new_data_path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move that outside the data node, to put it in the data_manager.
Just like we handle the parent_ids and the owner_id in the manager, I would set the path property in the manager as well (still retrieving the value from a fileDatanodeMixing method).
This is debatable, though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well this is specific for file DNs only, if we put it in the data manager, we're grouping it with other types of DNs like Sql or mongo, I don't think it's a good idea
What type of PR is this? (check all applicable)
Description
Related Tickets & Documents
#397