-
Notifications
You must be signed in to change notification settings - Fork 2
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
Refactor PFDL code #60
Conversation
maxhoerstr
commented
Aug 20, 2024
- Make code more modular to enable the reuse of the code (e.g.. make more functions and methods single purpose)
- Fix various bugs in the petri net generation
- Renaming
- Format code and add docstrings
- Allow a PFDL program to be passed over to the scheduler as a string (currently, only a file path was allowed)
- Add various quality of live features/fixes
- Allow the free configuration of the "start task" (former productionTask)
- Allow integers as loop limits and negative numbers
- Create a tree where each node contains a group id, to map the call hierarchy of the different tasks
There were still parent group ids used. They are unnecessary now, since the structure of the calls is realised with a tree structure (Node)
- Petri Net images and dot files are no always named "petri_net" - Append Call Tree from PetriNetGenerator to dot file for extension
- Cluster individual components of the PFDL (Service, Tasks, ..) - Save this information in the dot file
- Fix bug in drawing of petri net for extension - Move creation of folders on better suiting location - Remove unnecessary `used_in_extension` attributes and params
- Fix typos and remove comments - Temporarily disable removal of nodes from the petri net - Publish PFDL string to dashboard - Rewrite methods so PFDL string can be extracted from the file and used
- Send Petri Net update before Order is finished - Remove counting loop subgraph in dot file
This allows for more modularity so future plugin users can choose what to reuse if the overwrite the init function of the scheduler.
- Use the term "uuid" wherever a uuid is assigned - Avoid inconsistent variable naming
- Enable plugins to overload this method
- the changed file might have caused troubles when running it while the MFDL plugin is active
- Enable reusing parts of the method when multiple types per variable are allowed
The way that the nodes (places and transitions) in the petri net were clustered with the help of SNAKES was wrong. Now, the cluster is not overwritten anymore, but correctly added in the intended way. This resolves a bug where the deletion of specific nodes resulted in an KeyError in the snakes library.
- Adjust docstrings - Remove unused attribute 'cluster'
- Add definition for variable type - Apply changes to tree visitor - Adjust tests
- Instead of limiting the starting task name to 'productionTask', it can now be modified by passing the desired name to the Process
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.
Looks good overall, I only figured out some minor improvements that could be applied to increase the code quality.
pfdl_scheduler/petri_net/drawer.py
Outdated
@@ -89,6 +90,10 @@ def draw_clusters(clust, attr): | |||
attr["style"] = DEFAULT_CLUSTER_STYLE | |||
|
|||
|
|||
def draw_clusters(clust, attr): |
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.
What is the intention of duplicating the method above, including the same number of attributes? One version should be removed (they are actually doing the same, since DEFAULT_CLUSTER_STYLE is never reassigned). Also, consider renaming clust into _ since it is unused.
@@ -7,6 +7,7 @@ | |||
"""Contains the PetriNetGenerator class.""" | |||
|
|||
# standard libraries | |||
import copy | |||
from typing import Any, Callable, Dict, List, OrderedDict, Tuple |
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.
unused import
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.
Copy is used in Line 54 :)
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.
Sorry I marked the wrong line, this comment refers to the Tuple import in the line below
) | ||
node.cluster.add_node(current_connection_id) | ||
current_connection_uuid = create_transition("connection", "", self.net, node) | ||
# node.cluster.add_child(Cluster(current_connection_uuid)) |
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.
remove comment
) | ||
cluster = Cluster([parallel_loop_started]) | ||
node.cluster.add_child(cluster) | ||
# node.cluster.add_child(cluster) |
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.
remove comment
# self.net.remove_place(self.task_started_id) | ||
|
||
if self.net.has_place(place_uuid): | ||
# self.net.clusters._nodes.add(place_uuid) |
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.
remove comment
@@ -93,6 +94,29 @@ def write_tokens_to_file(token_stream: CommonTokenStream) -> None: | |||
file.write(token_text + "\n") | |||
|
|||
|
|||
def extract_content_and_file_path(program): |
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.
program: str
return type: Tuple[str, str]
pfdl_scheduler/scheduler.py
Outdated
self.setup_scheduling(draw_petri_net) | ||
|
||
# enable logging | ||
# self.attach(LogEntryObserver(self.scheduler_uuid)) |
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.
is this still useful?
@@ -20,7 +20,7 @@ Struct CuttingResult | |||
sheet_parts: SheetPart[] | |||
End | |||
|
|||
Struct TransportOrderStep | |||
Struct TransportOrderStep_Struct |
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.
Maybe remove the _ in the Struct and Service names here to be consistent with the other test files
@@ -50,14 +50,14 @@ Task cuttingTask | |||
End | |||
|
|||
Task transport | |||
Transport | |||
Transport_Service |
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.
See comment above
array = Array("string") | ||
array.length = 10 |
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.
This lines are meaningless and can be removed
Incorporate feedback regarding the quality of the code (fix typos, remove comments/ unused packages, fix naming)
@@ -20,7 +20,7 @@ Struct CuttingResult | |||
sheet_parts: SheetPart[] | |||
End | |||
|
|||
Struct TransportOrderStep_Struct | |||
Struct TransportOrderStep |
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.
Using keywords of other plugins will cause problems there, so the Struct needs to have a different name than TransportOrderStep (same for Transport)