Added some documentation, fixed test and missing schedule
This commit is contained in:
parent
ebfd85a666
commit
fd6c8b4277
26 changed files with 1284 additions and 72 deletions
|
|
@ -1,41 +0,0 @@
|
|||
## Node Module
|
||||
|
||||
Defines the abstract base Node class for graph-based structures. Each Node is assigned
|
||||
a unique identifier via an external IdGenerator. The class provides an interface for
|
||||
managing execution state and generating DOT graph representations using Jinja2 templates.
|
||||
|
||||
### Class: `Node`
|
||||
|
||||
- **Attributes**
|
||||
- `id: int`: A unique identifier assigned to each instance upon initialization.
|
||||
|
||||
- **Methods**
|
||||
- `get_id`
|
||||
- returns: `int`, The unique node ID
|
||||
|
||||
Retrieves the unique identifier of the node.
|
||||
|
||||
- `generate_stack_frame`
|
||||
- exec_id: `int`, The ID of the execution context.
|
||||
- returns: `None`
|
||||
|
||||
Initializes a new state frame for a specific execution context.
|
||||
Designed to be overridden in subclasses that use execution state.
|
||||
|
||||
- `delete_stack_frame`
|
||||
- exec_id: `int`, The ID of the execution context.
|
||||
- returns: `None`
|
||||
|
||||
Deletes the state frame for a specific execution context.
|
||||
Designed to be overridden in subclasses that use execution state.
|
||||
|
||||
- `generate_dot`
|
||||
- nodes: `list[str]`, A list to append DOT node definitions to.
|
||||
- edges: `list[str]`, A list to append DOT edges definitions to.
|
||||
- visited: `set[str]`, A set of already visited node IDs to avoid duplicates or recursion.
|
||||
- template: `list[str]`, A Jinja2 template used to format the node's DOT representation.
|
||||
- returns: `None`
|
||||
|
||||
Generates the DOT graph representation for this node and its relationships.
|
||||
Must be implemented in subclasses.
|
||||
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
from abc import abstractmethod
|
||||
from typing import override
|
||||
from jinja2 import Template
|
||||
|
||||
from api.od import ODAPI
|
||||
from .funcs import generate_dot_edge
|
||||
from .node import Node
|
||||
|
||||
|
||||
|
|
@ -33,3 +37,25 @@ class ExecNode(Node):
|
|||
@abstractmethod
|
||||
def execute(self, port: str, exec_id: int, od: ODAPI) -> tuple[int, any] | None:
|
||||
return None
|
||||
|
||||
@override
|
||||
def generate_dot(
|
||||
self, nodes: list[str], edges: list[str], visited: set[int], template: Template
|
||||
) -> None:
|
||||
for out_port, edge in self.next_node.items():
|
||||
template.render()
|
||||
generate_dot_edge(
|
||||
self,
|
||||
edge[0],
|
||||
edges,
|
||||
template,
|
||||
kwargs={
|
||||
"prefix": "e",
|
||||
"from_gate": out_port,
|
||||
"to_gate": edge[1],
|
||||
"color": "darkblue",
|
||||
},
|
||||
)
|
||||
|
||||
for edge in self.next_node.values():
|
||||
edge[0].generate_dot(nodes, edges, visited, template)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class Match(ExecNode, DataNode):
|
|||
nodes,
|
||||
template,
|
||||
**{
|
||||
"label": f"match_{self.n}\n{self.label}",
|
||||
"label": f"match\n{self.label}\nn = {self.n}",
|
||||
"ports_exec": (
|
||||
self.get_exec_input_gates(),
|
||||
self.get_exec_output_gates(),
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Rewrite(ExecNode, DataNode):
|
|||
nodes,
|
||||
template,
|
||||
**{
|
||||
"label": "rewrite",
|
||||
"label": f"rewrite\n{self.label}",
|
||||
"ports_exec": (
|
||||
self.get_exec_input_gates(),
|
||||
self.get_exec_output_gates(),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from .exec_node import ExecNode
|
|||
from .funcs import not_visited, generate_dot_node, IdGenerator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ..rule_scheduler import RuleSchedular
|
||||
from ..rule_scheduler import RuleScheduler
|
||||
|
||||
|
||||
class ScheduleState:
|
||||
|
|
@ -16,9 +16,9 @@ class ScheduleState:
|
|||
self.end_gate: str = ""
|
||||
|
||||
class SubSchedule(ExecNode, DataNode):
|
||||
def __init__(self, schedular: "RuleSchedular", file: str) -> None:
|
||||
self.schedule = schedular._load_schedule(file, _main=False)
|
||||
self.schedular = schedular
|
||||
def __init__(self, scheduler: "RuleScheduler", file: str) -> None:
|
||||
self.schedule = scheduler._load_schedule(file, _main=False)
|
||||
self.scheduler = scheduler
|
||||
super().__init__()
|
||||
self.state: dict[int, ScheduleState] = {}
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ class SubSchedule(ExecNode, DataNode):
|
|||
|
||||
@override
|
||||
def execute(self, port: str, exec_id: int, od: ODAPI) -> tuple[int, any] | None:
|
||||
runstatus, result = self.schedular._runner(
|
||||
runstatus, result = self.scheduler._runner(
|
||||
od,
|
||||
self.schedule,
|
||||
port,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue