Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug M dictionairy unpacking in utils. #343

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -64,7 +65,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,
)