update readme
This commit is contained in:
parent
13d8d26ed4
commit
5fabb373e3
42
README.md
42
README.md
|
|
@ -7,8 +7,26 @@ pip install pipenv fn tabulate
|
||||||
|
|
||||||
**Project:**
|
**Project:**
|
||||||
|
|
||||||
Example Run File:
|
Example Runs:
|
||||||
`/DiffyQ-SimCAD/sandboxUX/`
|
`/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
|
```python
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
@ -36,28 +54,6 @@ for raw_result in run2_raw_results:
|
||||||
print()
|
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 .
|
Same can be run in Jupyter .
|
||||||
```bash
|
```bash
|
||||||
jupyter notebook
|
jupyter notebook
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ from SimCAD.utils.ui import create_tensor_field
|
||||||
from SimCAD.utils.configProcessor import generate_config
|
from SimCAD.utils.configProcessor import generate_config
|
||||||
from SimCAD.engine.simulation import Executor as SimExecutor
|
from SimCAD.engine.simulation import Executor as SimExecutor
|
||||||
|
|
||||||
class ExecutionContext:
|
|
||||||
|
|
||||||
|
class ExecutionContext:
|
||||||
def parallelize_simulations(self, fs, states_list, configs, env_processes, Ts, Ns):
|
def parallelize_simulations(self, fs, states_list, configs, env_processes, Ts, Ns):
|
||||||
l = list(zip(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:
|
with Pool(len(configs)) as p:
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ class Executor(object):
|
||||||
|
|
||||||
return foldr(call, getColResults(step, sL, s, funcs))(ops)
|
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():
|
for state in state_dict.keys():
|
||||||
if state in list(env_processes.keys()):
|
if state in list(env_processes.keys()):
|
||||||
state_dict[state] = env_processes[state](step)(state_dict[state])
|
state_dict[state] = env_processes[state](step)(state_dict[state])
|
||||||
|
|
@ -41,7 +41,7 @@ class Executor(object):
|
||||||
# print(sL)
|
# print(sL)
|
||||||
|
|
||||||
# *** add env_proc value here as wrapper function ***
|
# *** 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:
|
for k in last_in_obj:
|
||||||
if k not in last_in_copy:
|
if k not in last_in_copy:
|
||||||
|
|
@ -50,10 +50,9 @@ class Executor(object):
|
||||||
del last_in_obj
|
del last_in_obj
|
||||||
|
|
||||||
# make env proc trigger field agnostic
|
# 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
|
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)
|
sL.append(last_in_copy)
|
||||||
del last_in_copy
|
del last_in_copy
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,35 @@
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
|
|
||||||
|
|
||||||
def no_state_identity(step, sL, s, _input):
|
def no_state_identity(step, sL, s, _input):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def state_identity(k):
|
def state_identity(k):
|
||||||
return lambda step, sL, s, _input: (k, s[k])
|
return lambda step, sL, s, _input: (k, s[k])
|
||||||
|
|
||||||
|
|
||||||
def b_identity(step, sL, s):
|
def b_identity(step, sL, s):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def behavior_identity(k):
|
def behavior_identity(k):
|
||||||
return b_identity
|
return b_identity
|
||||||
|
|
||||||
|
|
||||||
def key_filter(mechanisms, keyname):
|
def key_filter(mechanisms, keyname):
|
||||||
return [ v[keyname] for k, v in mechanisms.items() ]
|
return [ v[keyname] for k, v in mechanisms.items() ]
|
||||||
|
|
||||||
|
|
||||||
def fillna_with_id_func(identity, df, col):
|
def fillna_with_id_func(identity, df, col):
|
||||||
return df[[col]].fillna(value=identity(col))
|
return df[[col]].fillna(value=identity(col))
|
||||||
|
|
||||||
|
|
||||||
def apply_identity_funcs(identity, df, cols):
|
def apply_identity_funcs(identity, df, cols):
|
||||||
return list(map(lambda col: fillna_with_id_func(identity, df, col), cols))
|
return list(map(lambda col: fillna_with_id_func(identity, df, col), cols))
|
||||||
|
|
||||||
|
|
||||||
def create_matrix_field(mechanisms, key):
|
def create_matrix_field(mechanisms, key):
|
||||||
if key == 'states':
|
if key == 'states':
|
||||||
identity = state_identity
|
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
|
# Maybe Refactor to only use dictionary BUT I used dfs to fill NAs. Perhaps fill
|
||||||
def generate_config(state_dict, mechanisms, exo_proc):
|
def generate_config(state_dict, mechanisms, exo_proc):
|
||||||
|
|
||||||
|
# include False / False case
|
||||||
def no_update_handler(bdf, sdf):
|
def no_update_handler(bdf, sdf):
|
||||||
if (bdf.empty == False) and (sdf.empty == True):
|
if (bdf.empty == False) and (sdf.empty == True):
|
||||||
bdf_values = bdf.values.tolist()
|
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
|
return sdf_values, bdf_values
|
||||||
elif (bdf.empty == True) and (sdf.empty == False):
|
elif (bdf.empty == True) and (sdf.empty == False):
|
||||||
sdf_values = sdf.values.tolist()
|
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
|
return sdf_values, bdf_values
|
||||||
else:
|
else:
|
||||||
sdf_values = sdf.values.tolist()
|
sdf_values = sdf.values.tolist()
|
||||||
|
|
@ -55,8 +65,8 @@ def generate_config(state_dict, mechanisms, exo_proc):
|
||||||
sdf_functions = [
|
sdf_functions = [
|
||||||
lambda step, sL, s, _input: (k, v) for k, v in zip(state_dict.keys(), state_dict.values())
|
lambda step, sL, s, _input: (k, v) for k, v in zip(state_dict.keys(), state_dict.values())
|
||||||
]
|
]
|
||||||
sdf_values = [ sdf_functions ]
|
sdf_values = [sdf_functions]
|
||||||
bdf_values = [ [b_identity] * len(sdf_values) ]
|
bdf_values = [[b_identity] * len(sdf_values)]
|
||||||
return sdf_values, bdf_values
|
return sdf_values, bdf_values
|
||||||
|
|
||||||
zipped_list = []
|
zipped_list = []
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from SimCAD.utils.configProcessor import create_matrix_field
|
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']):
|
def create_tensor_field(mechanisms, exo_proc, keys=['behaviors', 'states']):
|
||||||
dfs = [create_matrix_field(mechanisms, k) for k in keys]
|
dfs = [create_matrix_field(mechanisms, k) for k in keys]
|
||||||
df = pd.concat(dfs, axis=1)
|
df = pd.concat(dfs, axis=1)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ from tabulate import tabulate
|
||||||
from SimCAD.engine import ExecutionContext, Executor
|
from SimCAD.engine import ExecutionContext, Executor
|
||||||
from sandboxUX import config1, config2
|
from sandboxUX import config1, config2
|
||||||
|
|
||||||
|
# pass ExecutionContext function instead of class
|
||||||
|
|
||||||
print("Simulation Run 1")
|
print("Simulation Run 1")
|
||||||
print()
|
print()
|
||||||
single_config = [config1]
|
single_config = [config1]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue