From cb02cc0e0208a0d056a5216f73eb8fef346aad89 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Sun, 11 Sep 2022 15:16:30 +0200 Subject: [PATCH] Improve platform file --- esds/helpers/platform.py | 21 +++++++++++++++++---- example/platform.yaml | 6 ++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/esds/helpers/platform.py b/esds/helpers/platform.py index a811398..99b6986 100644 --- a/esds/helpers/platform.py +++ b/esds/helpers/platform.py @@ -1,6 +1,7 @@ import yaml, os, importlib import numpy as np +from esds import Simulator class UnitsParser: def node_range(r,limit): @@ -55,6 +56,7 @@ class YAMLPlatformFile: "interferences": True, "node_count": 0, "implementations": [], + "arguments": [], "interfaces": dict() } @@ -156,13 +158,19 @@ class YAMLPlatformFile: if extension != ".py": self.parsing_error("File "+file+" must be a python file") for node in r: - self.default["implementations"][node]=file + self.default["implementations"][node]=path count = len(nodes["implementations"]) if count > 1 and count != self.default["node_count"]: self.parsing_error("If more than one implementation is specified, each node implementation should be provided ("+str(self.default["node_count"])+" in total)") else: self.parsing_error("node implementation not provided") - + ##### Nodes arguments + self.default["arguments"]=[None]*self.default["node_count"] + if "arguments" in nodes: + args=nodes["arguments"] + for r in args: + for node_id in UnitsParser.node_range(r,self.default["node_count"]): + self.default["arguments"][node_id]=args[r] def parse_general(self): general=self.platform["general"] @@ -197,10 +205,15 @@ class YAMLPlatformFile: self.default["interferences"]=general["interferences"] def run(self): - callback=None ##### First load callback from file if any + callback=None if self.default["breakpoints_file"] != None: module, ext=os.path.splitext(self.default["breakpoints_file"]) imported=importlib.import_module(module) callback=getattr(imported, self.default["breakpoints_callback"]) - pass + ##### Create simulator + simulator=Simulator(self.default["interfaces"]) + for node_id in range(0,self.default["node_count"]): + simulator.create_node(self.default["implementations"][node_id], args=self.default["arguments"][node_id]) + simulator.run() + \ No newline at end of file diff --git a/example/platform.yaml b/example/platform.yaml index 1f9eae5..911daa1 100644 --- a/example/platform.yaml +++ b/example/platform.yaml @@ -28,6 +28,12 @@ nodes: # 0-@ receiver.py is equivalent to 0-4 receiver.py implementations: - all sender.py + # Node implementations arguments + # arguments is a dictionary where key isrange of node the value is the arguments for + # this specific node range + arguments: { + "all": 2 + } ##### Interfaces Section ##### interfaces: