Skip to content

Commit

Permalink
renameing hell pt. 4
Browse files Browse the repository at this point in the history
  • Loading branch information
JEJodesty committed Feb 20, 2019
1 parent 1862416 commit 7fb7640
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 66 deletions.
79 changes: 59 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SimCad
# cadCAD
**Warning**:
**Do not** publish this package / software to **any** software repository **except** one permitted by BlockScience.

**Description:**

SimCAD is a differential games based simulation software package for research, validation, and Computer \
cadCAD is a differential games based simulation software package for research, validation, and Computer \
Aided Design of economic systems. An economic system is treated as a state based model and defined through a \
set of endogenous and exogenous state variables which are updated through mechanisms and environmental \
processes, respectively. Behavioral models, which may be deterministic or stochastic, provide the evolution of \
Expand All @@ -15,11 +15,9 @@ Simulations may be run with a range of initial conditions and parameters for sta
and environmental processes to understand and visualize network behavior under various conditions. Support for \
A/B testing policies, monte carlo analysis and other common numerical methods is provided.

SimCAD is written in Python 3.

**1. Install Dependencies:**
```bash
pip3 install -r requirements.txt
pip install -r requirements.txt
python3 setup.py sdist bdist_wheel
pip3 install dist/*.whl
```
Expand All @@ -32,51 +30,92 @@ Intructions:
Examples:
`/simulations/validation/*`

**3. Import SimCAD & Run Simulation:**
**3. Import cadCAD & Run Simulations:**

Examples: `/simulations/example_run.py` or `/simulations/example_run.ipynb`
Examples: `/simulations/*.py` or `/simulations/*.ipynb`

`/simulations/example_run.py`:
Single Simulation Run: `/simulations/single_config_run.py`
```python
import pandas as pd
from tabulate import tabulate

# The following imports NEED to be in the exact order
from SimCAD.engine import ExecutionMode, ExecutionContext, Executor
from validation import config1, config2
from SimCAD import configs
from cadCAD.engine import ExecutionMode, ExecutionContext, Executor
from simulations.validation import config1
from cadCAD import configs

exec_mode = ExecutionMode()

print("Simulation Execution 1")
print("Simulation Execution: Single Configuration")
print()
first_config = [configs[0]] # from config1
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:")
print("Tensor Field: config1")
print(tabulate(tensor_field, headers='keys', tablefmt='psql'))
print("Output:")
print(tabulate(result, headers='keys', tablefmt='psql'))
print()
```

print("Simulation Execution 2: Pairwise Execution")
print()
Parameter Sweep Simulation Run (Concurrent): `/simulations/param_sweep_run.py`
```python
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:")
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
```

Multiple Simulation Runs (Concurrent): `/simulations/multi_config run.py`
```python
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
```

The above can be run in Jupyter.
```bash
jupyter notebook
```
```
20 changes: 10 additions & 10 deletions Simulation.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# SimCAD Documentation
# cadCAD Documentation

## Introduction

A blockchain is a distributed ledger with economic agents transacting in a network. The state of the network evolves with every new transaction, which can be a result of user behaviors, protocol-defined system mechanisms, or external processes.

It is not uncommon today for blockchain projects to announce a set of rules for their network and make claims about their system level behavior. However, the validity of those claims is hardly validated. Furthermore, it is difficult to know the potential system-level impact when the network is considering an upgrade to their system rules and parameters.
It is not uncommon today for blockchain projects to announce a set of rules for their network and make claims about their system level behvaior. However, the validity of those claims is hardly validated. Furthermore, it is difficult to know the potential system-level impact when the network is considering an upgrade to their system rules and prameters.

To rigorously and reliably analyze, design, and improve cryptoeconomic networks, we are introducing this Computer Aided Design Engine where we define a cryptoeconomic network with its state and exogneous variables, model transactions as a result of agent behaviors, state mechanisms, and environmental processes. We can then run simulations with different initial states, mechanisms, environmental processes to understand and visualize network behavior under different conditions.

Expand All @@ -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),
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -148,4 +148,4 @@ sim_config = {
}

configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms))
```
```
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
wheel
pandas
wheel
pathos
fn
tabulate
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
author_email='[email protected]',
# license='LICENSE',
packages=find_packages()
)
)
34 changes: 0 additions & 34 deletions simulations/example_run.py

This file was deleted.

24 changes: 24 additions & 0 deletions simulations/multi_config run.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions simulations/param_sweep_run.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions simulations/single_config_run.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 7fb7640

Please sign in to comment.