ver. 0.2.4
This commit is contained in:
parent
4870f2db92
commit
0a0d85c257
|
|
@ -1,9 +1,6 @@
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from decimal import Decimal
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from fn.func import curried
|
from fn.func import curried
|
||||||
from funcy import curry
|
from funcy import curry
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
@ -175,9 +172,6 @@ def env_trigger(end_substep):
|
||||||
return lambda trigger_field, trigger_vals, funct_list: \
|
return lambda trigger_field, trigger_vals, funct_list: \
|
||||||
curry(trigger)(end_substep)(trigger_field)(trigger_vals)(funct_list)
|
curry(trigger)(end_substep)(trigger_field)(trigger_vals)(funct_list)
|
||||||
|
|
||||||
# trigger = curry(_trigger)
|
|
||||||
# print(timestep_trigger)
|
|
||||||
|
|
||||||
|
|
||||||
# param sweep enabling middleware
|
# param sweep enabling middleware
|
||||||
def config_sim(d):
|
def config_sim(d):
|
||||||
|
|
@ -185,7 +179,6 @@ def config_sim(d):
|
||||||
return flatten_tabulated_dict(tabulate_dict(d))
|
return flatten_tabulated_dict(tabulate_dict(d))
|
||||||
|
|
||||||
if "M" in d:
|
if "M" in d:
|
||||||
# print([{"N": d["N"], "T": d["T"], "M": M} for M in process_variables(d["M"])])
|
|
||||||
return [{"N": d["N"], "T": d["T"], "M": M} for M in process_variables(d["M"])]
|
return [{"N": d["N"], "T": d["T"], "M": M} for M in process_variables(d["M"])]
|
||||||
else:
|
else:
|
||||||
d["M"] = [{}]
|
d["M"] = [{}]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
from fn.op import foldr
|
from fn.op import foldr
|
||||||
from fn.func import curried
|
from fn.func import curried
|
||||||
from collections import Counter
|
|
||||||
|
|
||||||
def get_base_value(x):
|
def get_base_value(x):
|
||||||
if isinstance(x, str):
|
if isinstance(x, str):
|
||||||
|
|
@ -39,43 +38,7 @@ def dict_op(f, d1, d2):
|
||||||
|
|
||||||
key_set = set(list(d1.keys()) + list(d2.keys()))
|
key_set = set(list(d1.keys()) + list(d2.keys()))
|
||||||
|
|
||||||
|
|
||||||
return {k: f(set_base_value(d1, d2, k), set_base_value(d2, d1, k)) for k in key_set}
|
return {k: f(set_base_value(d1, d2, k), set_base_value(d2, d1, k)) for k in key_set}
|
||||||
#
|
|
||||||
# @curried
|
|
||||||
# def dict_op(f, d1, d2):
|
|
||||||
# def set_base_value(target_dict, source_dict, key):
|
|
||||||
# if key not in target_dict:
|
|
||||||
# return get_base_value(source_dict[key])
|
|
||||||
# else:
|
|
||||||
# return target_dict[key]
|
|
||||||
#
|
|
||||||
# key_set = set(list(d1.keys()) + list(d2.keys()))
|
|
||||||
#
|
|
||||||
# norm_d1 = {k: set_base_value(d1, d2, k) for k in key_set}
|
|
||||||
# norm_d2 = {k: set_base_value(d2, d1, k) for k in key_set}
|
|
||||||
#
|
|
||||||
# return {k: f(set_base_value(d1, d2, k), set_base_value(d2, d1, k)) for k in key_set}
|
|
||||||
|
|
||||||
|
|
||||||
# @curried
|
|
||||||
# def dict_op(f, d1, d2):
|
|
||||||
# # d1C = Counter(d1)
|
|
||||||
# # d2C = Counter(d2)
|
|
||||||
# def set_base_value(target_dict, source_dict, key):
|
|
||||||
# if key not in target_dict:
|
|
||||||
# return get_base_value(source_dict[key])
|
|
||||||
# else:
|
|
||||||
# return target_dict[key]
|
|
||||||
# key_set = set(list(d1.keys()) + list(d2.keys()))
|
|
||||||
# norm_d1 = Counter({k: set_base_value(d1, d2, k) for k in key_set})
|
|
||||||
# norm_d2 = Counter({k: set_base_value(d2, d1, k) for k in key_set})
|
|
||||||
# # print(norm_d1)
|
|
||||||
# # print(norm_d2)
|
|
||||||
# print(norm_d1 + norm_d2)
|
|
||||||
# # print(f(norm_d1, norm_d2))
|
|
||||||
# print()
|
|
||||||
# return f(norm_d1, norm_d2)
|
|
||||||
|
|
||||||
def dict_elemwise_sum():
|
def dict_elemwise_sum():
|
||||||
return dict_op(add)
|
return dict_op(add)
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,8 @@ def single_proc_exec(
|
||||||
Ts: List[range],
|
Ts: List[range],
|
||||||
Ns: List[int]
|
Ns: List[int]
|
||||||
):
|
):
|
||||||
# print(env_processes_list)
|
|
||||||
# print(configs_structs)
|
|
||||||
l = [simulation_execs, states_lists, configs_structs, env_processes_list, Ts, Ns]
|
l = [simulation_execs, states_lists, configs_structs, env_processes_list, Ts, Ns]
|
||||||
simulation_exec, states_list, config, env_processes, T, N = list(map(lambda x: x.pop(), l))
|
simulation_exec, states_list, config, env_processes, T, N = list(map(lambda x: x.pop(), l))
|
||||||
# print(config.env_processes)
|
|
||||||
result = simulation_exec(var_dict_list, states_list, config, env_processes, T, N)
|
result = simulation_exec(var_dict_list, states_list, config, env_processes, T, N)
|
||||||
return flatten(result)
|
return flatten(result)
|
||||||
|
|
||||||
|
|
@ -68,7 +65,6 @@ class Executor:
|
||||||
self.exec_method = exec_context.method
|
self.exec_method = exec_context.method
|
||||||
self.exec_context = exec_context.name
|
self.exec_context = exec_context.name
|
||||||
self.configs = configs
|
self.configs = configs
|
||||||
# self.main = self.execute
|
|
||||||
|
|
||||||
def execute(self) -> Tuple[List[Dict[str, Any]], DataFrame]:
|
def execute(self) -> Tuple[List[Dict[str, Any]], DataFrame]:
|
||||||
config_proc = Processor()
|
config_proc = Processor()
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
from typing import Any, Callable, Dict, List, Tuple
|
from typing import Any, Callable, Dict, List, Tuple
|
||||||
|
|
||||||
from pathos.pools import ThreadPool as TPool
|
from pathos.pools import ThreadPool as TPool
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from funcy import compose
|
|
||||||
|
|
||||||
from cadCAD.engine.utils import engine_exception
|
from cadCAD.engine.utils import engine_exception
|
||||||
from cadCAD.utils import flatten
|
from cadCAD.utils import flatten
|
||||||
|
|
@ -19,13 +17,10 @@ class Executor:
|
||||||
state_update_exception: Callable = id_exception
|
state_update_exception: Callable = id_exception
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
# behavior_ops
|
|
||||||
self.policy_ops = policy_ops
|
self.policy_ops = policy_ops
|
||||||
self.state_update_exception = state_update_exception
|
self.state_update_exception = state_update_exception
|
||||||
self.policy_update_exception = policy_update_exception
|
self.policy_update_exception = policy_update_exception
|
||||||
# behavior_update_exception
|
|
||||||
|
|
||||||
# get_behavior_input # sL: State Window
|
|
||||||
def get_policy_input(
|
def get_policy_input(
|
||||||
self,
|
self,
|
||||||
sweep_dict: Dict[str, List[Any]],
|
sweep_dict: Dict[str, List[Any]],
|
||||||
|
|
@ -35,10 +30,8 @@ class Executor:
|
||||||
funcs: List[Callable]
|
funcs: List[Callable]
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
|
|
||||||
# ops = self.policy_ops[::-1]
|
|
||||||
ops = self.policy_ops
|
ops = self.policy_ops
|
||||||
|
|
||||||
|
|
||||||
def get_col_results(sweep_dict, sub_step, sL, s, funcs):
|
def get_col_results(sweep_dict, sub_step, sL, s, funcs):
|
||||||
return list(map(lambda f: f(sweep_dict, sub_step, sL, s), funcs))
|
return list(map(lambda f: f(sweep_dict, sub_step, sL, s), funcs))
|
||||||
|
|
||||||
|
|
@ -119,23 +112,7 @@ class Executor:
|
||||||
run: int
|
run: int
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
|
|
||||||
# def dp_psu(d):
|
|
||||||
# for k, v in deepcopy(d).items():
|
|
||||||
# yield k, deepcopy(v)
|
|
||||||
#
|
|
||||||
# def dp_psub(l):
|
|
||||||
# for d in l:
|
|
||||||
# yield dict(dp_psu(d))
|
|
||||||
|
|
||||||
# last_in_obj: Dict[str, Any] = dict(dp_psu(sL[-1]))
|
|
||||||
|
|
||||||
last_in_obj: Dict[str, Any] = deepcopy(sL[-1])
|
last_in_obj: Dict[str, Any] = deepcopy(sL[-1])
|
||||||
# last_in_obj: Dict[str, Any] = sL[-1]
|
|
||||||
|
|
||||||
# last_in_obj: Dict[str, Any] = sH[-1]
|
|
||||||
# print(last_in_obj)
|
|
||||||
# print(sH[-1])
|
|
||||||
|
|
||||||
_input: Dict[str, Any] = self.policy_update_exception(self.get_policy_input(sweep_dict, sub_step, sH, last_in_obj, policy_funcs))
|
_input: Dict[str, Any] = self.policy_update_exception(self.get_policy_input(sweep_dict, sub_step, sH, last_in_obj, policy_funcs))
|
||||||
|
|
||||||
# ToDo: add env_proc generator to `last_in_copy` iterator as wrapper function
|
# ToDo: add env_proc generator to `last_in_copy` iterator as wrapper function
|
||||||
|
|
@ -152,22 +129,13 @@ class Executor:
|
||||||
return destination
|
return destination
|
||||||
|
|
||||||
last_in_copy: Dict[str, Any] = transfer_missing_fields(last_in_obj, dict(generate_record(state_funcs)))
|
last_in_copy: Dict[str, Any] = transfer_missing_fields(last_in_obj, dict(generate_record(state_funcs)))
|
||||||
# ToDo: Remove
|
|
||||||
# last_in_copy: Dict[str, Any] = self.apply_env_proc(env_processes, last_in_copy, last_in_copy['timestep'])
|
|
||||||
# print(env_processes)
|
|
||||||
# print()
|
|
||||||
last_in_copy: Dict[str, Any] = self.apply_env_proc(sweep_dict, env_processes, last_in_copy)
|
last_in_copy: Dict[str, Any] = self.apply_env_proc(sweep_dict, env_processes, last_in_copy)
|
||||||
|
|
||||||
|
|
||||||
# ToDo: make 'substep' & 'timestep' reserve fields
|
# ToDo: make 'substep' & 'timestep' reserve fields
|
||||||
last_in_copy['substep'], last_in_copy['timestep'], last_in_copy['run'] = sub_step, time_step, run
|
last_in_copy['substep'], last_in_copy['timestep'], last_in_copy['run'] = sub_step, time_step, run
|
||||||
|
|
||||||
sL.append(last_in_copy)
|
sL.append(last_in_copy)
|
||||||
del last_in_copy
|
del last_in_copy
|
||||||
|
|
||||||
# print(sL)
|
|
||||||
# print()
|
|
||||||
|
|
||||||
return sL
|
return sL
|
||||||
|
|
||||||
# mech_pipeline - state_update_block
|
# mech_pipeline - state_update_block
|
||||||
|
|
@ -182,23 +150,7 @@ class Executor:
|
||||||
) -> List[Dict[str, Any]]:
|
) -> List[Dict[str, Any]]:
|
||||||
|
|
||||||
sub_step = 0
|
sub_step = 0
|
||||||
# states_list_copy: List[Dict[str, Any]] = deepcopy(states_list)
|
|
||||||
# states_list_copy: List[Dict[str, Any]] = states_list
|
|
||||||
# ToDo: flatten first
|
|
||||||
# states_list_copy: List[Dict[str, Any]] = simulation_list[-1]
|
|
||||||
states_list_copy: List[Dict[str, Any]] = deepcopy(simulation_list[-1])
|
states_list_copy: List[Dict[str, Any]] = deepcopy(simulation_list[-1])
|
||||||
|
|
||||||
# def dp_psu(d):
|
|
||||||
# for k, v in deepcopy(d).items():
|
|
||||||
# yield k, deepcopy(v)
|
|
||||||
#
|
|
||||||
# def dp_psub(l):
|
|
||||||
# for d in l:
|
|
||||||
# yield dict(dp_psu(d))
|
|
||||||
|
|
||||||
# states_list_copy: List[Dict[str, Any]] = list(dp_psub(simulation_list[-1]))
|
|
||||||
# print(states_list_copy)
|
|
||||||
|
|
||||||
# ToDo: Causes Substep repeats in sL:
|
# ToDo: Causes Substep repeats in sL:
|
||||||
genesis_states: Dict[str, Any] = states_list_copy[-1]
|
genesis_states: Dict[str, Any] = states_list_copy[-1]
|
||||||
|
|
||||||
|
|
@ -211,7 +163,7 @@ class Executor:
|
||||||
del states_list_copy
|
del states_list_copy
|
||||||
states_list: List[Dict[str, Any]] = [genesis_states]
|
states_list: List[Dict[str, Any]] = [genesis_states]
|
||||||
|
|
||||||
# ToDo: Causes Substep repeats in sL, use for yield
|
# ToDo: Was causing Substep repeats in sL, use for yield
|
||||||
sub_step += 1
|
sub_step += 1
|
||||||
|
|
||||||
for [s_conf, p_conf] in configs: # tensor field
|
for [s_conf, p_conf] in configs: # tensor field
|
||||||
|
|
@ -219,11 +171,7 @@ class Executor:
|
||||||
states_list: List[Dict[str, Any]] = self.partial_state_update(
|
states_list: List[Dict[str, Any]] = self.partial_state_update(
|
||||||
sweep_dict, sub_step, states_list, simulation_list, s_conf, p_conf, env_processes, time_step, run
|
sweep_dict, sub_step, states_list, simulation_list, s_conf, p_conf, env_processes, time_step, run
|
||||||
)
|
)
|
||||||
# print(sub_step)
|
|
||||||
# print(simulation_list)
|
|
||||||
# print(flatten(simulation_list))
|
|
||||||
sub_step += 1
|
sub_step += 1
|
||||||
# print(sub_step)
|
|
||||||
|
|
||||||
time_step += 1
|
time_step += 1
|
||||||
|
|
||||||
|
|
@ -244,10 +192,6 @@ class Executor:
|
||||||
# ToDo: simulation_list should be a Tensor that is generated throughout the Executor
|
# ToDo: simulation_list should be a Tensor that is generated throughout the Executor
|
||||||
simulation_list: List[List[Dict[str, Any]]] = [states_list]
|
simulation_list: List[List[Dict[str, Any]]] = [states_list]
|
||||||
|
|
||||||
# print(simulation_list[-1])
|
|
||||||
# print()
|
|
||||||
# pipe_run = simulation_list[-1]
|
|
||||||
# print(simulation_list)
|
|
||||||
for time_step in time_seq:
|
for time_step in time_seq:
|
||||||
pipe_run: List[Dict[str, Any]] = self.state_update_pipeline(
|
pipe_run: List[Dict[str, Any]] = self.state_update_pipeline(
|
||||||
sweep_dict, simulation_list, configs, env_processes, time_step, run
|
sweep_dict, simulation_list, configs, env_processes, time_step, run
|
||||||
|
|
@ -255,8 +199,6 @@ class Executor:
|
||||||
|
|
||||||
_, *pipe_run = pipe_run
|
_, *pipe_run = pipe_run
|
||||||
simulation_list.append(pipe_run)
|
simulation_list.append(pipe_run)
|
||||||
# print(simulation_list)
|
|
||||||
# print()
|
|
||||||
|
|
||||||
return simulation_list
|
return simulation_list
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
from copy import deepcopy
|
from funcy import curry
|
||||||
|
|
||||||
from fn.func import curried
|
|
||||||
|
|
||||||
from cadCAD.configuration.utils import ep_time_step, time_step
|
from cadCAD.configuration.utils import ep_time_step, time_step
|
||||||
from funcy import curry
|
|
||||||
import pprint as pp
|
|
||||||
# from fn import _
|
|
||||||
from functools import reduce
|
|
||||||
|
|
||||||
def increment(y, incr_by):
|
def increment(y, incr_by):
|
||||||
return lambda _g, step, sL, s, _input: (y, s[y] + incr_by)
|
return lambda _g, step, sL, s, _input: (y, s[y] + incr_by)
|
||||||
|
|
@ -26,7 +20,6 @@ def update_timestamp(y, timedelta, format):
|
||||||
ep_time_step(s, dt_str=s[y], fromat_str=format, _timedelta=timedelta)
|
ep_time_step(s, dt_str=s[y], fromat_str=format, _timedelta=timedelta)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def apply(f, y: str, incr_by: int):
|
def apply(f, y: str, incr_by: int):
|
||||||
return lambda _g, step, sL, s, _input: (y, curry(f)(s[y])(incr_by))
|
return lambda _g, step, sL, s, _input: (y, curry(f)(s[y])(incr_by))
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
2
setup.py
2
setup.py
|
|
@ -11,7 +11,7 @@ long_description = "cadCAD is a differential games based simulation software pac
|
||||||
monte carlo analysis and other common numerical methods is provided."
|
monte carlo analysis and other common numerical methods is provided."
|
||||||
|
|
||||||
setup(name='cadCAD',
|
setup(name='cadCAD',
|
||||||
version='0.2.3',
|
version='0.2.4',
|
||||||
description="cadCAD: a differential games based simulation software package for research, validation, and \
|
description="cadCAD: a differential games based simulation software package for research, validation, and \
|
||||||
Computer Aided Design of economic systems",
|
Computer Aided Design of economic systems",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue