diff --git a/SimCAD/__init__.py b/SimCAD/__init__.py index bd4d6aa..3f660d7 100644 --- a/SimCAD/__init__.py +++ b/SimCAD/__init__.py @@ -1,2 +1,2 @@ configs = [] -# \ No newline at end of file +# diff --git a/SimCAD/configuration/__init__.py b/SimCAD/configuration/__init__.py index 0af1af7..223de64 100644 --- a/SimCAD/configuration/__init__.py +++ b/SimCAD/configuration/__init__.py @@ -49,7 +49,6 @@ class Processor: self.state_identity = id.state_identity self.apply_identity_funcs = id.apply_identity_funcs - # Make returntype chosen by user. def create_matrix_field(self, mechanisms, key): if key == 'states': identity = self.state_identity @@ -62,11 +61,8 @@ class Processor: else: return pd.DataFrame({'empty': []}) - # Maybe Refactor to only use dictionary BUT I used dfs to fill NAs. Perhaps fill def generate_config(self, state_dict, mechanisms, exo_proc): - # ToDo: include False / False case - # ToDo: Use Range multiplier instead for loop iterator def no_update_handler(bdf, sdf): if (bdf.empty == False) and (sdf.empty == True): bdf_values = bdf.values.tolist() @@ -98,4 +94,4 @@ class Processor: sdf_values, bdf_values = only_ep_handler(state_dict) zipped_list = list(zip(sdf_values, bdf_values)) - return list(map(lambda x: (x[0] + exo_proc, x[1]), zipped_list)) \ No newline at end of file + return list(map(lambda x: (x[0] + exo_proc, x[1]), zipped_list)) diff --git a/SimCAD/configuration/utils/__init__.py b/SimCAD/configuration/utils/__init__.py index 5364566..62c339a 100644 --- a/SimCAD/configuration/utils/__init__.py +++ b/SimCAD/configuration/utils/__init__.py @@ -8,7 +8,6 @@ class TensorFieldReport: def __init__(self, config_proc): self.config_proc = config_proc - # ??? dont for-loop to apply exo_procs, use exo_proc struct def create_tensor_field(self, mechanisms, exo_proc, keys=['behaviors', 'states']): dfs = [self.config_proc.create_matrix_field(mechanisms, k) for k in keys] df = pd.concat(dfs, axis=1) @@ -19,7 +18,6 @@ class TensorFieldReport: def bound_norm_random(rng, low, high): - # Add RNG Seed res = rng.normal((high+low)/2,(high-low)/6) if (reshigh): res = bound_norm_random(rng, low, high) @@ -34,7 +32,6 @@ def proc_trigger(trigger_step, update_f, step): return lambda x: x -# accept timedelta instead of timedelta params t_delta = timedelta(days=0, minutes=0, seconds=30) def time_step(dt_str, dt_format='%Y-%m-%d %H:%M:%S', _timedelta = t_delta): dt = datetime.strptime(dt_str, dt_format) @@ -42,7 +39,6 @@ def time_step(dt_str, dt_format='%Y-%m-%d %H:%M:%S', _timedelta = t_delta): return t.strftime(dt_format) -# accept timedelta instead of timedelta params t_delta = timedelta(days=0, minutes=0, seconds=1) def ep_time_step(s, dt_str, fromat_str='%Y-%m-%d %H:%M:%S', _timedelta = t_delta): if s['mech_step'] == 0: @@ -54,7 +50,7 @@ def ep_time_step(s, dt_str, fromat_str='%Y-%m-%d %H:%M:%S', _timedelta = t_delta def exo_update_per_ts(ep): @curried def ep_decorator(f, y, step, sL, s, _input): - if s['mech_step'] + 1 == 1: # inside f body to reduce performance costs + if s['mech_step'] + 1 == 1: return f(step, sL, s, _input) else: return (y, s[y]) diff --git a/SimCAD/configuration/utils/behaviorAggregation.py b/SimCAD/configuration/utils/behaviorAggregation.py index abde5d6..5f8b5f6 100644 --- a/SimCAD/configuration/utils/behaviorAggregation.py +++ b/SimCAD/configuration/utils/behaviorAggregation.py @@ -27,8 +27,7 @@ def foldr_dict_vals(f, d): def sum_dict_values(): return foldr_dict_vals(add) -# AttributeError: 'int' object has no attribute 'keys' -# config7c + @curried def dict_op(f, d1, d2): def set_base_value(target_dict, source_dict, key): @@ -44,6 +43,3 @@ def dict_op(f, d1, d2): def dict_elemwise_sum(): return dict_op(add) - - -# class BehaviorAggregation: \ No newline at end of file diff --git a/SimCAD/engine/__init__.py b/SimCAD/engine/__init__.py index 9f87879..97fa7ce 100644 --- a/SimCAD/engine/__init__.py +++ b/SimCAD/engine/__init__.py @@ -11,7 +11,6 @@ class ExecutionMode: multi_proc = 'multi_proc' -# ToDo: switch / rename self.name & context ?? class ExecutionContext: def __init__(self, context=ExecutionMode.multi_proc): self.name = context @@ -65,8 +64,6 @@ class Executor: config_idx += 1 - # Dimensions: N x r x mechs - if self.exec_context == ExecutionMode.single_proc: tensor_field = create_tensor_field(mechanisms.pop(), eps.pop()) result = self.exec_method(simulation_execs, states_lists, configs_structs, env_processes_list, Ts, Ns) @@ -77,4 +74,4 @@ class Executor: results = [] for result, mechanism, ep in list(zip(simulations, mechanisms, eps)): results.append((flatten(result), create_tensor_field(mechanism, ep))) - return results \ No newline at end of file + return results diff --git a/SimCAD/engine/simulation.py b/SimCAD/engine/simulation.py index 271f538..2660d2a 100644 --- a/SimCAD/engine/simulation.py +++ b/SimCAD/engine/simulation.py @@ -1,10 +1,7 @@ from copy import deepcopy from fn.op import foldr, call - -from SimCAD.utils import rename from SimCAD.engine.utils import engine_exception - id_exception = engine_exception(KeyError, KeyError, None) @@ -14,7 +11,6 @@ class Executor: self.state_update_exception = state_update_exception self.behavior_update_exception = behavior_update_exception - # Data Type reduction def get_behavior_input(self, step, sL, s, funcs): ops = self.behavior_ops[::-1] @@ -27,18 +23,16 @@ class Executor: for state in state_dict.keys(): if state in list(env_processes.keys()): env_state = env_processes[state] - if (env_state.__name__ == '_curried') or (env_state.__name__ == 'proc_trigger'): # might want to change + if (env_state.__name__ == '_curried') or (env_state.__name__ == 'proc_trigger'): state_dict[state] = env_state(step)(state_dict[state]) else: state_dict[state] = env_state(state_dict[state]) - def mech_step(self, m_step, sL, state_funcs, behavior_funcs, env_processes, t_step, run): last_in_obj = sL[-1] _input = self.state_update_exception(self.get_behavior_input(m_step, sL, last_in_obj, behavior_funcs)) - # ToDo: add env_proc generator to `last_in_copy` iterator as wrapper function last_in_copy = dict([self.behavior_update_exception(f(m_step, sL, last_in_obj, _input)) for f in state_funcs]) for k in last_in_obj: @@ -47,8 +41,7 @@ class Executor: del last_in_obj - # make env proc trigger field agnostic - self.apply_env_proc(env_processes, last_in_copy, last_in_copy['timestamp']) # mutating last_in_copy + self.apply_env_proc(env_processes, last_in_copy, last_in_copy['timestamp']) last_in_copy["mech_step"], last_in_copy["time_step"], last_in_copy['run'] = m_step, t_step, run sL.append(last_in_copy) @@ -59,8 +52,6 @@ class Executor: def mech_pipeline(self, states_list, configs, env_processes, t_step, run): m_step = 0 states_list_copy = deepcopy(states_list) - # print(states_list_copy) - # remove copy genesis_states = states_list_copy[-1] genesis_states['mech_step'], genesis_states['time_step'] = m_step, t_step states_list = [genesis_states] @@ -75,11 +66,9 @@ class Executor: return states_list - # rename pipe def block_pipeline(self, states_list, configs, env_processes, time_seq, run): time_seq = [x + 1 for x in time_seq] simulation_list = [states_list] - # print(len(configs)) for time_step in time_seq: pipe_run = self.mech_pipeline(simulation_list[-1], configs, env_processes, time_step, run) _, *pipe_run = pipe_run @@ -87,12 +76,11 @@ class Executor: return simulation_list - # Del _ / head def simulation(self, states_list, configs, env_processes, time_seq, runs): pipe_run = [] for run in range(runs): run += 1 - states_list_copy = deepcopy(states_list) # WHY ??? + states_list_copy = deepcopy(states_list) head, *tail = self.block_pipeline(states_list_copy, configs, env_processes, time_seq, run) genesis = head.pop() genesis['mech_step'], genesis['time_step'], genesis['run'] = 0, 0, run @@ -100,4 +88,4 @@ class Executor: pipe_run += [first_timestep_per_run] + tail del states_list_copy - return pipe_run \ No newline at end of file + return pipe_run diff --git a/SimCAD/engine/utils.py b/SimCAD/engine/utils.py index 947a167..bcf1507 100644 --- a/SimCAD/engine/utils.py +++ b/SimCAD/engine/utils.py @@ -31,11 +31,3 @@ def engine_exception(ErrorType, error_message, exception_function, try_function) except ErrorType: print(error_message) return exception_function - - -# def exception_handler(f, m_step, sL, last_mut_obj, _input): -# try: -# return f(m_step, sL, last_mut_obj, _input) -# except KeyError: -# print("Exception") -# return f(m_step, sL, sL[-2], _input) \ No newline at end of file diff --git a/SimCAD/utils/__init__.py b/SimCAD/utils/__init__.py index 3ee6e50..63d88c6 100644 --- a/SimCAD/utils/__init__.py +++ b/SimCAD/utils/__init__.py @@ -1,5 +1,3 @@ -# from fn.func import curried - def pipe(x): return x @@ -13,20 +11,10 @@ def flatten(l): return [item for sublist in l for item in sublist] -def flatmap(f, items): - return list(map(f, items)) - - def key_filter(l, keyname): return [v[keyname] for k, v in l.items()] -# @curried + def rename(new_name, f): f.__name__ = new_name - return f -# -# def rename(newname): -# def decorator(f): -# f.__name__ = newname -# return f -# return decorator \ No newline at end of file + return f \ No newline at end of file diff --git a/simulations/sim_test.py b/simulations/sim_test.py index ef1daa7..07a4190 100644 --- a/simulations/sim_test.py +++ b/simulations/sim_test.py @@ -3,7 +3,7 @@ from tabulate import tabulate # The following imports NEED to be in the exact same order from SimCAD.engine import ExecutionMode, ExecutionContext, Executor -from simulations.validation import config_1, config_2 +from simulations.validation import config1, config2 from SimCAD import configs # ToDo: pass ExecutionContext with execution method as ExecutionContext input