"s2": s2m2, # "s3": es3p1, # "s4": es4p2, } }, { "policies": { "b1": p1m3, "b2": p2m3 }, "variables": { "s1": s1m3, "s2": s2m3, # "s3": es3p1, # "s4": es4p2, } } ] sim_config_dict = {"N": 1, "T": range(5)} sim_config = config_sim(sim_config_dict) exp = Experiment() exp.append_model(model_id='sys_model_1', sim_configs=sim_config, initial_state=genesis_states, env_processes=env_processes, partial_state_update_blocks=partial_state_update_block, policy_ops=[lambda a, b: a + b])
} }, "m3": { "policies": { "b1": p1m3, "b2": p2m3 }, "states": { "s1": s1m3, "s2": s2m3 } } } sim_config_dict = { "N": 3, "T": range(5), } sim_config = config_sim(sim_config_dict) exp = Experiment() exp.append_model( model_id='sys_model_1', sim_configs=sim_config, initial_state=genesis_states, env_processes=env_processes, partial_state_update_blocks=partial_state_update_block )
"b2": p2m3 }, "states": { "s1": s1m3, "s2": s2m3 } } } sim_config_dict = { "N": 3, "T": range(5), } sim_config = config_sim(sim_config_dict) exp = Experiment() exp.append_model( # config_list=configs, user_id='user_b', sim_configs=sim_config, initial_state=genesis_states, env_processes=env_processes, partial_state_update_blocks=partial_state_update_block) multi_exp.append_model(model_id='sys_model_2', sim_configs=sim_config, initial_state=genesis_states, env_processes=env_processes, partial_state_update_blocks=partial_state_update_block)
}, "m2": { "policies": { "p1": p1m2, "p2": p2m2 }, "variables": variables }, "m3": { "policies": { "p1": p1m3, "p2": p2m3 }, "variables": variables } } sim_config = config_sim({ "N": 1, "T": range(3), }) exp = Experiment() exp.append_model( sim_configs=sim_config, initial_state=genesis_states, partial_state_update_blocks=partial_state_update_block, policy_ops=[lambda a, b: a + b, lambda y: y * 2] # Default: lambda a, b: a + b )
f=sweeped) # Genesis States genesis_states = {'alpha': 0, 'beta': 0, 'policies': {}, 'sweeped': {}} # Environment Process env_process['sweeped'] = env_timestep_trigger( trigger_field='timestep', trigger_vals=[5], funct_list=[lambda _g, x: _g['beta']]) sim_config = config_sim({ "N": 2, "T": range(5), "M": g, # Optional }) # New Convention partial_state_update_blocks = psub_list(psu_block, psu_steps) exp = Experiment() exp.append_model(sim_configs=sim_config, initial_state=genesis_states, env_processes=env_process, partial_state_update_blocks=partial_state_update_blocks) experiment.append_model( sim_configs=sim_config, initial_state=genesis_states, env_processes=env_process, partial_state_update_blocks=partial_state_update_blocks)
from cadCAD.configuration import Experiment from cadCAD.configuration.utils import config_sim from .state_variables import genesis_states from .partial_state_update_block import partial_state_update_block from .sys_params import sys_params sim_config = config_sim({ 'N': 1, # number of monte carlo runs 'T': range(1000), # number of timesteps 'M': sys_params, # simulation parameters }) exp = Experiment() exp.append_model(sim_configs=sim_config, model_id='sys_model_j', initial_state=genesis_states, partial_state_update_blocks=partial_state_update_block)
'3rd_to_last_x': [], '4th_to_last_x': [] } PSUB = {"policies": policies, "variables": variables} psubs = {"PSUB1": PSUB, "PSUB2": PSUB, "PSUB3": PSUB} sim_config = config_sim({ "N": 1, "T": range(3), }) exp = Experiment() exp.append_model(model_id='hist_state_access', sim_configs=sim_config, initial_state=genesis_states, partial_state_update_blocks=psubs) exec_mode = ExecutionMode() local_proc_ctx = ExecutionContext(context=exec_mode.local_mode) run = Executor(exec_context=local_proc_ctx, configs=exp.configs) raw_result, tensor_field, sessions = run.execute() result = pd.DataFrame(raw_result) cols = [ 'run', 'substep', 'timestep', 'x', 'nonexsistant', 'last_x', '2nd_to_last_x', '3rd_to_last_x', '4th_to_last_x' ] result = result[cols] print()
import json import os import unittest, pandas as pd from cadCAD.configuration import Experiment from cadCAD.engine import ExecutionMode, ExecutionContext, Executor from testing.models import param_sweep, policy_aggregation exp = Experiment() sys_model_A_id = "sys_model_A" exp.append_model( model_id=sys_model_A_id, sim_configs=param_sweep.sim_config, initial_state=param_sweep.genesis_states, env_processes=param_sweep.env_process, partial_state_update_blocks=param_sweep.partial_state_update_blocks ) sys_model_B_id = "sys_model_B" exp.append_model( model_id=sys_model_B_id, sim_configs=param_sweep.sim_config, initial_state=param_sweep.genesis_states, env_processes=param_sweep.env_process, partial_state_update_blocks=param_sweep.partial_state_update_blocks ) sys_model_C_id = "sys_model_C" exp.append_model( model_id=sys_model_C_id, sim_configs=policy_aggregation.sim_config, initial_state=policy_aggregation.genesis_states, partial_state_update_blocks=policy_aggregation.partial_state_update_block, policy_ops=[lambda a, b: a + b, lambda y: y * 2] # Default: lambda a, b: a + b
psu_block[m]["variables"]['alpha'] = alpha_plus_gamma psu_block[m]["variables"]['alpha_plus_gamma'] = alpha psu_block[m]["variables"]['beta'] = beta psu_block[m]['variables']['policies'] = policies psu_block[m]["variables"]['sweeped'] = var_timestep_trigger(y='sweeped', f=sweeped) psubs = psub_list(psu_block, psu_steps) print() pp.pprint(psu_block) print() exp = Experiment() exp.append_model( model_id='param_sweep', sim_configs=sim_config, initial_state=genesis_states, env_processes=env_process, partial_state_update_blocks=psubs ) exec_mode = ExecutionMode() local_proc_ctx = ExecutionContext(context=exec_mode.local_mode) run = Executor(exec_context=local_proc_ctx, configs=exp.configs) raw_result, tensor_field, sessions = run.execute() result = pd.DataFrame(raw_result) print() print("Tensor Field:") print(tabulate(tensor_field, headers='keys', tablefmt='psql')) print("Output:") print(tabulate(result, headers='keys', tablefmt='psql'))