From a721c0fd691836f6c96a142577fba9d9cf641240 Mon Sep 17 00:00:00 2001 From: Danilo Lessa Bernardineli Date: Thu, 21 Dec 2023 11:46:02 -0300 Subject: [PATCH] fix subset ordering --- cadCAD/configuration/utils/__init__.py | 2 +- cadCAD/engine/execution.py | 18 ++++++++---------- cadCAD/types.py | 8 ++++---- testing/test_runs.py | 9 +++++---- testing/tests/cadCAD_memory_address.json | 2 +- 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cadCAD/configuration/utils/__init__.py b/cadCAD/configuration/utils/__init__.py index 7ebac29a..8359c1b9 100644 --- a/cadCAD/configuration/utils/__init__.py +++ b/cadCAD/configuration/utils/__init__.py @@ -104,7 +104,7 @@ def ep_decorator(f, y, var_dict, sub_step, sL, s, _input, **kwargs): else: return y, s[y] - return {es: ep_decorator(f, es) for es, f in ep.items()} + return {es: ep_decorator(f, es) for es, f in ep.items()} # type: ignore def trigger_condition(s, pre_conditions, cond_opp): diff --git a/cadCAD/engine/execution.py b/cadCAD/engine/execution.py index 26666163..97a5fa87 100644 --- a/cadCAD/engine/execution.py +++ b/cadCAD/engine/execution.py @@ -26,20 +26,18 @@ def single_proc_exec( additional_objs=None ) -> List: - + if not isinstance(var_dict_list, Sequence): var_dict_list = list([var_dict_list]) + raw_params = ( + simulation_execs, states_lists, configs_structs, env_processes_list, + Ts, SimIDs, Ns, SubsetIDs, SubsetWindows, var_dict_list) + results: List = [] - for var_dict in var_dict_list: - print(f'Execution Mode: single_threaded') - raw_params: List[List] = [ - simulation_execs, states_lists, configs_structs, env_processes_list, - Ts, SimIDs, Ns, SubsetIDs, SubsetWindows - ] - simulation_exec, states_list, config, env_processes, T, sim_id, N, subset_id, subset_window = list( - map(lambda x: x.pop(), raw_params) - ) + print(f'Execution Mode: single_threaded') + for raw_param in zip(*raw_params): + simulation_exec, states_list, config, env_processes, T, sim_id, N, subset_id, subset_window, var_dict = raw_param result = simulation_exec( var_dict, states_list, config, env_processes, T, sim_id, N, subset_id, subset_window, configured_n, additional_objs ) diff --git a/cadCAD/types.py b/cadCAD/types.py index d5b9302f..d7bf731a 100644 --- a/cadCAD/types.py +++ b/cadCAD/types.py @@ -1,4 +1,4 @@ -from typing import TypedDict, Callable, Union, Dict, List, Tuple, Iterator +from typing import TypedDict, Callable, Union, Dict, List, Tuple, Iterable from collections import deque State = Dict[str, object] @@ -20,18 +20,18 @@ class StateUpdateBlock(TypedDict): StateUpdateBlocks = List[StateUpdateBlock] class ConfigurationDict(TypedDict): - T: Iterator # Generator for the timestep variable + T: Iterable # Generator for the timestep variable N: int # Number of MC Runs M: Union[Parameters, SweepableParameters] # Parameters / List of Parameter to Sweep TargetValue = object EnvProcess: Callable[[State, SweepableParameters, TargetValue], TargetValue] EnvProcesses = Dict[str, Callable] -TimeSeq = Iterator +TimeSeq = Iterable SimulationID = int Run = int SubsetID = int -SubsetWindow = Iterator +SubsetWindow = Iterable N_Runs = int ExecutorFunction = Callable[[Parameters, StateHistory, StateUpdateBlocks, EnvProcesses, TimeSeq, SimulationID, Run, SubsetID, SubsetWindow, N_Runs], object] diff --git a/testing/test_runs.py b/testing/test_runs.py index a695b1dc..69d1b149 100644 --- a/testing/test_runs.py +++ b/testing/test_runs.py @@ -1,4 +1,4 @@ -from typing import Dict, List +from typing import Dict, List, Optional from cadCAD.engine import Executor, ExecutionContext, ExecutionMode from cadCAD.configuration import Experiment from cadCAD.configuration.utils import env_trigger, var_substep_trigger, config_sim, psub_list @@ -7,6 +7,7 @@ import types import inspect import pytest +from pandas import DataFrame def describe_or_return(v: object) -> object: @@ -63,8 +64,8 @@ def assign_params(_df: pd.DataFrame, configs) -> pd.DataFrame: SWEEP_PARAMS: Dict[str, List] = { 'alpha': [1], - 'beta': [lambda x: 2 * x, lambda x: x], - 'gamma': [3, 4], + 'beta': [lambda x: 2 * x, lambda x: x, lambda x: x / 2], + 'gamma': [3, 4, 5], 'omega': [7] } @@ -184,7 +185,7 @@ def test_unique_single_experiment(mode): N_RUNS=1, N_TIMESTEPS=2, params=SINGLE_PARAMS), mode) -def experiment_assertions(exp, mode=None): +def experiment_assertions(exp: Experiment, mode: Optional[str]=None) -> None: if mode == None: mode = ExecutionMode().local_mode exec_context = ExecutionContext(mode) diff --git a/testing/tests/cadCAD_memory_address.json b/testing/tests/cadCAD_memory_address.json index 7d5810f9..c60ead7b 100644 --- a/testing/tests/cadCAD_memory_address.json +++ b/testing/tests/cadCAD_memory_address.json @@ -1 +1 @@ -{"memory_address": "0x10ddf9580"} \ No newline at end of file +{"memory_address": "0x111857380"} \ No newline at end of file