m_strat.api.dag.node
1from dataclasses import dataclass 2 3# types that are allowed witihn blueprint params. Modification may cause error 4__ALLOWED_SCHEMAS = { 5 int, 6 float, 7 bool, 8 str, 9 list, 10 # dict, 11 # set, 12 # datetime.datetime, 13 # datetime.date, 14 # datetime.time, 15 bytes, 16} 17 18 19def BlueprintNode(name: str, schema: dict[str:type] = None): 20 """Designates a function as a DAG node, Function must have arguments (context,params) ONLY and MUST always return context 21 Args: 22 name (str): Unique name of blueprint 23 schema (dict[str,type], optional): Dictionay. Defaults to {}. 24 """ 25 if schema is None: 26 schema = {} 27 28 def decorator(node_func): 29 assert isinstance(name, str), "Node Name must be a string" 30 assert len(name) > 0, "Node name is empty" 31 32 if schema: 33 assert all( 34 v in __ALLOWED_SCHEMAS and isinstance(k, str) for k, v in schema.items() 35 ), "Invalid Schema keys or values" 36 37 node_func.__is_m_strat_node__ = True 38 node_func.__m_strat_node_name__ = name 39 node_func.__m_strat_node_schema__ = schema 40 return node_func 41 42 return decorator 43 44 45@dataclass 46class ExecutionNode: 47 id: str # The human readable 'name' of the node instance 48 param_id: str # the node parmater identifier (at runtime is retireved as params) 49 blueprint_name: ( 50 str # the name of the blueprint, must exactly match the BlueprintNode name 51 ) 52 pos: list = None # optional positional information for GUIs 53 54 def to_dict(self): 55 """Converts datalcass to a dictionary, used for serialization""" 56 return { 57 "id": self.id, 58 "blueprint_name": self.blueprint_name, 59 "param_id": self.param_id, 60 "pos": self.pos, 61 }
def
BlueprintNode( name: str, schema: dict[slice(<class 'str'>, <class 'type'>, None)] = None):
20def BlueprintNode(name: str, schema: dict[str:type] = None): 21 """Designates a function as a DAG node, Function must have arguments (context,params) ONLY and MUST always return context 22 Args: 23 name (str): Unique name of blueprint 24 schema (dict[str,type], optional): Dictionay. Defaults to {}. 25 """ 26 if schema is None: 27 schema = {} 28 29 def decorator(node_func): 30 assert isinstance(name, str), "Node Name must be a string" 31 assert len(name) > 0, "Node name is empty" 32 33 if schema: 34 assert all( 35 v in __ALLOWED_SCHEMAS and isinstance(k, str) for k, v in schema.items() 36 ), "Invalid Schema keys or values" 37 38 node_func.__is_m_strat_node__ = True 39 node_func.__m_strat_node_name__ = name 40 node_func.__m_strat_node_schema__ = schema 41 return node_func 42 43 return decorator
Designates a function as a DAG node, Function must have arguments (context,params) ONLY and MUST always return context Args: name (str): Unique name of blueprint schema (dict[str,type], optional): Dictionay. Defaults to {}.
@dataclass
class
ExecutionNode:
46@dataclass 47class ExecutionNode: 48 id: str # The human readable 'name' of the node instance 49 param_id: str # the node parmater identifier (at runtime is retireved as params) 50 blueprint_name: ( 51 str # the name of the blueprint, must exactly match the BlueprintNode name 52 ) 53 pos: list = None # optional positional information for GUIs 54 55 def to_dict(self): 56 """Converts datalcass to a dictionary, used for serialization""" 57 return { 58 "id": self.id, 59 "blueprint_name": self.blueprint_name, 60 "param_id": self.param_id, 61 "pos": self.pos, 62 }