From 15c1d2fa8c26339f58cfab52e7b3f031f039fbb3 Mon Sep 17 00:00:00 2001 From: "Joshua E. Jodesty" Date: Thu, 8 Nov 2018 17:42:18 -0500 Subject: [PATCH] bug: Cannot run with single state update --- engine/mechanismExecutor.py | 37 ++++++++++++++++++++----------------- engine/run.py | 2 +- ui/config.py | 27 ++++++++++++++------------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/engine/mechanismExecutor.py b/engine/mechanismExecutor.py index b275567..569b192 100644 --- a/engine/mechanismExecutor.py +++ b/engine/mechanismExecutor.py @@ -23,7 +23,7 @@ def exception_handler(f, m_step, sL, last_mut_obj, _input): return f(m_step, sL, sL[-2], _input) -def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step): +def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step, run): last_in_obj = sL[-1] _input = exception_handler(getBehaviorInput, m_step, sL, last_in_obj, behavior_funcs) @@ -33,14 +33,14 @@ def mech_step(m_step, sL, state_funcs, behavior_funcs, env_processes, t_step): apply_env_proc(env_processes, last_in_copy, last_in_copy['timestamp']) # mutating last_in_copy - last_in_copy["mech_step"], last_in_copy["time_step"] = m_step, t_step + last_in_copy["mech_step"], last_in_copy["time_step"], last_in_copy['run'] = m_step, t_step, run sL.append(last_in_copy) del last_in_copy return sL -def block_gen(states_list, configs, env_processes, t_step): +def block_gen(states_list, configs, env_processes, t_step, run): m_step = 0 states_list_copy = deepcopy(states_list) genesis_states = states_list_copy[-1] @@ -50,7 +50,8 @@ def block_gen(states_list, configs, env_processes, t_step): m_step += 1 for config in configs: s_conf, b_conf = config[0], config[1] - states_list = mech_step(m_step, states_list, s_conf, b_conf, env_processes, t_step) + states_list = mech_step(m_step, states_list, s_conf, b_conf, env_processes, t_step, run) + # print(states_list) # print(b_conf) m_step += 1 @@ -60,29 +61,31 @@ def block_gen(states_list, configs, env_processes, t_step): # rename pipe -def pipeline(states_list, configs, env_processes, time_seq): +def pipe(states_list, configs, env_processes, time_seq, run): time_seq = [x + 1 for x in time_seq] simulation_list = [states_list] for time_step in time_seq: - pipeline_run = block_gen(simulation_list[-1], configs, env_processes, time_step) - _, *pipeline_run = pipeline_run - simulation_list.append(pipeline_run) + pipe_run = block_gen(simulation_list[-1], configs, env_processes, time_step, run) + _, *pipe_run = pipe_run + simulation_list.append(pipe_run) return simulation_list # Del head def simulation(states_list, configs, env_processes, time_seq, runs): - pipeline_run = [] + pipe_run = [] for run in range(runs): - if run == 0: - head, *tail = pipeline(states_list, configs, env_processes, time_seq) - head[-1]['mech_step'], head[-1]['time_step'] = 0, 0 + run += 1 + if run == 1: + head, *tail = pipe(states_list, configs, env_processes, time_seq, run) + head[-1]['mech_step'], head[-1]['time_step'], head[-1]['run'] = 0, 0, 0 simulation_list = [head] + tail - pipeline_run += simulation_list + pipe_run += simulation_list + # print(pipe_run) else: - transient_states_list = [pipeline_run[-1][-1]] - _, *tail = pipeline(transient_states_list, configs, env_processes, time_seq) - pipeline_run += tail + transient_states_list = [pipe_run[-1][-1]] + _, *tail = pipe(transient_states_list, configs, env_processes, time_seq, run) + pipe_run += tail - return pipeline_run \ No newline at end of file + return pipe_run \ No newline at end of file diff --git a/engine/run.py b/engine/run.py index 25e26d4..4ff8d01 100644 --- a/engine/run.py +++ b/engine/run.py @@ -10,7 +10,7 @@ def main(): states_list = [state_dict] ep = list(exogenous_states.values()) configs = generate_config(state_dict, mechanisms, ep) - print(len(configs)) + # print(len(configs)) print(tabulate(create_tensor_field(mechanisms, ep), headers='keys', tablefmt='psql')) print # print(configs) diff --git a/ui/config.py b/ui/config.py index d6a37c7..78e7ac4 100644 --- a/ui/config.py +++ b/ui/config.py @@ -107,39 +107,40 @@ env_processes = { "s4": proc_trigger('2018-10-01 15:16:25', env_b) } -# test return vs. non-return functions as lambdas -# test fully defined functions +# lambdas # genesis Sites should always be there -behavior_ops = [foldr(_ + _), lambda x: x + 0] +# [1, 2] +behavior_ops = [ foldr(_ + _), lambda x: x + 0 ] +# need at least 1 behaviour and 1 state function for the 1st mech with behaviors mechanisms = { "m1": { "behaviors": { - # "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, - # "b2": b2m1 + "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, + "b2": b2m1 }, "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value "s1": s1m1, - # "s2": s2m1 + "s2": s2m1 } }, "m2": { "behaviors": { "b1": b1m2, - # "b2": b2m2 + "b2": b2m2 }, "states": { - # "s1": s1m2, - # "s2": s2m2 + "s1": s1m2, + "s2": s2m2 } }, "m3": { "behaviors": { - # "b1": b1m3, - # "b2": b2m3 #toggle for error + "b1": b1m3, + "b2": b2m3 }, "states": { - # "s1": s1m3, - # "s2": s2m3 + "s1": s1m3, + "s2": s2m3 } } }