Browse Source

semi configurable translation function for benchmarking

Snej69420 6 months ago
parent
commit
8a08683ca2

+ 5 - 1
benchmarks/Agents/DelayedAtomic.jl

@@ -20,6 +20,8 @@ end
     stats::Bool = false
     int_count::Int = 0
     ext_count::Int = 0
+
+    output::Int = 2
 end
 
 format_state(agent::DelayedAtomic) = "State.$(agent.state)"
@@ -31,6 +33,7 @@ end
 
 function internal_transition!(agent::DelayedAtomic, model)
     agent.stats && (agent.int_count += 1)
+    agent.output += 1
     agent.int_delay > 0.0 && julia_stones(agent.int_delay)
     agent.state = Passive
 end
@@ -48,6 +51,7 @@ end
 
 function output!(agent::DelayedAtomic, model)
     if agent.has_out_port
-        send_message!(agent, model, :o_out, 0)
+#         send_message!(agent, model, :o_out, 42)
+        send_message!(agent, model, :o_out, agent.output)
     end
 end

+ 26 - 18
benchmarks/Agents/Topologies.jl

@@ -1,5 +1,13 @@
 @enum Structure LI HI HO HOmod
 
+const tIdentity = (msg::Int) -> msg
+const tScaled = (msg::Int) -> (msg ^ 2)
+
+const translation_table = Dict(i => i + 100 for i in 0:1000)
+const tAccessed = (msg::Int) -> (get(translation_table, msg % 1000, msg))
+
+global active_z_function = tIdentity
+
 # Port Config
 function setup_ports!(top_model::CoupledDEVS, type::Structure)
     has_out_port = type in (HI, HO, HOmod)
@@ -29,9 +37,9 @@ function build_leaf_node(name::String, type::Structure, int_delay::Float64, ext_
         int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
         has_out_port=has_out_port, stats=stats)
 
-    connect!(top_model, self.i_in, atom.i_in)
+    connect!(top_model, self.i_in, atom.i_in; Z=active_z_function)
     if has_out_port
-        connect!(top_model, atom.o_out, self.o_out)
+        connect!(top_model, atom.o_out, self.o_out; Z=active_z_function)
     end
 
     return top_model
@@ -58,16 +66,16 @@ end
 # Routing
 function route_LI!(top_model::CoupledDEVS, width_models::Vector{ModelRef})
     for atom in width_models
-        connect!(top_model, self.i_in, atom.i_in)
+        connect!(top_model, self.i_in, atom.i_in; Z=active_z_function)
     end
 end
 
 function route_HI!(top_model::CoupledDEVS, width_models::Vector{ModelRef})
     for atom in width_models
-        connect!(top_model, self.i_in, atom.i_in)
+        connect!(top_model, self.i_in, atom.i_in; Z=active_z_function)
     end
     for i in 1:(length(width_models) - 1)
-        connect!(top_model, width_models[i].o_out, width_models[i + 1].i_in)
+        connect!(top_model, width_models[i].o_out, width_models[i + 1].i_in; Z=active_z_function)
     end
 end
 
@@ -76,15 +84,15 @@ function route_HO!(top_model::CoupledDEVS, width_models::Vector{ModelRef})
         curr_atom = width_models[i]
         next_atom = width_models[i + 1]
 
-        connect!(top_model, curr_atom.o_out, next_atom.i_in)
-        connect!(top_model, self.i_in2, curr_atom.i_in)
-        connect!(top_model, curr_atom.o_out, self.o_out2)
+        connect!(top_model, curr_atom.o_out, next_atom.i_in; Z=active_z_function)
+        connect!(top_model, self.i_in2, curr_atom.i_in; Z=active_z_function)
+        connect!(top_model, curr_atom.o_out, self.o_out2; Z=active_z_function)
     end
 
     if !isempty(width_models)
         last_atom = width_models[end]
-        connect!(top_model, self.i_in2, last_atom.i_in)
-        connect!(top_model, last_atom.o_out, self.o_out2)
+        connect!(top_model, self.i_in2, last_atom.i_in; Z=active_z_function)
+        connect!(top_model, last_atom.o_out, self.o_out2; Z=active_z_function)
     end
 end
 
@@ -115,29 +123,29 @@ function build_HOmod!(top_model::CoupledDEVS, child::ModelRef, depth::Int, width
     end
 
     for atom in atomics[0]
-        connect!(top_model, self.i_in2, atom.i_in)
+        connect!(top_model, self.i_in2, atom.i_in; Z=active_z_function)
     end
     for i in 1:(width - 1)
         if !isempty(atomics[i])
-            connect!(top_model, self.i_in2, atomics[i][1].i_in)
+            connect!(top_model, self.i_in2, atomics[i][1].i_in; Z=active_z_function)
         end
     end
 
     for atom in atomics[0]
-        connect!(top_model, atom.o_out, child.i_in2)
+        connect!(top_model, atom.o_out, child.i_in2; Z=active_z_function)
     end
 
     if haskey(atomics, 1) && haskey(atomics, 0)
         for atom1 in atomics[1]
             for atom0 in atomics[0]
-                connect!(top_model, atom1.o_out, atom0.i_in)
+                connect!(top_model, atom1.o_out, atom0.i_in; Z=active_z_function)
             end
         end
     end
 
     for i in 2:(width - 1)
         for j in 1:length(atomics[i])
-            connect!(top_model, atomics[i][j].o_out, atomics[i-1][j+1].i_in)
+            connect!(top_model, atomics[i][j].o_out, atomics[i-1][j+1].i_in; Z=active_z_function)
         end
     end
 end
@@ -162,12 +170,12 @@ function build_devstone(type::Structure, name::String, depth::Int, width::Int, i
     child = add_submodel!(top_model, coupled_name, child_coupled)
 
     # Connect Parent to Child
-    connect!(top_model, self.i_in, child.i_in)
+    connect!(top_model, self.i_in, child.i_in; Z=active_z_function)
     if type == HO
-        connect!(top_model, self.i_in, child.i_in2)
+        connect!(top_model, self.i_in, child.i_in2; Z=active_z_function)
     end
     if has_out_port
-        connect!(top_model, child.o_out, self.o_out)
+        connect!(top_model, child.o_out, self.o_out; Z=active_z_function)
     end
 
     # Sub-topology Generation & Routing

+ 2 - 2
benchmarks/Agents/main.jl

@@ -84,9 +84,9 @@ function build_environment(type::Structure, devstone_model::CoupledDEVS, gen_per
         output = 6, period = gen_period, cycles = 1)
     add_submodel!(env, :devstone, devstone_model)
 
-    connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in)
+    connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in; Z=active_z_function)
     if type == HO || type == HOmod
-        connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in2)
+        connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in2; Z=active_z_function)
     end
     return env
 end

+ 133 - 111
benchmarks/pythonpdevs/devstone.py

@@ -8,40 +8,59 @@ from pypdevs.infinity import INFINITY
 from graphviz import Source
 
 import random
+
 random.seed(42)
 DIGITS = 3
 
+def tIdentity(msg):
+    return msg
+
+def tScaled(msg):
+    return msg ** 2
+
+
+translation_table = {i: i + 100 for i in range(1001)}
+def tAccessed(msg):
+    key = msg % 1000
+    return translation_table.get(key, msg)
+
+
+active_z_function = tIdentity
+
 
 class DelayedAtomic(AtomicDEVS):
-    def __init__(self, name: str, int_delay: float, ext_delay: float, add_out_port: bool = False, prep_time=0.0, mode: str = ""):
+    def __init__(self, name: str, int_delay: float, ext_delay: float, add_out_port: bool = False, prep_time=0.0,
+                 mode: str = ""):
         super().__init__(name)
         self.state = "passive"
         self.int_delay = int_delay
         self.ext_delay = ext_delay
         self.prep_time = prep_time
 
+        self.state = "passive", 2
+
         self.i_in = self.addInPort("i_in")
-        if add_out_port: # for HI and HO models
+        if add_out_port:  # for HI and HO models
             self.o_out = self.addOutPort("o_out")
 
         # Dynamic Structure extras
         self.mode = mode
-        self.out_ports = [] # used for dynamic structure model LI2HI
+        self.out_ports = []  # used for dynamic structure model LI2HI
 
     def intTransition(self):
         if self.int_delay:
             pystones(self.int_delay)
-        return "passive"
+        return "passive", self.state[1] + 1
 
     def timeAdvance(self):
-        if self.state == "active":
+        if self.state[0] == "active":
             return self.prep_time
         else:
             return INFINITY
 
     def outputFnc(self):
         if hasattr(self, "o_out") and self.o_out is not None:
-            return {self.o_out: [0]}
+            return {self.o_out: [self.state[1]]}
 
         # for DSDEVS LI2HI
         if len(self.out_ports) == 1 and self.out_ports[0].outline != []:
@@ -52,7 +71,7 @@ class DelayedAtomic(AtomicDEVS):
         if self.ext_delay:
             pystones(self.ext_delay)
 
-        return "active"
+        return "active", self.state[1]
 
     def modelTransition(self, state):
         result = False
@@ -70,9 +89,9 @@ class DelayedAtomic(AtomicDEVS):
             # which has a output port by default
             state["LI2HI"] = True
             state["name"] = self.name
-            self.out_ports.append(self.addOutPort("o_HI")) # standard LI model doesn't have by default
+            self.out_ports.append(self.addOutPort("o_HI"))  # standard LI model doesn't have by default
             # print(f"{self.name}: should be first call!!")
-            return True # send to the parent to connect ports
+            return True  # send to the parent to connect ports
         return False
 
     def HI2LI(self, state):
@@ -85,7 +104,8 @@ class DelayedAtomic(AtomicDEVS):
 
 
 class DelayedAtomicStats(DelayedAtomic):
-    def __init__(self, name: str, int_delay: float, ext_delay: float, add_out_port: bool = False, prep_time=0, mode:str = ""):
+    def __init__(self, name: str, int_delay: float, ext_delay: float, add_out_port: bool = False, prep_time=0,
+                 mode: str = ""):
         super().__init__(name, int_delay, ext_delay, add_out_port, prep_time, mode)
 
         self.int_count = 0
@@ -99,6 +119,7 @@ class DelayedAtomicStats(DelayedAtomic):
         self.ext_count += 1
         return super().extTransition(inputs)
 
+
 def getStats(model, display=True):
     total_i = 0
     total_e = 0
@@ -137,7 +158,7 @@ class DEVStoneWrapper(CoupledDEVS, ABC):
         self.i_in = self.addInPort("i_in")
         self.o_out = self.addOutPort("o_out")
 
-        self.models = [] # stores all models part of the coupled model
+        self.models = []  # stores all models part of the coupled model
         # added to deal with DS DEVS which don't keep it all in the component_set
 
         if depth < 1:
@@ -158,21 +179,21 @@ class DEVStoneWrapper(CoupledDEVS, ABC):
 
             self.models.append(self.addSubModel(atomic))
 
-            self.connectPorts(self.i_in, atomic.i_in)
-            self.connectPorts(atomic.o_out, self.o_out)
+            self.connectPorts(self.i_in, atomic.i_in, active_z_function)
+            self.connectPorts(atomic.o_out, self.o_out, active_z_function)
         else:
             coupled = self.gen_coupled()
             self.addSubModel(coupled)
-            self.connectPorts(self.i_in, coupled.i_in)
-            self.connectPorts(coupled.o_out, self.o_out)
+            self.connectPorts(self.i_in, coupled.i_in, active_z_function)
+            self.connectPorts(coupled.o_out, self.o_out, active_z_function)
 
             if dynamic:
-                return # width will be dynamically generated
+                return  # width will be dynamically generated
 
             # + (idx * 1e-6) to address too many transitions at the same time
             # => problem for Classic DEVS only it seems
             for idx in range(width - 1):
-                p_time = 1 - round(random.uniform(idx/self.width, (idx + 0.5)/self.width), DIGITS)
+                p_time = 1 - round(random.uniform(idx / self.width, (idx + 0.5) / self.width), DIGITS)
                 name = f"A{idx}"
                 if self.stats:
                     atomic = DelayedAtomicStats(name, int_delay, ext_delay,
@@ -182,31 +203,6 @@ class DEVStoneWrapper(CoupledDEVS, ABC):
                                            add_out_port=add_atomic_out_ports, prep_time=p_time, mode=mode)
                 self.models.append(self.addSubModel(atomic))
 
-    def dot(self, name) -> None:
-        result = ("\n\ndigraph {\n\tlayout=dot;"
-                  "\n\tnodesep=0.25;"
-                  "\n\tranksep=0.2;"
-                  "\n\trankdir=LR;"
-                  "\n\tsplines=ortho;\n")
-        result += f"\tCoupled_{self.depth}[shape=box, label=\"C_{self.depth}\"];\n"
-        coupled = self.component_set[0]
-        result += f"\t{coupled.name}[shape=box, label=\"{'C_' + '_'.join(coupled.name.split('_')[1:3])}\"];\n"
-        for model in self.models:
-            result += f"\t{model.name}[shape=ellipse, label=\"{'A_' + '_'.join(model.name.split('_')[1:3])}\"];\n"
-
-        for connections in self.i_in.outline:
-            result += f"\tCoupled_{self.depth}:i_in -> {str(connections).split('.')[-2]}:{connections.name};\n"
-
-        for model in self.models:
-            if not hasattr(model, "o_out"):
-                continue
-            for connections in model.o_out.outline:
-                result += f"\t{model.name}:o_out -> {str(connections).split('.')[2]}:{connections.name};\n"
-        result += "}\n"
-
-        src = Source(result)
-        src.view(filename=f'{name}_{self.depth}')
-
     @abstractmethod
     def gen_coupled(self):
         """ :return a coupled method with i_in and o_out ports"""
@@ -221,10 +217,10 @@ class LI(DEVStoneWrapper):
 
         for idx in range(1, len(self.component_set)):
             assert isinstance(self.component_set[idx], AtomicDEVS)
-            self.connectPorts(self.i_in, self.component_set[idx].i_in)
+            self.connectPorts(self.i_in, self.component_set[idx].i_in, active_z_function)
 
     def gen_coupled(self):
-        return LI(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+        return LI(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
                   prep_time=self.prep_time, stats=self.stats)
 
 
@@ -236,15 +232,15 @@ class HI(DEVStoneWrapper):
 
         if len(self.component_set) > 1:
             assert isinstance(self.component_set[-1], AtomicDEVS)
-            self.connectPorts(self.i_in, self.component_set[-1].i_in)
+            self.connectPorts(self.i_in, self.component_set[-1].i_in, active_z_function)
 
         for idx in range(1, len(self.component_set) - 1):
             assert isinstance(self.component_set[idx], AtomicDEVS)
-            self.connectPorts(self.component_set[idx].o_out, self.component_set[idx + 1].i_in)
-            self.connectPorts(self.i_in, self.component_set[idx].i_in)
+            self.connectPorts(self.component_set[idx].o_out, self.component_set[idx + 1].i_in, active_z_function)
+            self.connectPorts(self.i_in, self.component_set[idx].i_in, active_z_function)
 
     def gen_coupled(self):
-        return HI(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+        return HI(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
                   prep_time=self.prep_time, stats=self.stats)
 
 
@@ -259,21 +255,21 @@ class HO(DEVStoneWrapper):
 
         assert len(self.component_set) > 0
         if isinstance(self.component_set[0], CoupledDEVS):
-            self.connectPorts(self.i_in, self.component_set[0].i_in2) # seems wrong i_in -> i_in and i_in2 -> i_in2 not criss-crossed??
+            self.connectPorts(self.i_in, self.component_set[0].i_in2, active_z_function)  # seems wrong i_in -> i_in and i_in2 -> i_in2 not criss-crossed??
 
         if len(self.component_set) > 1:
             assert isinstance(self.component_set[-1], AtomicDEVS)
-            self.connectPorts(self.i_in2, self.component_set[-1].i_in)
-            self.connectPorts(self.component_set[-1].o_out, self.o_out2)
+            self.connectPorts(self.i_in2, self.component_set[-1].i_in, active_z_function)
+            self.connectPorts(self.component_set[-1].o_out, self.o_out2, active_z_function)
 
         for idx in range(1, len(self.component_set) - 1):
             assert isinstance(self.component_set[idx], AtomicDEVS)
             self.connectPorts(self.component_set[idx].o_out, self.component_set[idx + 1].i_in)
             self.connectPorts(self.i_in2, self.component_set[idx].i_in)
-            self.connectPorts(self.component_set[idx].o_out, self.o_out2)
+            self.connectPorts(self.component_set[idx].o_out, self.o_out2, active_z_function)
 
     def gen_coupled(self):
-        return HO(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+        return HO(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
                   prep_time=self.prep_time, stats=self.stats)
 
 
@@ -311,14 +307,15 @@ class HOmod(CoupledDEVS):
                 atomic = DelayedAtomic("A0", int_delay, ext_delay, add_out_port=True, prep_time=p_time)
             self.models.append(self.addSubModel(atomic))
 
-            self.connectPorts(self.i_in, atomic.i_in)
-            self.connectPorts(atomic.o_out, self.o_out)
+            self.connectPorts(self.i_in, atomic.i_in, active_z_function)
+            self.connectPorts(atomic.o_out, self.o_out, active_z_function)
         else:
-            c_name = f"C{depth-1}"
-            coupled = HOmod(c_name, self.depth - 1, self.width, self.int_delay, self.ext_delay, prep_time=prep_time, stats=stats)
+            c_name = f"C{depth - 1}"
+            coupled = HOmod(c_name, self.depth - 1, self.width, self.int_delay, self.ext_delay, prep_time=prep_time,
+                            stats=stats)
             self.addSubModel(coupled)
-            self.connectPorts(self.i_in, coupled.i_in)
-            self.connectPorts(coupled.o_out, self.o_out)
+            self.connectPorts(self.i_in, coupled.i_in, active_z_function)
+            self.connectPorts(coupled.o_out, self.o_out, active_z_function)
 
             if width >= 2:
                 atomics = defaultdict(list)
@@ -330,7 +327,7 @@ class HOmod(CoupledDEVS):
                         name = f"A{i}_{j}"
                         if self.stats:
                             atomic = DelayedAtomicStats(name, int_delay, ext_delay,
-                                                   add_out_port=True, prep_time=prep_time)
+                                                        add_out_port=True, prep_time=prep_time)
                         else:
                             atomic = DelayedAtomic(name, int_delay, ext_delay,
                                                    add_out_port=True, prep_time=prep_time)
@@ -339,20 +336,20 @@ class HOmod(CoupledDEVS):
 
                 # Connect EIC
                 for atomic in atomics[0]:
-                    self.connectPorts(self.i_in2, atomic.i_in)
+                    self.connectPorts(self.i_in2, atomic.i_in, active_z_function)
                 for i in range(1, width):
                     atomic_set = atomics[i]
-                    self.connectPorts(self.i_in2, atomic_set[0].i_in)
+                    self.connectPorts(self.i_in2, atomic_set[0].i_in, active_z_function)
 
                 # Connect IC
                 for atomic in atomics[0]:  # First row to coupled component
-                    self.connectPorts(atomic.o_out, coupled.i_in2)
+                    self.connectPorts(atomic.o_out, coupled.i_in2, active_z_function)
                 for i in range(len(atomics[1])):  # Second to first rows
                     for j in range(len(atomics[0])):
-                        self.connectPorts(atomics[1][i].o_out, atomics[0][j].i_in)
+                        self.connectPorts(atomics[1][i].o_out, atomics[0][j].i_in, active_z_function)
                 for i in range(2, width):  # Rest of rows
                     for j in range(len(atomics[i])):
-                        self.connectPorts(atomics[i][j].o_out, atomics[i - 1][j + 1].i_in)
+                        self.connectPorts(atomics[i][j].o_out, atomics[i - 1][j + 1].i_in, active_z_function)
 
 
 class LI2HI(DEVStoneWrapper):
@@ -370,12 +367,12 @@ class LI2HI(DEVStoneWrapper):
             self.connectPorts(self.i_in, self.component_set[idx].i_in)
 
     def gen_coupled(self):
-        return LI2HI(f"C{self.depth-1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
-                  prep_time=self.prep_time, stats=self.stats)
+        return LI2HI(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+                     prep_time=self.prep_time, stats=self.stats)
 
     def modelTransition(self, state):
         if state.get("LI2HI", True):
-            for i in range(len(self.component_set) - 1): # -1 because the last model can't be connected
+            for i in range(len(self.component_set) - 1):  # -1 because the last model can't be connected
                 # basically checks if it is an atomic model and if it got the extra output port
                 if hasattr(self.component_set[i], "out_ports") and len(self.component_set[i].out_ports) == 1:
                     # print(f"Connect {self.component_set[i].name} to {self.component_set[i+1].name}")
@@ -389,6 +386,7 @@ class HI2LI(DEVStoneWrapper):
     Dynamic DEVStone variant that starts as an HI
     and (gradually??) transforms into an LI model
     """
+
     def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, prep_time=0, stats=False):
         super().__init__(name, depth, width, int_delay, ext_delay, add_atomic_out_ports=True, prep_time=prep_time,
                          stats=stats, mode="HI2LI")
@@ -403,17 +401,17 @@ class HI2LI(DEVStoneWrapper):
             self.connectPorts(self.i_in, self.component_set[idx].i_in)
 
     def gen_coupled(self):
-        return HI2LI(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
-                  prep_time=self.prep_time, stats=self.stats)
+        return HI2LI(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+                     prep_time=self.prep_time, stats=self.stats)
 
 
 class DynamicGenerator(AtomicDEVS):
     def __init__(self, name: str, period: float = 1, target: int = 1, num: int = 1):
         super().__init__(name)
         self.period = period
-        self.number = num # how many models need to be generated per cycle
+        self.number = num  # how many models need to be generated per cycle
 
-        self.state = target + self.number # total models to generate
+        self.state = target + self.number  # total models to generate
         # the number of models to generate per cycle is added
         # since the internal transition occurs before the
         # model transition, otherwise the model generation
@@ -478,38 +476,42 @@ class Distributer(AtomicDEVS):
 
 class DynamicDEVStoneWrapper(DEVStoneWrapper, ABC):
     def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float,
-                 add_atomic_out_ports: bool = False, /, prep_time=0, stats=False, root=False, mode: str = "", number: int = 1, gen_mode: str="uniform"):
+                 add_atomic_out_ports: bool = False, /, prep_time=0, stats=False, root=False, mode: str = "",
+                 number: int = 1, gen_mode: str = "uniform"):
         if number <= 0:
             raise ValueError("number of models to be generated must be greater than zero")
 
         self.root = root
         self.mode = mode
-        self.created = 0 # keeps track of how many atomic models have been created
+        self.created = 0  # keeps track of how many atomic models have been created
         self.current_width = 1
         self.number = number
-        self.max_gen = width - 1 # dynamically generate atomic components until width is reached excludes the coupled model
+        self.max_gen = width - 1  # dynamically generate atomic components until width is reached excludes the coupled model
 
         super().__init__(name, depth, width, int_delay, ext_delay, add_atomic_out_ports, prep_time=prep_time,
                          stats=stats, mode=mode, dynamic=True)
 
         self.connector = self.i_in
         if self.depth == 1:
-            self.generator = self.addSubModel(DynamicGenerator(self.name + "_gen", target=self.max_gen, num=self.number))
+            self.generator = self.addSubModel(
+                DynamicGenerator(self.name + "_gen", target=self.max_gen, num=self.number))
 
     def createAtomic(self):
         name = f"Atomic_0_{self.current_width}"
         if self.depth > 1:
-            name = f"Atomic_{self.depth-1}_{self.current_width-1}"
+            name = f"Atomic_{self.depth - 1}_{self.current_width - 1}"
 
-        p_time = 1 - round(random.uniform((self.current_width - 1) / self.width, ((self.current_width - 1) + 0.5) / self.width), DIGITS)
+        p_time = 1 - round(
+            random.uniform((self.current_width - 1) / self.width, ((self.current_width - 1) + 0.5) / self.width),
+            DIGITS)
         if self.stats:
             atomic = DelayedAtomicStats(name, self.int_delay, self.ext_delay,
-                                          add_out_port=self.add_atomic_out_ports, prep_time=p_time,
-                                          mode=self.mode)
+                                        add_out_port=self.add_atomic_out_ports, prep_time=p_time,
+                                        mode=self.mode)
         else:
             atomic = DelayedAtomic(name, self.int_delay, self.ext_delay,
-                                     add_out_port=self.add_atomic_out_ports, prep_time=p_time,
-                                     mode=self.mode)
+                                   add_out_port=self.add_atomic_out_ports, prep_time=p_time,
+                                   mode=self.mode)
 
         self.models.append(self.addSubModel(atomic))
         return atomic
@@ -525,7 +527,8 @@ class DynamicDEVStoneWrapper(DEVStoneWrapper, ABC):
                 self.connectPorts(self.connector, atom.i_in)
 
                 if len(self.models) > 1:
-                    prev = self.models[-2] # new model was already added so the previous one isn't the last in the list anymore
+                    prev = self.models[
+                        -2]  # new model was already added so the previous one isn't the last in the list anymore
                     if isinstance(prev, AtomicDEVS) and hasattr(prev, "o_out"):
                         self.connectPorts(prev.o_out, atom.i_in)
                     if hasattr(self, "o_out2"):
@@ -535,12 +538,12 @@ class DynamicDEVStoneWrapper(DEVStoneWrapper, ABC):
 
                 if self.current_width > self.width:
                     raise RuntimeError(f"The width has grown beyond what was specified!"
-                                   f"\n current width: {self.current_width}"
-                                   f"\n specified width: {self.width}")
+                                       f"\n current width: {self.current_width}"
+                                       f"\n specified width: {self.width}")
 
             # enables visualisation of each level (coupled model)
-                # if self.current_width == self.width:
-                #     self.dot(f"dLI_{self.depth}")
+            # if self.current_width == self.width:
+            #     self.dot(f"dLI_{self.depth}")
 
             if not self.root:
                 state["created"] += number
@@ -554,11 +557,14 @@ class dLI(DynamicDEVStoneWrapper):
     """
     A LI model which grows in width
     """
-    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, /, prep_time=0, stats=False, root=True, number: int = 1, gen_mode: str = "uniform"):
-        super().__init__(name, depth, width, int_delay, ext_delay, False, prep_time, stats, mode="LI-Dynamic", root=root, number=number, gen_mode=gen_mode)
+
+    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, /, prep_time=0,
+                 stats=False, root=True, number: int = 1, gen_mode: str = "uniform"):
+        super().__init__(name, depth, width, int_delay, ext_delay, False, prep_time, stats, mode="LI-Dynamic",
+                         root=root, number=number, gen_mode=gen_mode)
 
     def gen_coupled(self):
-        return dLI(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+        return dLI(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
                    prep_time=self.prep_time, stats=self.stats, root=False, number=self.number)
 
 
@@ -566,8 +572,11 @@ class mdLI(DynamicDEVStoneWrapper):
     """
     A LI model which grows in width
     """
-    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, /, prep_time=0, stats=False, root=True, number: int = 1, gen_mode: str = "uniform"):
-        super().__init__(name, depth, width, int_delay, ext_delay, False, prep_time, stats, mode="LI-Dynamic", root=root, number=number, gen_mode=gen_mode)
+
+    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, /, prep_time=0,
+                 stats=False, root=True, number: int = 1, gen_mode: str = "uniform"):
+        super().__init__(name, depth, width, int_delay, ext_delay, False, prep_time, stats, mode="LI-Dynamic",
+                         root=root, number=number, gen_mode=gen_mode)
 
         intermediate = Distributer("distributer")
         self.addSubModel(intermediate)
@@ -575,21 +584,23 @@ class mdLI(DynamicDEVStoneWrapper):
         self.connectPorts(self.i_in, intermediate.i_in)
         self.connector = intermediate.o_out
 
-
     def gen_coupled(self):
-        return mdLI(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
-                   prep_time=self.prep_time, stats=self.stats, root=False, number=self.number)
+        return mdLI(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+                    prep_time=self.prep_time, stats=self.stats, root=False, number=self.number)
 
 
 class dHI(DynamicDEVStoneWrapper):
     """
     A HI model which grows in width
     """
-    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, /, prep_time=0, stats=False, root=True, number: int = 1, gen_mode: str = "uniform"):
-        super().__init__(name, depth, width, int_delay, ext_delay, True, prep_time, stats, mode="HI-Dynamic", root=root, number=number, gen_mode=gen_mode)
+
+    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, /, prep_time=0,
+                 stats=False, root=True, number: int = 1, gen_mode: str = "uniform"):
+        super().__init__(name, depth, width, int_delay, ext_delay, True, prep_time, stats, mode="HI-Dynamic", root=root,
+                         number=number, gen_mode=gen_mode)
 
     def gen_coupled(self):
-        return dHI(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+        return dHI(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
                    prep_time=self.prep_time, stats=self.stats, root=False, number=self.number)
 
 
@@ -597,8 +608,11 @@ class mdHI(DynamicDEVStoneWrapper):
     """
     A HI model which grows in width
     """
-    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, /, prep_time=0, stats=False, root: bool = True, number: int = 1, gen_mode: str = "uniform"):
-        super().__init__(name, depth, width, int_delay, ext_delay, True, prep_time=prep_time, stats=stats, mode="HI-Dynamic", root=root, number=number, gen_mode=gen_mode)
+
+    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, /, prep_time=0,
+                 stats=False, root: bool = True, number: int = 1, gen_mode: str = "uniform"):
+        super().__init__(name, depth, width, int_delay, ext_delay, True, prep_time=prep_time, stats=stats,
+                         mode="HI-Dynamic", root=root, number=number, gen_mode=gen_mode)
         intermediate = Distributer("distributer")
         self.addSubModel(intermediate)
 
@@ -606,36 +620,43 @@ class mdHI(DynamicDEVStoneWrapper):
         self.connector = intermediate.o_out
 
     def gen_coupled(self):
-        return mdHI(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
-                   prep_time=self.prep_time, stats=self.stats, root=False, number=self.number)
+        return mdHI(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay,
+                    prep_time=self.prep_time, stats=self.stats, root=False, number=self.number)
 
 
 class dHO(DynamicDEVStoneWrapper):
-    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, prep_time=0, stats=False, root: bool = True, number: int = 1, gen_mode: str = "uniform"):
-        super().__init__(name, depth, width, int_delay, ext_delay, True, prep_time=prep_time, stats=stats, mode="HO-dynamic", root=root, number=number, gen_mode=gen_mode)
+    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, prep_time=0, stats=False,
+                 root: bool = True, number: int = 1, gen_mode: str = "uniform"):
+        super().__init__(name, depth, width, int_delay, ext_delay, True, prep_time=prep_time, stats=stats,
+                         mode="HO-dynamic", root=root, number=number, gen_mode=gen_mode)
 
         self.i_in2 = self.addInPort("i_in2")
         self.o_out2 = self.addOutPort("o_out2")
 
         assert len(self.component_set) > 0
         if isinstance(self.component_set[0], CoupledDEVS):
-            self.connectPorts(self.i_in, self.component_set[0].i_in2) # seems wrong i_in -> i_in and i_in2 -> i_in2 not criss-crossed??
+            self.connectPorts(self.i_in, self.component_set[
+                0].i_in2)  # seems wrong i_in -> i_in and i_in2 -> i_in2 not criss-crossed??
         self.connector = self.i_in2
 
     def gen_coupled(self):
-        return dHO(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay, self.prep_time, self.stats, root=False, number=self.number)
+        return dHO(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay, self.prep_time,
+                   self.stats, root=False, number=self.number)
 
 
 class mdHO(DynamicDEVStoneWrapper):
-    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, prep_time=0, stats=False, root: bool = True, number: int = 1, gen_mode: str = "uniform"):
-        super().__init__(name, depth, width, int_delay, ext_delay, True, prep_time=prep_time, stats=stats, mode="HO-dynamic", root=root, number=number, gen_mode=gen_mode)
+    def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, prep_time=0, stats=False,
+                 root: bool = True, number: int = 1, gen_mode: str = "uniform"):
+        super().__init__(name, depth, width, int_delay, ext_delay, True, prep_time=prep_time, stats=stats,
+                         mode="HO-dynamic", root=root, number=number, gen_mode=gen_mode)
 
         self.i_in2 = self.addInPort("i_in2")
         self.o_out2 = self.addOutPort("o_out2")
 
         assert len(self.component_set) > 0
         if isinstance(self.component_set[0], CoupledDEVS):
-            self.connectPorts(self.i_in, self.component_set[0].i_in2) # seems wrong i_in -> i_in and i_in2 -> i_in2 not criss-crossed??
+            self.connectPorts(self.i_in, self.component_set[
+                0].i_in2)  # seems wrong i_in -> i_in and i_in2 -> i_in2 not criss-crossed??
 
         intermediate = Distributer("distributer")
         self.addSubModel(intermediate)
@@ -643,7 +664,8 @@ class mdHO(DynamicDEVStoneWrapper):
         self.connector = intermediate.o_out
 
     def gen_coupled(self):
-        return mdHO(f"C{self.depth -1}", self.depth - 1, self.width, self.int_delay, self.ext_delay, self.prep_time, self.stats, root=False, number=self.number)
+        return mdHO(f"C{self.depth - 1}", self.depth - 1, self.width, self.int_delay, self.ext_delay, self.prep_time,
+                    self.stats, root=False, number=self.number)
 
 
 class dynamicTest(CoupledDEVS):
@@ -653,7 +675,7 @@ class dynamicTest(CoupledDEVS):
         self.o_out = self.addOutPort("o_out")
 
         self.coupled = self.addSubModel(dynamicTest2())
-        self.model1 = self.addSubModel(DelayedAtomic("root",0, 0, True, 0.1))
+        self.model1 = self.addSubModel(DelayedAtomic("root", 0, 0, True, 0.1))
         self.model2 = self.addSubModel(DelayedAtomic("model1", 0, 0, True, 0.1))
         self.model3 = self.addSubModel(DelayedAtomic("model2", 0, 0, True, 0.1))
         # self.model4 = self.addSubModel(DelayedAtomic("model3", 0, 0, True, 0.1))

+ 3 - 4
benchmarks/pythonpdevs/main.py

@@ -1,12 +1,11 @@
 import argparse
 import sys
 import time
-from functools import partial
 
 from pypdevs.DEVS import CoupledDEVS
 from pypdevs.simulator import Simulator
 
-from devstone import LI, HI, HO, HOmod, LI2HI, HI2LI, dLI, mdLI, dHI, mdHI, dHO, mdHO, dynamicTest, getStats
+from devstone import LI, HI, HO, HOmod, LI2HI, HI2LI, dLI, mdLI, dHI, mdHI, dHO, mdHO, dynamicTest, getStats, active_z_function
 from generator import Generator
 from benchmarks.model_properties import model_properties
 
@@ -30,11 +29,11 @@ class DEVStoneEnvironment(CoupledDEVS):
         self.addSubModel(generator)
         self.addSubModel(devstone_model)
 
-        self.connectPorts(generator.o_out, devstone_model.i_in)
+        self.connectPorts(generator.o_out, devstone_model.i_in, active_z_function)
 
         for model in HO_MODELS:
             if isinstance(devstone_model, model):
-                self.connectPorts(generator.o_out, devstone_model.i_in2)
+                self.connectPorts(generator.o_out, devstone_model.i_in2, active_z_function)
 
 
 MODEL_TYPES = ("LI", "HI", "HO", "HOmod", "LI2HI", "HI2LI", "dLI", "mdLI", "dHI", "mdHI", "dHO", "mdHO", "test")