Skip to content

Commit

Permalink
0.4.18
Browse files Browse the repository at this point in the history
  • Loading branch information
JEJodesty committed Aug 4, 2020
1 parent 13a8b65 commit 86470e8
Show file tree
Hide file tree
Showing 44 changed files with 640 additions and 559 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
.idea
.eggs
.pytest_cache
client_work

notebooks
*.egg-info
__pycache__
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog:
### August 4, 2020
* Experiment Class: Representation of an experiment as one or more configured System Models

### June 22, 2020
* Bug Fix: Multiprocessing error for Windows

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/ ___/ __` / __ / / / /| | / / / /
/ /__/ /_/ / /_/ / /___/ ___ |/ /_/ /
\___/\__,_/\__,_/\____/_/ |_/_____/
by cadCAD ver. 0.4.17
by cadCAD ver. 0.4.18
======================================
Complex Adaptive Dynamics
o i e
Expand Down
132 changes: 15 additions & 117 deletions cadCAD/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from pprint import pprint
from typing import Dict, Callable, List, Tuple
from pandas.core.frame import DataFrame
from collections import deque
from copy import deepcopy
import pandas as pd
# from time import time

from cadCAD import configs
from cadCAD.utils import key_filter
Expand All @@ -13,11 +11,10 @@


class Configuration(object):
def __init__(self, user_id, sim_config={}, initial_state={}, seeds={}, env_processes={},
def __init__(self, user_id, subset_id, subset_window, sim_config={}, initial_state={}, seeds={}, env_processes={},
exogenous_states={}, partial_state_update_blocks={}, policy_ops=[lambda a, b: a + b],
session_id=0, simulation_id=0, run_id=1, experiment_id=0, exp_window=deque([0, None], 2), **kwargs
) -> None:
# print(exogenous_states)
self.sim_config = sim_config
self.initial_state = initial_state
self.seeds = seeds
Expand All @@ -28,24 +25,27 @@ def __init__(self, user_id, sim_config={}, initial_state={}, seeds={}, env_proce
self.kwargs = kwargs

self.user_id = user_id
self.session_id = session_id # eesntially config id
self.session_id = session_id # essentially config id
self.simulation_id = simulation_id
self.run_id = run_id
self.experiment_id = experiment_id
self.exp_window = exp_window
self.subset_id = subset_id
self.subset_window = subset_window

sanitize_config(self)


class Experiment:
def __init__(self):
self.exp_id = 0
self.subset_id = 0
self.exp_window = deque([self.exp_id, None], 2)
self.subset_window = deque([self.subset_id, None], 2)

def append_configs(
self,
user_id='cadCAD_user',
session_id=0, # ToDo: change to string
sim_configs={}, initial_state={}, seeds={}, raw_exogenous_states={}, env_processes={},
partial_state_update_blocks={}, policy_ops=[lambda a, b: a + b], _exo_update_per_ts: bool = True,
config_list=configs
Expand All @@ -71,10 +71,11 @@ def append_configs(

sim_cnt = 0
new_sim_configs = []
for t in list(zip(sim_configs, list(range(len(sim_configs))))):
for subset_id, t in enumerate(list(zip(sim_configs, list(range(len(sim_configs)))))):
sim_config = t[0]
sim_config['subset_id'] = subset_id
sim_config['subset_window'] = self.subset_window
N = sim_config['N']

if N > 1:
for n in range(N):
sim_config['simulation_id'] = simulation_id + sim_cnt
Expand All @@ -92,8 +93,8 @@ def append_configs(
sim_cnt += 1

run_id = 0
print(self.exp_id)
for sim_config in new_sim_configs:
subset_id = sim_config['subset_id']
sim_config['N'] = run_id + 1
if max_runs == 1:
sim_config['run_id'] = run_id
Expand All @@ -115,110 +116,17 @@ def append_configs(
user_id=user_id,
session_id=f"{user_id}={sim_config['simulation_id']}_{sim_config['run_id']}",
simulation_id=sim_config['simulation_id'],
# run_id=run_id_config
run_id=sim_config['run_id'],

experiment_id=self.exp_id,
exp_window=self.exp_window
exp_window=self.exp_window,
subset_id=subset_id,
subset_window=self.subset_window
)
configs.append(config)
run_id += 1

# print(exp_cnt)
self.exp_id += 1
self.exp_window.appendleft(self.exp_id)
# print()
# print(self.exp_id)


# def append_configs(
# user_id='cadCAD_user',
# session_id=0, #ToDo: change to string
# sim_configs={}, initial_state={}, seeds={}, raw_exogenous_states={}, env_processes={},
# partial_state_update_blocks={}, policy_ops=[lambda a, b: a + b], _exo_update_per_ts: bool = True,
# config_list=configs
# ) -> None:
#
# try:
# max_runs = sim_configs[0]['N']
# except KeyError:
# max_runs = sim_configs['N']
#
# if _exo_update_per_ts is True:
# exogenous_states = exo_update_per_ts(raw_exogenous_states)
# else:
# exogenous_states = raw_exogenous_states
#
# if isinstance(sim_configs, dict):
# sim_configs = [sim_configs]
#
# simulation_id = 0
# if len(config_list) > 0:
# last_config = config_list[-1]
# simulation_id = last_config.simulation_id + 1
#
# sim_cnt = 0
# new_sim_configs = []
# for t in list(zip(sim_configs, list(range(len(sim_configs))))):
# sim_config = t[0]
# N = sim_config['N']
#
# if N > 1:
# for n in range(N):
# sim_config['simulation_id'] = simulation_id + sim_cnt
# sim_config['run_id'] = n
# sim_config['N'] = 1
# # sim_config['N'] = n + 1
# new_sim_configs.append(deepcopy(sim_config))
# del sim_config
# else:
# sim_config['simulation_id'] = simulation_id
# sim_config['run_id'] = 0
# new_sim_configs.append(deepcopy(sim_config))
# # del sim_config
#
# sim_cnt += 1
#
# # print(configs)
# run_id = 0
# # if len(configs) > 0:
# # ds_run_id = configs[-1].__dict__['run_id'] + 1
# # # print()
# # # print(configs[-1].__dict__['simulation_id'])
# # # print(configs[-1].__dict__['run_id'])
# # # configs[-1].__dict__['run_id']
# # # print(configs[-1].__dict__['run_id'] + 1)
# # run_id = ds_run_id + 1
#
# for sim_config in new_sim_configs:
# sim_config['N'] = run_id + 1
# if max_runs == 1:
# sim_config['run_id'] = run_id
# elif max_runs >= 1:
# if run_id >= max_runs:
# sim_config['N'] = run_id - (max_runs - 1)
#
# config = Configuration(
# sim_config=sim_config,
# initial_state=initial_state,
# seeds=seeds,
# exogenous_states=exogenous_states,
# env_processes=env_processes,
# partial_state_update_blocks=partial_state_update_blocks,
# policy_ops=policy_ops,
#
# # session_id=session_id,
# user_id=user_id,
# session_id=f"{user_id}={sim_config['simulation_id']}_{sim_config['run_id']}",
# simulation_id=sim_config['simulation_id'],
# # run_id=run_id_config
# run_id=sim_config['run_id']
# )
# configs.append(config)
# run_id += 1
#
# # print(configs)
# # print(f'simulation_id: {configs[-1].__dict__["simulation_id"]}')
# # print(f'run_id: {configs[-1].__dict__["run_id"]}')


class Identity:
Expand Down Expand Up @@ -300,7 +208,7 @@ def only_ep_handler(state_dict):
return sdf_values, bdf_values

if len(partial_state_updates) != 0:
# backwards compatibility #
# backwards compatibility
partial_state_updates = sanitize_partial_state_updates(partial_state_updates)

bdf = self.create_matrix_field(partial_state_updates, 'policies')
Expand All @@ -312,13 +220,3 @@ def only_ep_handler(state_dict):
zipped_list = list(zip(sdf_values, bdf_values))

return list(map(lambda x: (x[0] + exo_proc, x[1]), zipped_list))

# def timing_val(func):
# def wrapper(*arg, **kw):
# '''source: http://www.daniweb.com/code/snippet368.html'''
# t1 = time()
# res = func(*arg, **kw)
# t2 = time()
# print(f"{func.__name__}: {t2-t1 :.5f}")
# return res
# return wrapper
8 changes: 3 additions & 5 deletions cadCAD/configuration/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import Counter
from datetime import datetime, timedelta
from collections import Counter
from copy import deepcopy
from functools import reduce
from funcy import curry
Expand Down Expand Up @@ -41,9 +41,9 @@ def configs_as_spec(configs):

def configs_as_objs(configs):
counted_IDs_configs = configs_as_spec(configs)
new_config = list(map(lambda x: x[1], counted_IDs_configs))
new_configs = list(map(lambda x: x[1], counted_IDs_configs))
del counted_IDs_configs
return new_config
return new_configs


def configs_as_dicts(configs):
Expand Down Expand Up @@ -79,15 +79,13 @@ def bound_norm_random(rng, low, high):

tstep_delta = timedelta(days=0, minutes=0, seconds=30)
def time_step(dt_str, dt_format='%Y-%m-%d %H:%M:%S', _timedelta = tstep_delta):
# print(dt_str)
dt = datetime.strptime(dt_str, dt_format)
t = dt + _timedelta
return t.strftime(dt_format)


ep_t_delta = timedelta(days=0, minutes=0, seconds=1)
def ep_time_step(s_condition, dt_str, fromat_str='%Y-%m-%d %H:%M:%S', _timedelta = ep_t_delta):
# print(dt_str)
if s_condition:
return time_step(dt_str, fromat_str, _timedelta)
else:
Expand Down
Loading

0 comments on commit 86470e8

Please sign in to comment.