Skip to content

Commit

Permalink
Merge branch 'master' into hard_to_debug_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
emanuellima1 authored Dec 15, 2023
2 parents ec754b0 + 546881a commit 13026ba
Show file tree
Hide file tree
Showing 10 changed files with 338 additions and 137 deletions.
67 changes: 0 additions & 67 deletions .circleci/config.yml

This file was deleted.

61 changes: 61 additions & 0 deletions .github/workflows/cadcad-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This workflow will install Python dependencies and run tests with multiple versions of Python

name: cadCAD CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:
continue-on-error: true

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install test and build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install jupyter
pip install -r requirements.txt
- name: Build cadCAD
run: |
python setup.py bdist_wheel
python -m pip install dist/*.whl --force-reinstall
- name: Run tests
run: |
python testing/tests/multi_model_row_count.py
python testing/tests/param_sweep.py
python testing/tests/policy_aggregation.py
python testing/tests/timestep1psub0.py
python testing/tests/runs_not_zero.py
python testing/tests/run1psub0.py
python testing/tests/append_mod_test.py
python testing/tests/cadCAD_exp.py
- name: Run Jupyter test
run: |
python testing/tests/import_cadCAD_test.py
45 changes: 28 additions & 17 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
Authors
=======

cadCAD was implemented by Joshua E. Jodesty and designed by Michael Zargham, Markus B. Koch, and
Matthew V. Barlin from 2018 to 2020.
cadCAD was originally implemented by Joshua E. Jodesty and designed by Michael Zargham, Markus B. Koch, and
Matthew V. Barlin in 2018. Since then, upgrades and improvements were further committed by Danilo L. Bernardineli, Tyler D. Mace
and Emanuel Lima.



Project Maintainers:
- Joshua E. Jodesty <[email protected]>
- Markus B. Koch <[email protected]>
- Michael Zargham <[email protected]>
Current Project Maintainers:
- Emanuel Lima <[email protected]> @emanuellima1
- Michael Zargham <[email protected]> @mzargham


Original Contributors:
- Joshua E. Jodesty
- Markus B. Koch
- Matthew V. Barlin
- Michael Zargham
- Zixuan Zhang
- Charles Rice
Active and Past Contributors:
- Joshua E. Jodesty @JEJodesty
- Markus B. Koch @markusbkoch
- Matthew V. Barlin @matttyb80
- Michael Zargham @mzargham
- Danilo L. Bernardineli @danlessa
- Tyler D. Mace @tylerdmace
- Emanuel Lima @emanuellima1
- Zixuan Zhang @zixuanzh
- Charles Rice @charles-rice
- Benjamin Scholz @BenSchZA


We’d also like to thank:
- Andrew Clark
- Nick Hirannet
- Jonathan Gabler
- Harry Goodnight
- Andrew Clark @aclarkData
- Nick Hirannet @nick-phl-7
- Jonathan Gabler
- Harry Goodnight @
- Charlie Hoppes
- Nikhil Jamdade
- Chris Frazier
- Griff Green @GriffGreen
- Isaac @eenti
- Jonny Dubowsky @jonnydubowsky
- Sem Brestels @sembrestels
- @fjribi
- Andrea Maria Piana @cammellos
6 changes: 4 additions & 2 deletions cadCAD/engine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from time import time
from typing import Callable, Dict, List, Any, Tuple
from typing import Callable, Dict, List, Any, Tuple, Union

from cadCAD.utils import flatten
from cadCAD.utils.execution import print_exec_info
Expand Down Expand Up @@ -39,6 +39,7 @@ def auto_mode_switcher(config_amt: int):
class ExecutionContext:
def __init__(self, context=ExecutionMode.local_mode, method=None, additional_objs=None) -> None:
self.name = context
self.additional_objs = additional_objs
if context == 'local_proc':
self.method = local_simulations
elif context == 'single_proc':
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(self,
self.SimExecutor = SimExecutor
self.exec_method = exec_context.method
self.exec_context = exec_context.name
self.additional_objs = exec_context.additional_objs
self.configs = configs
self.empty_return = empty_return

Expand Down Expand Up @@ -174,7 +176,7 @@ def get_final_results(simulations: List[StateHistory],
print("Execution Method: " + self.exec_method.__name__)
simulations_results = self.exec_method(
sim_executors, var_dict_list, states_lists, configs_structs, env_processes_list, Ts, SimIDs, RunIDs,
ExpIDs, SubsetIDs, SubsetWindows, original_N
ExpIDs, SubsetIDs, SubsetWindows, original_N, self.additional_objs
)

final_result = get_final_results(
Expand Down
17 changes: 10 additions & 7 deletions cadCAD/engine/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def single_proc_exec(
ExpIDs: List[int],
SubsetIDs: List[SubsetID],
SubsetWindows: List[SubsetWindow],
configured_n: List[N_Runs]
configured_n: List[N_Runs],
additional_objs=None
):

# HACK for making it run with N_Runs=1
Expand All @@ -38,7 +39,7 @@ def single_proc_exec(
map(lambda x: x.pop(), raw_params)
)
result = simulation_exec(
var_dict_list, states_list, config, env_processes, T, sim_id, N, subset_id, subset_window, configured_n
var_dict_list, states_list, config, env_processes, T, sim_id, N, subset_id, subset_window, configured_n, additional_objs
)
return flatten(result)

Expand All @@ -58,7 +59,8 @@ def parallelize_simulations(
ExpIDs: List[int],
SubsetIDs: List[SubsetID],
SubsetWindows: List[SubsetWindow],
configured_n: List[N_Runs]
configured_n: List[N_Runs],
additional_objs=None
):

print(f'Execution Mode: parallelized')
Expand Down Expand Up @@ -96,7 +98,7 @@ def process_executor(params):
if len_configs_structs > 1:
pp = PPool(processes=len_configs_structs)
results = pp.map(
lambda t: t[0](t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9], configured_n), params
lambda t: t[0](t[1], t[2], t[3], t[4], t[5], t[6], t[7], t[8], t[9], configured_n, additional_objs), params
)
pp.close()
pp.join()
Expand All @@ -123,18 +125,19 @@ def local_simulations(
ExpIDs: List[int],
SubsetIDs: List[SubsetID],
SubsetWindows: List[SubsetWindow],
configured_n: List[N_Runs]
configured_n: List[N_Runs],
additional_objs=None
):
config_amt = len(configs_structs)

if config_amt == 1: # and configured_n != 1
return single_proc_exec(
simulation_execs, var_dict_list, states_lists, configs_structs, env_processes_list,
Ts, SimIDs, Ns, ExpIDs, SubsetIDs, SubsetWindows, configured_n
Ts, SimIDs, Ns, ExpIDs, SubsetIDs, SubsetWindows, configured_n, additional_objs
)
elif config_amt > 1: # and configured_n != 1
return parallelize_simulations(
simulation_execs, var_dict_list, states_lists, configs_structs, env_processes_list,
Ts, SimIDs, Ns, ExpIDs, SubsetIDs, SubsetWindows, configured_n
Ts, SimIDs, Ns, ExpIDs, SubsetIDs, SubsetWindows, configured_n, additional_objs
)
# elif config_amt > 1 and configured_n == 1:
50 changes: 31 additions & 19 deletions cadCAD/engine/simulation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from typing import Any, Callable, Dict, List, Tuple
from copy import deepcopy
from types import MappingProxyType
from functools import reduce
from funcy import curry
from funcy import curry # type: ignore

from cadCAD.utils import flatten
from cadCAD.engine.utils import engine_exception
from cadCAD.types import *

id_exception: Callable = curry(engine_exception)(KeyError)(KeyError)(None)

Expand Down Expand Up @@ -107,20 +109,30 @@ def env_composition(target_field, state_dict, target_value):
# mech_step
def partial_state_update(
self,
sweep_dict: Dict[str, List[Any]],
sub_step: int,
sL,
sH,
state_funcs: List[Callable],
policy_funcs: List[Callable],
env_processes: Dict[str, Callable],
sweep_dict: Parameters,
sub_step: Substep,
sL: list[State],
sH: StateHistory,
state_funcs: List[StateUpdateFunction],
policy_funcs: List[PolicyFunction],
env_processes: EnvProcesses,
time_step: int,
run: int,
additional_objs
) -> List[Dict[str, Any]]:

# last_in_obj: Dict[str, Any] = MappingProxyType(sL[-1])
last_in_obj: Dict[str, Any] = deepcopy(sL[-1])
if type(additional_objs) == dict:
if additional_objs.get('deepcopy_off', False) == True:
last_in_obj = MappingProxyType(sL[-1])
if len(additional_objs) == 1:
additional_objs = None
# XXX: drop the additional objects if only used for deepcopy
# toggling.
else:
last_in_obj = deepcopy(sL[-1])
else:
last_in_obj = deepcopy(sL[-1])

_input: Dict[str, Any] = self.policy_update_exception(
self.get_policy_input(sweep_dict, sub_step, sH, last_in_obj, policy_funcs, additional_objs)
)
Expand Down Expand Up @@ -217,18 +229,18 @@ def run_pipeline(

def simulation(
self,
sweep_dict: Dict[str, List[Any]],
states_list: List[Dict[str, Any]],
sweep_dict: SweepableParameters,
states_list: StateHistory,
configs,
env_processes: Dict[str, Callable],
time_seq: range,
simulation_id: int,
env_processes: EnvProcesses,
time_seq: TimeSeq,
simulation_id: SimulationID,
run: int,
subset_id,
subset_window,
configured_N,
subset_id: SubsetID,
subset_window: SubsetWindow,
configured_N: int,
# remote_ind
additional_objs=None
additional_objs: Union[None, Dict]=None
):
run += 1
subset_window.appendleft(subset_id)
Expand Down
8 changes: 4 additions & 4 deletions cadCAD/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ class ConfigurationDict(TypedDict):
N: int # Number of MC Runs
M: Union[Parameters, SweepableParameters] # Parameters / List of Parameter to Sweep


EnvProcesses = object
TargetValue = object
EnvProcess: Callable[[State, SweepableParameters, TargetValue], TargetValue]
EnvProcesses = dict[str, Callable]
TimeSeq = Iterator
SimulationID = int
Run = int
SubsetID = int
SubsetWindow = Iterator
N_Runs = int


ExecutorFunction = Callable[[Parameters, StateHistory, StateUpdateBlocks, EnvProcesses, TimeSeq, SimulationID, Run, SubsetID, SubsetWindow, N_Runs], object]
ExecutionParameter = Tuple[ExecutorFunction, Parameters, StateHistory, StateUpdateBlocks, EnvProcesses, TimeSeq, SimulationID, Run, SubsetID, SubsetWindow, N_Runs]

Expand All @@ -45,4 +45,4 @@ class SessionDict(TypedDict):
simulation_id: int
run_id: int
subset_id: int
subset_window: deque
subset_window: deque
Loading

0 comments on commit 13026ba

Please sign in to comment.