ver. 0.2.4
This commit is contained in:
parent
4870f2db92
commit
0a0d85c257
|
|
@ -1,9 +1,6 @@
|
|||
from datetime import datetime, timedelta
|
||||
from decimal import Decimal
|
||||
from copy import deepcopy
|
||||
from functools import reduce
|
||||
from pprint import pprint
|
||||
|
||||
from fn.func import curried
|
||||
from funcy import curry
|
||||
import pandas as pd
|
||||
|
|
@ -175,9 +172,6 @@ def env_trigger(end_substep):
|
|||
return lambda 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
|
||||
def config_sim(d):
|
||||
|
|
@ -185,7 +179,6 @@ def config_sim(d):
|
|||
return flatten_tabulated_dict(tabulate_dict(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"])]
|
||||
else:
|
||||
d["M"] = [{}]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
from fn.op import foldr
|
||||
from fn.func import curried
|
||||
from collections import Counter
|
||||
|
||||
def get_base_value(x):
|
||||
if isinstance(x, str):
|
||||
|
|
@ -39,43 +38,7 @@ def dict_op(f, d1, d2):
|
|||
|
||||
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}
|
||||
#
|
||||
# @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():
|
||||
return dict_op(add)
|
||||
|
|
|
|||
|
|
@ -27,11 +27,8 @@ def single_proc_exec(
|
|||
Ts: List[range],
|
||||
Ns: List[int]
|
||||
):
|
||||
# print(env_processes_list)
|
||||
# print(configs_structs)
|
||||
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))
|
||||
# print(config.env_processes)
|
||||
result = simulation_exec(var_dict_list, states_list, config, env_processes, T, N)
|
||||
return flatten(result)
|
||||
|
||||
|
|
@ -68,7 +65,6 @@ class Executor:
|
|||
self.exec_method = exec_context.method
|
||||
self.exec_context = exec_context.name
|
||||
self.configs = configs
|
||||
# self.main = self.execute
|
||||
|
||||
def execute(self) -> Tuple[List[Dict[str, Any]], DataFrame]:
|
||||
config_proc = Processor()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
from typing import Any, Callable, Dict, List, Tuple
|
||||
|
||||
from pathos.pools import ThreadPool as TPool
|
||||
from copy import deepcopy
|
||||
from functools import reduce
|
||||
from funcy import compose
|
||||
|
||||
from cadCAD.engine.utils import engine_exception
|
||||
from cadCAD.utils import flatten
|
||||
|
|
@ -19,13 +17,10 @@ class Executor:
|
|||
state_update_exception: Callable = id_exception
|
||||
) -> None:
|
||||
|
||||
# behavior_ops
|
||||
self.policy_ops = policy_ops
|
||||
self.state_update_exception = state_update_exception
|
||||
self.policy_update_exception = policy_update_exception
|
||||
# behavior_update_exception
|
||||
|
||||
# get_behavior_input # sL: State Window
|
||||
def get_policy_input(
|
||||
self,
|
||||
sweep_dict: Dict[str, List[Any]],
|
||||
|
|
@ -35,10 +30,8 @@ class Executor:
|
|||
funcs: List[Callable]
|
||||
) -> Dict[str, Any]:
|
||||
|
||||
# ops = self.policy_ops[::-1]
|
||||
ops = self.policy_ops
|
||||
|
||||
|
||||
def get_col_results(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
|
||||
) -> 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] = 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))
|
||||
|
||||
# ToDo: add env_proc generator to `last_in_copy` iterator as wrapper function
|
||||
|
|
@ -152,22 +129,13 @@ class Executor:
|
|||
return destination
|
||||
|
||||
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)
|
||||
|
||||
|
||||
# ToDo: make 'substep' & 'timestep' reserve fields
|
||||
last_in_copy['substep'], last_in_copy['timestep'], last_in_copy['run'] = sub_step, time_step, run
|
||||
|
||||
sL.append(last_in_copy)
|
||||
del last_in_copy
|
||||
|
||||
# print(sL)
|
||||
# print()
|
||||
|
||||
return sL
|
||||
|
||||
# mech_pipeline - state_update_block
|
||||
|
|
@ -182,23 +150,7 @@ class Executor:
|
|||
) -> List[Dict[str, Any]]:
|
||||
|
||||
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])
|
||||
|
||||
# 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:
|
||||
genesis_states: Dict[str, Any] = states_list_copy[-1]
|
||||
|
||||
|
|
@ -211,7 +163,7 @@ class Executor:
|
|||
del states_list_copy
|
||||
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
|
||||
|
||||
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(
|
||||
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
|
||||
# print(sub_step)
|
||||
|
||||
time_step += 1
|
||||
|
||||
|
|
@ -244,10 +192,6 @@ class Executor:
|
|||
# ToDo: simulation_list should be a Tensor that is generated throughout the Executor
|
||||
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:
|
||||
pipe_run: List[Dict[str, Any]] = self.state_update_pipeline(
|
||||
sweep_dict, simulation_list, configs, env_processes, time_step, run
|
||||
|
|
@ -255,8 +199,6 @@ class Executor:
|
|||
|
||||
_, *pipe_run = pipe_run
|
||||
simulation_list.append(pipe_run)
|
||||
# print(simulation_list)
|
||||
# print()
|
||||
|
||||
return simulation_list
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,6 @@
|
|||
from copy import deepcopy
|
||||
|
||||
from fn.func import curried
|
||||
from funcy import curry
|
||||
|
||||
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):
|
||||
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)
|
||||
)
|
||||
|
||||
|
||||
def apply(f, y: str, incr_by: int):
|
||||
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."
|
||||
|
||||
setup(name='cadCAD',
|
||||
version='0.2.3',
|
||||
version='0.2.4',
|
||||
description="cadCAD: a differential games based simulation software package for research, validation, and \
|
||||
Computer Aided Design of economic systems",
|
||||
long_description=long_description,
|
||||
|
|
|
|||
Loading…
Reference in New Issue