diff --git a/README.md b/README.md index e971e98..a39e97f 100644 --- a/README.md +++ b/README.md @@ -77,4 +77,4 @@ for raw_result, tensor_field in run2.main(): The above can be run in Jupyter. ```bash jupyter notebook -``` +```git s \ No newline at end of file diff --git a/Simulation.md b/Simulation.md index 81d1ece..8c1d3cf 100644 --- a/Simulation.md +++ b/Simulation.md @@ -1,4 +1,4 @@ -# SimmCAD Documentation +# cadCAD Documentation ## Introduction @@ -31,13 +31,13 @@ from decimal import Decimal import numpy as np from datetime import timedelta -from SimCAD import configs -from SimCAD.configuration import Configuration -from SimCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \ +from cadCAD import configs +from cadCAD.configuration import Configuration +from cadCAD.configuration.utils import exo_update_per_ts, proc_trigger, bound_norm_random, \ ep_time_step ``` -State variables and their initial values can be defined as follows. Note that `timestamp` is a required field for this iteration of SimCAD for `env_proc` to work. Future iterations will strive to make this more generic and timestamp optional. +State variables and their initial values can be defined as follows. Note that `timestamp` is a required field for this iteration of cadCAD for `env_proc` to work. Future iterations will strive to make this more generic and timestamp optional. ```python genesis_dict = { 's1': Decimal(0.0), @@ -63,7 +63,7 @@ transitions = { "m2": {...} } ``` -Every behavior per transition should return a dictionary as actions taken by the agents. They will then be aggregated through addition in this version of SimCAD. Some examples of behaviors per transition are as follows. More flexible and user-defined aggregation functions will be introduced in future iterations but no example is provided at this point. +Every behavior per transition should return a dictionary as actions taken by the agents. They will then be aggregated through addition in this version of cadCAD. Some examples of behaviors per transition are as follows. More flexible and user-defined aggregation functions will be introduced in future iterations but no example is provided at this point. ```python def b1m1(step, sL, s): return {'param1': 1} @@ -105,7 +105,7 @@ seed = { 'c': np.random.RandomState(3) } ``` -SimCAD currently supports generating random number from a normal distribution through `bound_norm_random` with `min` and `max` values specified. Examples of environmental processes with randomness are as follows. We also define timestamp format with `ts_format` and timestamp changes with `t_delta`. Users can define other distributions to update exogenous variables. +cadCAD currently supports generating random number from a normal distribution through `bound_norm_random` with `min` and `max` values specified. Examples of environmental processes with randomness are as follows. We also define timestamp format with `ts_format` and timestamp changes with `t_delta`. Users can define other distributions to update exogenous variables. ```python proc_one_coef_A = 0.7 proc_one_coef_B = 1.3 @@ -127,7 +127,7 @@ def es5p2(step, sL, s, _input): x = ep_time_step(s, s['timestamp'], fromat_str=ts_format, _timedelta=t_delta) return (y, x) ``` -User can also define specific external events such as market shocks at specific timestamps through `env_processes` with `proc_trigger`. An environmental process with no `proc_trigger` will be called at every timestamp. In the example below, it will return the value of `s3` at every timestamp. Logical event triggers, such as a big draw down in exogenous variables, will be supported in a later version of SimCAD. +User can also define specific external events such as market shocks at specific timestamps through `env_processes` with `proc_trigger`. An environmental process with no `proc_trigger` will be called at every timestamp. In the example below, it will return the value of `s3` at every timestamp. Logical event triggers, such as a big draw down in exogenous variables, will be supported in a later version of cadCAD. ```python def env_a(x): return x @@ -148,4 +148,4 @@ sim_config = { } configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms)) -``` +``` \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 48a300b..70c7dfe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ +pandas +wheel pathos fn tabulate \ No newline at end of file diff --git a/setup.py b/setup.py index deef949..a01f39c 100644 --- a/setup.py +++ b/setup.py @@ -20,4 +20,4 @@ setup(name='cadCAD', author_email='joshua@block.science', # license='LICENSE', packages=find_packages() -) +) \ No newline at end of file diff --git a/simulations/example_run.py b/simulations/example_run.py deleted file mode 100644 index 9598981..0000000 --- a/simulations/example_run.py +++ /dev/null @@ -1,34 +0,0 @@ -import pandas as pd -from tabulate import tabulate -# The following imports NEED to be in the exact order -from cadCAD.engine import ExecutionMode, ExecutionContext, Executor -from simulations.validation import sweep_config, config1, config2, config4 -from cadCAD import configs - -exec_mode = ExecutionMode() - -# print("Simulation Execution 1") -# print() -# first_config = [configs[0]] # FOR non-sweep configs ONLY -# single_proc_ctx = ExecutionContext(context=exec_mode.single_proc) -# run1 = Executor(exec_context=single_proc_ctx, configs=first_config) -# run1_raw_result, tensor_field = run1.main() -# result = pd.DataFrame(run1_raw_result) -# print() -# print("Tensor Field:") -# print(tabulate(tensor_field, headers='keys', tablefmt='psql')) -# print("Output:") -# print(tabulate(result, headers='keys', tablefmt='psql')) -# print() - -print("Simulation Execution 2: Concurrent Execution") -multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc) -run2 = Executor(exec_context=multi_proc_ctx, configs=configs) -for raw_result, tensor_field in run2.main(): - result = pd.DataFrame(raw_result) - print() - print("Tensor Field:") - print(tabulate(tensor_field, headers='keys', tablefmt='psql')) - print("Output:") - print(tabulate(result, headers='keys', tablefmt='psql')) - print() \ No newline at end of file diff --git a/simulations/multi_config run.py b/simulations/multi_config run.py new file mode 100644 index 0000000..c81e1f0 --- /dev/null +++ b/simulations/multi_config run.py @@ -0,0 +1,24 @@ +import pandas as pd +from tabulate import tabulate +# The following imports NEED to be in the exact order +from cadCAD.engine import ExecutionMode, ExecutionContext, Executor +from simulations.validation import config1, config2 +from cadCAD import configs + +exec_mode = ExecutionMode() + +print("Simulation Execution: Concurrent Execution") +multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc) +run2 = Executor(exec_context=multi_proc_ctx, configs=configs) + +i = 0 +config_names = ['config1', 'config2'] +for raw_result, tensor_field in run2.main(): + result = pd.DataFrame(raw_result) + print() + print("Tensor Field: " + config_names[i]) + print(tabulate(tensor_field, headers='keys', tablefmt='psql')) + print("Output:") + print(tabulate(result, headers='keys', tablefmt='psql')) + print() + i += 1 \ No newline at end of file diff --git a/simulations/param_sweep_run.py b/simulations/param_sweep_run.py new file mode 100644 index 0000000..ecf620f --- /dev/null +++ b/simulations/param_sweep_run.py @@ -0,0 +1,24 @@ +import pandas as pd +from tabulate import tabulate +# The following imports NEED to be in the exact order +from cadCAD.engine import ExecutionMode, ExecutionContext, Executor +from simulations.validation import sweep_config +from cadCAD import configs + +exec_mode = ExecutionMode() + +print("Simulation Execution: Concurrent Execution") +multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc) +run2 = Executor(exec_context=multi_proc_ctx, configs=configs) + +i = 0 +config_names = ['sweep_config_A', 'sweep_config_B'] +for raw_result, tensor_field in run2.main(): + result = pd.DataFrame(raw_result) + print() + print("Tensor Field: " + config_names[i]) + print(tabulate(tensor_field, headers='keys', tablefmt='psql')) + print("Output:") + print(tabulate(result, headers='keys', tablefmt='psql')) + print() + i += 1 \ No newline at end of file diff --git a/simulations/single_config_run.py b/simulations/single_config_run.py new file mode 100644 index 0000000..38b1307 --- /dev/null +++ b/simulations/single_config_run.py @@ -0,0 +1,22 @@ +import pandas as pd +from tabulate import tabulate +# The following imports NEED to be in the exact order +from cadCAD.engine import ExecutionMode, ExecutionContext, Executor +from simulations.validation import config1 +from cadCAD import configs + +exec_mode = ExecutionMode() + +print("Simulation Execution: Single Configuration") +print() +first_config = configs # only contains config1 +single_proc_ctx = ExecutionContext(context=exec_mode.single_proc) +run1 = Executor(exec_context=single_proc_ctx, configs=first_config) +run1_raw_result, tensor_field = run1.main() +result = pd.DataFrame(run1_raw_result) +print() +print("Tensor Field: config1") +print(tabulate(tensor_field, headers='keys', tablefmt='psql')) +print("Output:") +print(tabulate(result, headers='keys', tablefmt='psql')) +print() \ No newline at end of file