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

fix: easy supports list/array/sequence type as parameter #348

Merged
merged 1 commit into from
Mar 14, 2024
Merged
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
26 changes: 16 additions & 10 deletions cadCAD/tools/execution/easy_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import types
from typing import Dict, Union

import pandas as pd # type: ignore
import pandas as pd # type: ignore
from cadCAD.configuration import Experiment
from cadCAD.configuration.utils import config_sim
from cadCAD.engine import ExecutionContext, ExecutionMode, Executor
Expand Down Expand Up @@ -47,8 +47,9 @@ def easy_run(
"""

# Set-up sim_config
simulation_parameters = {'N': N_samples, 'T': range(N_timesteps), 'M': params}
sim_config = config_sim(simulation_parameters) # type: ignore
simulation_parameters = {'N': N_samples,
'T': range(N_timesteps), 'M': params}
sim_config = config_sim(simulation_parameters) # type: ignore

# Create a new experiment
exp = Experiment()
Expand Down Expand Up @@ -91,22 +92,27 @@ def easy_run(
if assign_params == True:
pass
else:
params_set &= assign_params # type: ignore
params_set &= assign_params # type: ignore

# Logic for getting the assign params criteria
if type(assign_params) is list:
selected_params = set(assign_params) & params_set # type: ignore
selected_params = set(assign_params) & params_set # type: ignore
elif type(assign_params) is set:
selected_params = assign_params & params_set
else:
selected_params = params_set
# Attribute parameters to each row*
params_dict = select_config_M_dict(configs, 0, selected_params)

# Handles all cases of parameter types including list
for key, value in params_dict.items():
df[key] = df.apply(lambda _: value, axis=1)

# Attribute parameters to each row
df = df.assign(**select_config_M_dict(configs, 0, selected_params))
for i, (_, n_df) in enumerate(df.groupby(['simulation', 'subset', 'run'])):
df.loc[n_df.index] = n_df.assign(
**select_config_M_dict(configs, i, selected_params)
)
params_dict = select_config_M_dict(configs, i, selected_params)
for key, value in params_dict.items():
df.loc[n_df.index, key] = df.loc[n_df.index].apply(
lambda _: value, axis=1)

# Based on Vitor Marthendal (@marthendalnunes) snippet
if use_label == True:
Expand Down