Skip to content

Commit

Permalink
fix subset ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
danlessa committed Dec 21, 2023
1 parent 73d953f commit a721c0f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cadCAD/configuration/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 8 additions & 10 deletions cadCAD/engine/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
8 changes: 4 additions & 4 deletions cadCAD/types.py
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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]
Expand Down
9 changes: 5 additions & 4 deletions testing/test_runs.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,6 +7,7 @@
import types
import inspect
import pytest
from pandas import DataFrame


def describe_or_return(v: object) -> object:
Expand Down Expand Up @@ -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]
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion testing/tests/cadCAD_memory_address.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"memory_address": "0x10ddf9580"}
{"memory_address": "0x111857380"}

0 comments on commit a721c0f

Please sign in to comment.