Skip to content

Commit

Permalink
Debug M dictionairy unpacking in utils. (#343)
Browse files Browse the repository at this point in the history
* Debug M dictionairy unpacking in utils.

* Update deepcopy_off in easy_run.
  • Loading branch information
LinuxIsCool authored Mar 14, 2024
1 parent c2ae474 commit 3317b82
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cadCAD/configuration/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def config_sim(config_dict: ConfigurationDict):
raise Exception('When sweeping, `M` list lengths should either be 1 and/or equal. More than two distinct lengths are not allowed')
elif (distinct_param_value_lengths == 1) and (0 in param_values_length_set):
return config_dict
elif (1 in param_values_length_set):
elif (distinct_param_value_lengths == 1) or (1 in param_values_length_set):
return [{**config_dict, "M": M}

for M in flatten_tabulated_dict(tabulate_dict(params))]
Expand Down
3 changes: 2 additions & 1 deletion cadCAD/tools/execution/easy_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def easy_run(
assign_params: Union[bool, set] = True,
drop_substeps=True,
exec_mode='local',
deepcopy_off=False,
) -> pd.DataFrame:
"""
Run cadCAD simulations without headaches.
Expand All @@ -65,7 +66,7 @@ def easy_run(
_exec_mode = ExecutionMode().local_mode
elif exec_mode == 'single':
_exec_mode = ExecutionMode().single_mode
exec_context = ExecutionContext(_exec_mode)
exec_context = ExecutionContext(_exec_mode, additional_objs={'deepcopy_off': deepcopy_off})
executor = Executor(exec_context=exec_context, configs=configs)

# Execute the cadCAD experiment
Expand Down
66 changes: 66 additions & 0 deletions testing/tools/test_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from cadCAD.tools.execution import easy_run

# def test_empty_easy_run():
# state_variables = {
# }
#
# params = {
# }
#
# psubs = [
# {
# 'policies': {},
# 'variables': {},
# },
# ]
#
# N_timesteps = 2
#
# N_samples = 1
#
# results = easy_run(
# state_variables,
# params,
# psubs,
# N_timesteps,
# N_samples,
# )
# print(results)



def test_easy_run():
state_variables = {
'a':0.5,
}

params = {
'c':[1, 2],
'd':[1, 2],
}

def p(params, substep, state_history, previous_state):
a_delta = 1 - params['c'] * previous_state['a']
return {'a_delta': a_delta}

def s(params, substep, state_history, previous_state, policy_input):
return 'a', previous_state['a'] + policy_input['a_delta']

psubs = [
{
'policies': {'p': p},
'variables': {'a': s},
},
]

N_timesteps = 2

N_samples = 1

results = easy_run(
state_variables,
params,
psubs,
N_timesteps,
N_samples,
)

0 comments on commit 3317b82

Please sign in to comment.