Skip to content

Commit

Permalink
Merge branch 'danlessa:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
danlessa authored Mar 8, 2023
2 parents 8835161 + 6ce44fb commit b2c8bde
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 144 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ as a 2 dimensional `list`
+----+------------+-----------+----+---------------------+-----+---------+----------+
```

* **Flattened Configuration List:** The `cadCAD.configs` (System Model Configuration) `list` has been **temporarily**
* **Flattened Configuration list:** The `cadCAD.configs` (System Model Configuration) `list` has been **temporarily**
flattened to contain single run `cadCAD.configuration.Configuration` objects to both fault-tolerant simulation and
elastic workloads. This functionality will be restored in a subsequent release by a class that returns
`cadCAD.configs`'s original representation in ver. `0.3.1`.
* The conversion utilities have been provided to restore its original representation of configurations with
runs >= 1
* [System Configuration Conversions](documentation/System_Configuration.md)
* Configuration as List of Configuration Objects (as in ver. `0.3.1`)
* Configuration as list of Configuration Objects (as in ver. `0.3.1`)
* New: System Configuration as a Pandas DataFrame
* New: System Configuration as List of Dictionaries
* New: System Configuration as list of Dictionaries

###### Examples:
* Notes:
Expand Down
13 changes: 6 additions & 7 deletions cadCAD/configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Dict, Callable, List, Tuple
from pandas.core.frame import DataFrame
from datetime import datetime
from collections import deque
Expand Down Expand Up @@ -187,27 +186,27 @@ def append_model(


class Identity:
def __init__(self, policy_id: Dict[str, int] = {'identity': 0}) -> None:
def __init__(self, policy_id: dict[str, int] = {'identity': 0}) -> None:
self.beh_id_return_val = policy_id

def p_identity(self, var_dict, sub_step, sL, s, **kwargs):
return self.beh_id_return_val

def policy_identity(self, k: str) -> Callable:
def policy_identity(self, k: str) -> callable:
return self.p_identity

def no_state_identity(self, var_dict, sub_step, sL, s, _input, **kwargs):
return None

def state_identity(self, k: str) -> Callable:
def state_identity(self, k: str) -> callable:
return lambda var_dict, sub_step, sL, s, _input, **kwargs: (k, s[k])

# state_identity = cloudpickle.dumps(state_identity)

def apply_identity_funcs(self,
identity: Callable,
identity: callable,
df: DataFrame,
cols: List[str]) -> DataFrame:
cols: list[str]) -> DataFrame:
"""
Apply the identity on each df column, using its self value as the
argument.
Expand Down Expand Up @@ -240,7 +239,7 @@ def create_matrix_field(self, partial_state_updates, key: str) -> DataFrame:
return pd.DataFrame({'empty': []})

def generate_config(self, initial_state, partial_state_updates, exo_proc
) -> List[Tuple[List[Callable], List[Callable]]]:
) -> list[tuple[list[callable], list[callable]]]:

def no_update_handler(bdf, sdf):
if (bdf.empty == False) and (sdf.empty == True):
Expand Down
15 changes: 7 additions & 8 deletions cadCAD/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from time import time
from typing import Callable, Dict, List, Any, Tuple
from tqdm.auto import tqdm

from cadCAD.utils import flatten
Expand All @@ -9,10 +8,10 @@
from cadCAD.engine.simulation import Executor as SimExecutor
from cadCAD.engine.execution import single_proc_exec, parallelize_simulations, local_simulations

VarDictType = Dict[str, List[Any]]
StatesListsType = List[Dict[str, Any]]
ConfigsType = List[Tuple[List[Callable], List[Callable]]]
EnvProcessesType = Dict[str, Callable]
VarDictType = dict[str, list[object]]
StatesListsType = list[dict[str, object]]
ConfigsType = list[tuple[list[callable], list[callable]]]
EnvProcessesType = dict[str, callable]


class ExecutionMode:
Expand Down Expand Up @@ -57,7 +56,7 @@ def distroduce_proc(

class Executor:
def __init__(self,
exec_context: ExecutionContext, configs: List[Configuration], sc=None, empty_return=False
exec_context: ExecutionContext, configs: list[Configuration], sc=None, empty_return=False
) -> None:
self.sc = sc
self.SimExecutor = SimExecutor
Expand All @@ -66,7 +65,7 @@ def __init__(self,
self.configs = configs
self.empty_return = empty_return

def execute(self) -> Tuple[Any, Any, Dict[str, Any]]:
def execute(self) -> tuple[object, object, dict[str, object]]:
if self.empty_return is True:
return [], [], []

Expand Down Expand Up @@ -136,7 +135,7 @@ def get_final_results(simulations, psus, eps, sessions, remote_threshold):
remote_threshold = 100
config_amt = len(self.configs)

def auto_mode_switcher(config_amt):
def auto_mode_switcher(config_amt) -> tuple:
try:
if config_amt == 1:
return ExecutionMode.single_mode, single_proc_exec
Expand Down
61 changes: 30 additions & 31 deletions cadCAD/engine/execution.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
from typing import Callable, Dict, List, Any, Tuple
from pathos.multiprocessing import ProcessPool as PPool
from collections import Counter

from cadCAD.utils import flatten

VarDictType = Dict[str, List[Any]]
StatesListsType = List[Dict[str, Any]]
ConfigsType = List[Tuple[List[Callable], List[Callable]]]
EnvProcessesType = Dict[str, Callable]
VarDictType = dict[str, list[object]]
StatesListsType = list[dict[str, object]]
ConfigsType = list[tuple[list[callable], list[callable]]]
EnvProcessesType = dict[str, callable]


def single_proc_exec(
simulation_execs: List[Callable],
var_dict_list: List[VarDictType],
states_lists: List[StatesListsType],
configs_structs: List[ConfigsType],
env_processes_list: List[EnvProcessesType],
Ts: List[range],
simulation_execs: list[callable],
var_dict_list: list[VarDictType],
states_lists: list[StatesListsType],
configs_structs: list[ConfigsType],
env_processes_list: list[EnvProcessesType],
Ts: list[range],
SimIDs,
Ns: List[int],
ExpIDs: List[int],
Ns: list[int],
ExpIDs: list[int],
SubsetIDs,
SubsetWindows,
configured_n
Expand All @@ -39,16 +38,16 @@ def single_proc_exec(


def parallelize_simulations(
simulation_execs: List[Callable],
var_dict_list: List[VarDictType],
states_lists: List[StatesListsType],
configs_structs: List[ConfigsType],
env_processes_list: List[EnvProcessesType],
Ts: List[range],
simulation_execs: list[callable],
var_dict_list: list[VarDictType],
states_lists: list[StatesListsType],
configs_structs: list[ConfigsType],
env_processes_list: list[EnvProcessesType],
Ts: list[range],
SimIDs,
Ns: List[int],
ExpIDs: List[int],
SubsetIDs,
Ns: list[int],
ExpIDs: list[int],
SubsetIDs: list[int],
SubsetWindows,
configured_n
):
Expand Down Expand Up @@ -104,16 +103,16 @@ def process_executor(params):


def local_simulations(
simulation_execs: List[Callable],
var_dict_list: List[VarDictType],
states_lists: List[StatesListsType],
configs_structs: List[ConfigsType],
env_processes_list: List[EnvProcessesType],
Ts: List[range],
simulation_execs: list[callable],
var_dict_list: list[VarDictType],
states_lists: list[StatesListsType],
configs_structs: list[ConfigsType],
env_processes_list: list[EnvProcessesType],
Ts: list[range],
SimIDs,
Ns: List[int],
ExpIDs: List[int],
SubsetIDs,
Ns: list[int],
ExpIDs: list[int],
SubsetIDs: list[int],
SubsetWindows,
configured_n
):
Expand Down
Loading

0 comments on commit b2c8bde

Please sign in to comment.