From 5fabb373e312da8844409dfed7c2543b6d408935 Mon Sep 17 00:00:00 2001 From: "Joshua E. Jodesty" Date: Sun, 18 Nov 2018 14:28:28 -0500 Subject: [PATCH] update readme --- README.md | 42 +++++++++++++++------------------ SimCAD/engine/__init__.py | 2 +- SimCAD/engine/simulation.py | 7 +++--- SimCAD/utils/configProcessor.py | 18 ++++++++++---- SimCAD/utils/ui.py | 2 ++ sandboxUX/sim_test.py | 2 ++ 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index b555506..5ccb3ff 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,26 @@ pip install pipenv fn tabulate **Project:** -Example Run File: +Example Runs: `/DiffyQ-SimCAD/sandboxUX/` + +**User Interface: Simulation Configuration** + +Configurations: +```bash +/DiffyQ-SimCAD/ui/config.py +``` + +**Build Tool & Package Import:** + +Step 1. Build & Install Package locally: +```bash +pip install . +pip install -e . +``` +* [Package Creation Tutorial](https://python-packaging.readthedocs.io/en/latest/minimal.html) + +Step 2. Import Package & Run: ```python import pandas as pd from tabulate import tabulate @@ -36,28 +54,6 @@ for raw_result in run2_raw_results: print() ``` -**User Interface: Simulation Configuration** - -Configurations: -```bash -/DiffyQ-SimCAD/ui/config.py -``` - -**Build Tool & Package Import:** - -Step 1. Build & Install Package locally: -```bash -pip install . -pip install -e . -``` -* [Package Creation Tutorial](https://python-packaging.readthedocs.io/en/latest/minimal.html) - -Step 2. Import Package & Run: -```python -from engine import run -run.main() -``` - Same can be run in Jupyter . ```bash jupyter notebook diff --git a/SimCAD/engine/__init__.py b/SimCAD/engine/__init__.py index f51f9dc..534b67b 100644 --- a/SimCAD/engine/__init__.py +++ b/SimCAD/engine/__init__.py @@ -6,8 +6,8 @@ from SimCAD.utils.ui import create_tensor_field from SimCAD.utils.configProcessor import generate_config from SimCAD.engine.simulation import Executor as SimExecutor -class ExecutionContext: +class ExecutionContext: def parallelize_simulations(self, fs, states_list, configs, env_processes, Ts, Ns): l = list(zip(fs, states_list, configs, env_processes, Ts, Ns)) with Pool(len(configs)) as p: diff --git a/SimCAD/engine/simulation.py b/SimCAD/engine/simulation.py index 04fc156..f0f8fba 100644 --- a/SimCAD/engine/simulation.py +++ b/SimCAD/engine/simulation.py @@ -19,7 +19,7 @@ class Executor(object): return foldr(call, getColResults(step, sL, s, funcs))(ops) - def apply_env_proc(env_processes, state_dict, step): + def apply_env_proc(self, env_processes, state_dict, step): for state in state_dict.keys(): if state in list(env_processes.keys()): state_dict[state] = env_processes[state](step)(state_dict[state]) @@ -41,7 +41,7 @@ class Executor(object): # print(sL) # *** add env_proc value here as wrapper function *** - last_in_copy = dict([ self.exception_handler(f, m_step, sL, last_in_obj, _input) for f in state_funcs ]) + last_in_copy = dict([self.exception_handler(f, m_step, sL, last_in_obj, _input) for f in state_funcs]) for k in last_in_obj: if k not in last_in_copy: @@ -50,10 +50,9 @@ class Executor(object): del last_in_obj # make env proc trigger field agnostic - Executor.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']) # mutating last_in_copy last_in_copy["mech_step"], last_in_copy["time_step"], last_in_copy['run'] = m_step, t_step, run - # print(last_in_copy) sL.append(last_in_copy) del last_in_copy diff --git a/SimCAD/utils/configProcessor.py b/SimCAD/utils/configProcessor.py index e2da966..fdbb4e4 100644 --- a/SimCAD/utils/configProcessor.py +++ b/SimCAD/utils/configProcessor.py @@ -1,26 +1,35 @@ import pandas as pd from functools import reduce + def no_state_identity(step, sL, s, _input): return None + def state_identity(k): return lambda step, sL, s, _input: (k, s[k]) + def b_identity(step, sL, s): return 0 + + def behavior_identity(k): return b_identity + def key_filter(mechanisms, keyname): return [ v[keyname] for k, v in mechanisms.items() ] + def fillna_with_id_func(identity, df, col): return df[[col]].fillna(value=identity(col)) + def apply_identity_funcs(identity, df, cols): return list(map(lambda col: fillna_with_id_func(identity, df, col), cols)) + def create_matrix_field(mechanisms, key): if key == 'states': identity = state_identity @@ -37,14 +46,15 @@ def create_matrix_field(mechanisms, key): # Maybe Refactor to only use dictionary BUT I used dfs to fill NAs. Perhaps fill def generate_config(state_dict, mechanisms, exo_proc): + # include False / False case def no_update_handler(bdf, sdf): if (bdf.empty == False) and (sdf.empty == True): bdf_values = bdf.values.tolist() - sdf_values = [ [no_state_identity] * len(bdf_values) for m in range(len(mechanisms)) ] + sdf_values = [[no_state_identity] * len(bdf_values) for m in range(len(mechanisms))] return sdf_values, bdf_values elif (bdf.empty == True) and (sdf.empty == False): sdf_values = sdf.values.tolist() - bdf_values = [ [b_identity] * len(sdf_values) for m in range(len(mechanisms)) ] + bdf_values = [[b_identity] * len(sdf_values) for m in range(len(mechanisms))] return sdf_values, bdf_values else: sdf_values = sdf.values.tolist() @@ -55,8 +65,8 @@ def generate_config(state_dict, mechanisms, exo_proc): sdf_functions = [ lambda step, sL, s, _input: (k, v) for k, v in zip(state_dict.keys(), state_dict.values()) ] - sdf_values = [ sdf_functions ] - bdf_values = [ [b_identity] * len(sdf_values) ] + sdf_values = [sdf_functions] + bdf_values = [[b_identity] * len(sdf_values)] return sdf_values, bdf_values zipped_list = [] diff --git a/SimCAD/utils/ui.py b/SimCAD/utils/ui.py index 3122591..bed280d 100644 --- a/SimCAD/utils/ui.py +++ b/SimCAD/utils/ui.py @@ -1,6 +1,8 @@ import pandas as pd from SimCAD.utils.configProcessor import create_matrix_field + +# dont for-loop to apply exo_procs, use exo_proc struct def create_tensor_field(mechanisms, exo_proc, keys=['behaviors', 'states']): dfs = [create_matrix_field(mechanisms, k) for k in keys] df = pd.concat(dfs, axis=1) diff --git a/sandboxUX/sim_test.py b/sandboxUX/sim_test.py index ea7ef0b..cbc0965 100644 --- a/sandboxUX/sim_test.py +++ b/sandboxUX/sim_test.py @@ -4,6 +4,8 @@ from tabulate import tabulate from SimCAD.engine import ExecutionContext, Executor from sandboxUX import config1, config2 +# pass ExecutionContext function instead of class + print("Simulation Run 1") print() single_config = [config1]