diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2019-12-18 11:39:31 +0100 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2019-12-18 11:39:31 +0100 |
commit | 342468318abd2004a2f01105fb0c9c0507c62211 (patch) | |
tree | 42fab479820bb54f80c08e0e36cfe79faedb27e2 | |
parent | 6dea5e30f9023b7748d9249f80aaeeded6011bc1 (diff) |
workload/simulate: Fix param handover
-rwxr-xr-x | bin/workload.py | 4 | ||||
-rwxr-xr-x | lib/automata.py | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/bin/workload.py b/bin/workload.py index d2e5b34..c9d4e76 100755 --- a/bin/workload.py +++ b/bin/workload.py @@ -22,9 +22,9 @@ prev_param = None for trace_part in timedword: print('Trace Part {}'.format(trace_part)) if type(trace_part) is TimedWord: - result = pta.simulate(trace_part, orig_state=prev_state) + result = pta.simulate(trace_part, orig_state=prev_state, orig_param=prev_param) elif type(trace_part) is Workload: - result = pta.simulate(trace_part.word, orig_state=prev_state) + result = pta.simulate(trace_part.word, orig_state=prev_state, orig_param=prev_param) if prev_state != result.end_state: print('Warning: loop starts in state {}, but terminates in {}'.format(prev_state, result.end_state.name)) if prev_param != result.parameters: diff --git a/lib/automata.py b/lib/automata.py index 02dbfb6..552b482 100755 --- a/lib/automata.py +++ b/lib/automata.py @@ -965,7 +965,7 @@ class PTA: else: return generator - def simulate(self, trace: list, orig_state: str = 'UNINITIALIZED', accounting=None): + def simulate(self, trace: list, orig_state: str = 'UNINITIALIZED', orig_param=None, accounting=None): u""" Simulate a single run through the PTA and return total energy, duration, final state, and resulting parameters. @@ -973,6 +973,8 @@ class PTA: or list of (Transition, argument tuple, parameter) tuples originating from dfs. The tuple (None, duration) represents a sleep time between states in us :param orig_state: origin state, default UNINITIALIZED + :param orig_param: initial parameters, default: `self.initial_param_values` + :param accounting: EnergyAccounting object, default empty :returns: SimulationResult with duration in s, total energy in J, end state, and final parameters """ @@ -984,7 +986,10 @@ class PTA: state = orig_state else: state = self.state[orig_state] - param_dict = dict([[self.parameters[i], self.initial_param_values[i]] for i in range(len(self.parameters))]) + if orig_param: + param_dict = orig_param.copy() + else: + param_dict = dict([[self.parameters[i], self.initial_param_values[i]] for i in range(len(self.parameters))]) for function in trace: if isinstance(function[0], Transition): function_name = function[0].name |