From 932b158672334e6be061028243ca565e254c4f64 Mon Sep 17 00:00:00 2001 From: "Joshua E. Jodesty" Date: Mon, 3 Dec 2018 14:34:45 -0500 Subject: [PATCH] Include all param names in config & execution examples --- README.md | 11 ++++++----- notebooks/barlin/App2_Config6a-temp.ipynb | 20 ++++++++++---------- simulations/sim_test.py | 9 ++++----- simulations/validation/config1.py | 11 ++++++++++- simulations/validation/config2.py | 11 ++++++++++- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 4559920..e3ac4b0 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ from tabulate import tabulate # The following imports NEED to be in the exact same order from SimCAD.engine import ExecutionMode, ExecutionContext, Executor -from sandbox.validation import config1, config2 +from simulations.validation import config1, config2 from SimCAD import configs # ToDo: pass ExecutionContext with execution method as ExecutionContext input @@ -47,17 +47,18 @@ exec_mode = ExecutionMode() print("Simulation Run 1") print() single_config = [configs[0]] -single_proc_ctx = ExecutionContext(exec_mode.single_proc) -run1 = Executor(single_proc_ctx, single_config) +single_proc_ctx = ExecutionContext(context=exec_mode.single_proc) +run1 = Executor(exec_context=single_proc_ctx, configs=single_config) run1_raw_result = run1.main() result = pd.DataFrame(run1_raw_result) +# result.to_csv('~/Projects/DiffyQ-SimCAD/results/config4csv', sep=',') print(tabulate(result, headers='keys', tablefmt='psql')) print() print("Simulation Run 2: Pairwise Execution") print() -multi_proc_ctx = ExecutionContext(exec_mode.multi_proc) -run2 = Executor(multi_proc_ctx, configs) +multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc) +run2 = Executor(exec_context=multi_proc_ctx, configs=configs) run2_raw_results = run2.main() for raw_result in run2_raw_results: result = pd.DataFrame(raw_result) diff --git a/notebooks/barlin/App2_Config6a-temp.ipynb b/notebooks/barlin/App2_Config6a-temp.ipynb index a7721ad..e167bdc 100644 --- a/notebooks/barlin/App2_Config6a-temp.ipynb +++ b/notebooks/barlin/App2_Config6a-temp.ipynb @@ -1226,7 +1226,6 @@ { "ename": "TypeError", "evalue": "'decimal.Decimal' object is not subscriptable", - "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", @@ -1235,7 +1234,8 @@ "\u001b[1;32mpandas/_libs/src\\inference.pyx\u001b[0m in \u001b[0;36mpandas._libs.lib.map_infer\u001b[1;34m()\u001b[0m\n", "\u001b[1;32m\u001b[0m in \u001b[0;36mweighted_avg\u001b[1;34m(x)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mweighted_avg\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mTypeError\u001b[0m: 'decimal.Decimal' object is not subscriptable" - ] + ], + "output_type": "error" } ], "source": [ @@ -1277,13 +1277,13 @@ { "ename": "AttributeError", "evalue": "'numpy.ndarray' object has no attribute 'reset_index'", - "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mtest3\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtest2\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreset_index\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mravel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mview\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdtype\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'index'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'A'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfloat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'B'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfloat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;34m'C'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfloat\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[1;31mAttributeError\u001b[0m: 'numpy.ndarray' object has no attribute 'reset_index'" - ] + ], + "output_type": "error" } ], "source": [] @@ -1860,7 +1860,6 @@ { "ename": "KeyError", "evalue": "'Buy_Log'", - "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", @@ -1883,7 +1882,8 @@ "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n", "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n", "\u001b[1;31mKeyError\u001b[0m: 'Buy_Log'" - ] + ], + "output_type": "error" }, { "data": { @@ -1911,7 +1911,6 @@ { "ename": "KeyError", "evalue": "'Buy_Log'", - "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", @@ -1934,7 +1933,8 @@ "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n", "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n", "\u001b[1;31mKeyError\u001b[0m: 'Buy_Log'" - ] + ], + "output_type": "error" } ], "source": [ @@ -1956,13 +1956,13 @@ { "ename": "NameError", "evalue": "name 'buy_delta' is not defined", - "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfigure\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfigsize\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m12\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m8\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmean_df\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'time_step'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mbuy_delta\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#, df['Zeus_LT']], figsize=(15,10)) #, logy=True)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 3\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmean_df\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'time_step'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0msell_delta\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mplot\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmean_df\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'time_step'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mext_delta\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mylim\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m400\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m400\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mNameError\u001b[0m: name 'buy_delta' is not defined" - ] + ], + "output_type": "error" }, { "data": { diff --git a/simulations/sim_test.py b/simulations/sim_test.py index 3ec01c8..ac02508 100644 --- a/simulations/sim_test.py +++ b/simulations/sim_test.py @@ -17,8 +17,8 @@ exec_mode = ExecutionMode() print("Simulation Run 1") print() single_config = [configs[0]] -single_proc_ctx = ExecutionContext(exec_mode.single_proc) -run1 = Executor(single_proc_ctx, single_config) +single_proc_ctx = ExecutionContext(context=exec_mode.single_proc) +run1 = Executor(exec_context=single_proc_ctx, configs=single_config) run1_raw_result = run1.main() result = pd.DataFrame(run1_raw_result) # result.to_csv('~/Projects/DiffyQ-SimCAD/results/config4.csv', sep=',') @@ -27,9 +27,8 @@ print() print("Simulation Run 2: Pairwise Execution") print() -multi_proc_ctx = ExecutionContext(exec_mode.multi_proc) -# configs = [config1, config1] -run2 = Executor(multi_proc_ctx, configs) +multi_proc_ctx = ExecutionContext(context=exec_mode.multi_proc) +run2 = Executor(exec_context=multi_proc_ctx, configs=configs) run2_raw_results = run2.main() for raw_result in run2_raw_results: result = pd.DataFrame(raw_result) diff --git a/simulations/validation/config1.py b/simulations/validation/config1.py index 665c77c..8953963 100644 --- a/simulations/validation/config1.py +++ b/simulations/validation/config1.py @@ -164,4 +164,13 @@ sim_config = { "T": range(5) } -configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms)) \ No newline at end of file +configs.append( + Configuration( + sim_config=sim_config, + state_dict=state_dict, + seed=seed, + exogenous_states=exogenous_states, + env_processes=env_processes, + mechanisms=mechanisms + ) +) \ No newline at end of file diff --git a/simulations/validation/config2.py b/simulations/validation/config2.py index 794b41e..ed2702e 100644 --- a/simulations/validation/config2.py +++ b/simulations/validation/config2.py @@ -168,4 +168,13 @@ sim_config = { "T": range(5) } -configs.append(Configuration(sim_config, state_dict, seed, exogenous_states, env_processes, mechanisms)) \ No newline at end of file +configs.append( + Configuration( + sim_config=sim_config, + state_dict=state_dict, + seed=seed, + exogenous_states=exogenous_states, + env_processes=env_processes, + mechanisms=mechanisms + ) +) \ No newline at end of file