bug: Cannot run with single state update

This commit is contained in:
Joshua E. Jodesty 2018-11-08 17:42:18 -05:00
parent 84963ae8c1
commit 15c1d2fa8c
3 changed files with 35 additions and 31 deletions

View File

@ -23,7 +23,7 @@ def exception_handler(f, m_step, sL, last_mut_obj, _input):
return f(m_step, sL, sL[-2], _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] last_in_obj = sL[-1]
_input = exception_handler(getBehaviorInput, m_step, sL, last_in_obj, behavior_funcs) _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 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) sL.append(last_in_copy)
del last_in_copy del last_in_copy
return sL 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 m_step = 0
states_list_copy = deepcopy(states_list) states_list_copy = deepcopy(states_list)
genesis_states = states_list_copy[-1] genesis_states = states_list_copy[-1]
@ -50,7 +50,8 @@ def block_gen(states_list, configs, env_processes, t_step):
m_step += 1 m_step += 1
for config in configs: for config in configs:
s_conf, b_conf = config[0], config[1] 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) # print(b_conf)
m_step += 1 m_step += 1
@ -60,29 +61,31 @@ def block_gen(states_list, configs, env_processes, t_step):
# rename pipe # 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] time_seq = [x + 1 for x in time_seq]
simulation_list = [states_list] simulation_list = [states_list]
for time_step in time_seq: for time_step in time_seq:
pipeline_run = block_gen(simulation_list[-1], configs, env_processes, time_step) pipe_run = block_gen(simulation_list[-1], configs, env_processes, time_step, run)
_, *pipeline_run = pipeline_run _, *pipe_run = pipe_run
simulation_list.append(pipeline_run) simulation_list.append(pipe_run)
return simulation_list return simulation_list
# Del head # Del head
def simulation(states_list, configs, env_processes, time_seq, runs): def simulation(states_list, configs, env_processes, time_seq, runs):
pipeline_run = [] pipe_run = []
for run in range(runs): for run in range(runs):
if run == 0: run += 1
head, *tail = pipeline(states_list, configs, env_processes, time_seq) if run == 1:
head[-1]['mech_step'], head[-1]['time_step'] = 0, 0 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 simulation_list = [head] + tail
pipeline_run += simulation_list pipe_run += simulation_list
# print(pipe_run)
else: else:
transient_states_list = [pipeline_run[-1][-1]] transient_states_list = [pipe_run[-1][-1]]
_, *tail = pipeline(transient_states_list, configs, env_processes, time_seq) _, *tail = pipe(transient_states_list, configs, env_processes, time_seq, run)
pipeline_run += tail pipe_run += tail
return pipeline_run return pipe_run

View File

@ -10,7 +10,7 @@ def main():
states_list = [state_dict] states_list = [state_dict]
ep = list(exogenous_states.values()) ep = list(exogenous_states.values())
configs = generate_config(state_dict, mechanisms, ep) 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(tabulate(create_tensor_field(mechanisms, ep), headers='keys', tablefmt='psql'))
print print
# print(configs) # print(configs)

View File

@ -107,39 +107,40 @@ env_processes = {
"s4": proc_trigger('2018-10-01 15:16:25', env_b) "s4": proc_trigger('2018-10-01 15:16:25', env_b)
} }
# test return vs. non-return functions as lambdas # lambdas
# test fully defined functions
# genesis Sites should always be there # 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 = { mechanisms = {
"m1": { "m1": {
"behaviors": { "behaviors": {
# "b1": b1m1, # lambda step, sL, s: s['s1'] + 1, "b1": b1m1, # lambda step, sL, s: s['s1'] + 1,
# "b2": b2m1 "b2": b2m1
}, },
"states": { # exclude only. TypeError: reduce() of empty sequence with no initial value "states": { # exclude only. TypeError: reduce() of empty sequence with no initial value
"s1": s1m1, "s1": s1m1,
# "s2": s2m1 "s2": s2m1
} }
}, },
"m2": { "m2": {
"behaviors": { "behaviors": {
"b1": b1m2, "b1": b1m2,
# "b2": b2m2 "b2": b2m2
}, },
"states": { "states": {
# "s1": s1m2, "s1": s1m2,
# "s2": s2m2 "s2": s2m2
} }
}, },
"m3": { "m3": {
"behaviors": { "behaviors": {
# "b1": b1m3, "b1": b1m3,
# "b2": b2m3 #toggle for error "b2": b2m3
}, },
"states": { "states": {
# "s1": s1m3, "s1": s1m3,
# "s2": s2m3 "s2": s2m3
} }
} }
} }