def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY blue_agents = Composite(group_names[BLUE_GRP_IDX], {"color": BLUE}, member_creator=create_resident, num_members=get_prop('num_blue', NUM_BLUE, execution_key=execution_key), group=BLUE, execution_key=execution_key) red_agents = Composite(group_names[RED_GRP_IDX], {"color": RED}, member_creator=create_resident, num_members=get_prop('num_red', NUM_RED, execution_key=execution_key), group=RED, execution_key=execution_key) city = Env(MODEL_NAME, members=[blue_agents, red_agents], height=get_prop('grid_height', DEF_CITY_DIM, execution_key=execution_key), width=get_prop('grid_width', DEF_CITY_DIM, execution_key=execution_key), execution_key=execution_key) city.exclude_menu_item("line_graph")
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY calm = Composite(CALM, {"color": BLUE}, member_creator=create_resident, num_members=get_prop('num_people', NUM_CALM_AGENTS, execution_key=execution_key), group=BLUE, execution_key=execution_key) panic = Composite(PANIC, {"color": RED}, member_creator=create_resident, num_members=NUM_PANIC_AGENTS, group=RED, execution_key=execution_key) city = Env(MODEL_NAME, members=[calm, panic], height=get_prop('grid_height', DEF_CITY_DIM, execution_key=execution_key), width=get_prop('grid_width', DEF_CITY_DIM, execution_key=execution_key), execution_key=execution_key) set_env_attr(STATES, [CALM, PANIC], execution_key=execution_key) city.exclude_menu_item("line_graph")
def set_up(props=None): """ A func to set up run that can also be used by test code. """ global sandpile_env global groups global group_indices pa = get_props(MODEL_NAME, props) width = pa.get('grid_width', DEF_WIDTH) height = pa.get('grid_height', DEF_HEIGHT) groups = [] group_indices = {} for i in range(NUM_GROUPS): groups.append(Composite("Group" + str(i), {"marker": CIRCLE})) group_indices[groups[i].name] = i for y in range(height): for x in range(width): groups[0] += create_grain(x, y) sandpile_env = Env("Sandpile", action=sandpile_action, height=height, width=width, members=groups, attrs={"size": 65, "hide_axes": True, "hide_legend": True}, random_placing=False, props=pa) sandpile_env.attrs["center_agent"] = sandpile_env.get_agent_at(height // 2, width // 2) return sandpile_env, groups, group_indices
def run_model_put(payload, run_time): """ We create a dummy env that fills itself in to create the real env from the payload. """ env = Env(name='temp name', serial_obj=payload) env.runN(periods=run_time) return json_converter(env)
def test_runN(self): """ Test running for N turns. """ new_env = Env("Test1 env", action=env_action, members=[self.newton]) num_periods = 10 acts = new_env.runN(num_periods) self.assertEqual(acts, num_periods)
def test_plot_data(self): """ Test the construction of scatter plot data. """ global travis travis = os.getenv("TRAVIS") if not travis: our_grp = Composite(GRP1, members=[self.newton]) self.env = Env("Test env", members=[our_grp]) ret = self.env.plot_data() (x, y) = self.newton.pos self.assertEqual(ret, {GRP1: {X: [x], Y: [y], 'color': None}})
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY width = get_prop('grid_width', DEF_WIDTH, execution_key=execution_key) height = (width // 2) + (width % 2) groups = [ Composite(WHITE, {"color": WHITE}, execution_key=execution_key), Composite(BLACK, { "color": BLACK, "marker": SQUARE }, execution_key=execution_key) ] for y in range(height): for x in range(width): groups[W] += create_wolf_cell(x, y, execution_key) wolfram_env = Env(MODEL_NAME, action=wolfram_action, height=height, width=width, members=groups, attrs={ "size": 50, "hide_grid_lines": True, "hide_legend": True }, random_placing=False, execution_key=execution_key) rule_num = get_prop('rule_number', DEF_RULE, execution_key=execution_key) wolfram_env.set_attr("rule_num", rule_num) wolfram_env.set_attr("rule_dict", get_rule(rule_num)) wolfram_env.exclude_menu_item("line_graph") ''' This switch needs to happen before the environment is executed. Using add switch doesn't process the switch until after the environment is executed which breaks the model. ''' top_center_agent = \ wolfram_env.get_agent_at(width // 2, top_row(execution_key)) switch(top_center_agent.name, WHITE, BLACK, execution_key=execution_key) # top row is the "previous" because we just processed it set_env_attr("prev_row_idx", top_row(execution_key), execution_key=execution_key)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY groups = [] groups.append( Composite(BLUE_TSETTERS, {"color": NAVY}, execution_key=execution_key)) groups.append(Composite(RED_TSETTERS, {"color": DARKRED}, member_creator=create_tsetter, num_members=get_prop('num_tsetters', NUM_TSETTERS, execution_key=execution_key), execution_key=execution_key)) groups.append( Composite(RED_FOLLOWERS, {"color": RED}, execution_key=execution_key)) groups.append(Composite(BLUE_FOLLOWERS, {"color": BLUE}, member_creator=create_follower, num_members=get_prop('num_followers', NUM_FOLLOWERS, execution_key=execution_key), execution_key=execution_key)) Env(MODEL_NAME, members=groups, attrs={OPP_GROUP: opp_group}, execution_key=execution_key)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY width = get_prop('grid_width', DEF_WIDTH, execution_key=execution_key) height = get_prop('grid_height', DEF_HEIGHT, execution_key=execution_key) groups = [] for i in range(NUM_GROUPS): groups.append( Composite(str(i), {"marker": CIRCLE}, execution_key=execution_key)) for y in range(height): for x in range(width): groups[0] += create_grain(x, y, execution_key=execution_key) sandpile_env = Env(MODEL_NAME, action=sandpile_action, height=height, width=width, members=groups, attrs={ "size": 65, "hide_axes": True, "hide_legend": True }, random_placing=False, execution_key=execution_key) # these settings must be re-done every API re-load: set_env_attrs(execution_key) return sandpile_env, groups
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY blue_group = Composite("Blues", {"color": BLUE}, member_creator=create_agent, num_members=get_prop('num_blue', DEF_NUM_BLUE, execution_key=execution_key), execution_key=execution_key) red_group = Composite("Reds", {"color": RED}, member_creator=create_agent, num_members=get_prop('num_red', DEF_NUM_RED, execution_key=execution_key), execution_key=execution_key) Env(MODEL_NAME, height=get_prop('grid_height', DEF_HEIGHT, execution_key=execution_key), width=get_prop('grid_width', DEF_WIDTH, execution_key=execution_key), members=[blue_group, red_group], execution_key=execution_key)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) num_members = get_prop('num_babysitter', DEF_BABYSITTER) co_op_members = Composite(CO_OP_MEMBERS, num_members=num_members, member_creator=create_babysitter) central_bank = Composite("central_bank", num_members=1, member_creator=create_central_bank) Env('coop_env', members=[co_op_members, central_bank], action=coop_action, width=UNLIMITED, height=UNLIMITED, census=coop_report, pop_hist_setup=initial_exchanges, pop_hist_func=record_exchanges, attrs={ "show_special_points": CB_intervention_points, "special_points_name": "CB intervention points" })
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY toxins = Composite(TOXINS, {"color": RED}, member_creator=create_toxin, num_members=get_prop('num_toxins', NUM_TOXINS, execution_key=execution_key), execution_key=execution_key) nutrients = Composite(NUTRIENTS, {"color": GREEN}, member_creator=create_nutrient, num_members=get_prop('num_nutrients', NUM_TOXINS, execution_key=execution_key), execution_key=execution_key) bacteria = Composite(BACTERIA, {"color": BLUE}, member_creator=create_bacterium, num_members=get_prop('num_toxins', DEF_NUM_BACT, execution_key=execution_key), execution_key=execution_key) Env(MODEL_NAME, height=get_prop('grid_height', DEF_HEIGHT, execution_key=execution_key), width=get_prop('grid_width', DEF_WIDTH, execution_key=execution_key), members=[toxins, nutrients, bacteria], execution_key=execution_key)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) exec_key = init_exec_key(props) groups = [] groups.append( Composite("value_investors", {"color": BLUE}, member_creator=create_value_investor, num_members=get_prop("value_investors", DEF_NUM_VALUE_INVESTOR, execution_key=exec_key), execution_key=exec_key)) groups.append( Composite("trend_followers", {"color": RED}, member_creator=create_trend_follower, num_members=get_prop("trend_followers", DEF_NUM_TREND_FOLLOWER, execution_key=exec_key), execution_key=exec_key), ) groups.append(create_market_maker(MARKET_MAKER)) Env(MODEL_NAME, members=groups, width=UNLIMITED, height=UNLIMITED, pop_hist_setup=initial_price, execution_key=exec_key) get_env(execution_key=exec_key).exclude_menu_item("scatter_plot") set_env_attrs(execution_key=exec_key)
def set_up(): """ A func to set up run that can also be used by test code. """ blue_tsetters = Composite(BLUE_TSETTERS, {"color": NAVY}) red_tsetters = Composite(RED_TSETTERS, {"color": DARKRED}) for i in range(NUM_TSETTERS): red_tsetters += create_tsetter(i) if DEBUG2: print(red_tsetters.__repr__()) red_followers = Composite(RED_FOLLOWERS, {"color": RED}) blue_followers = Composite(BLUE_FOLLOWERS, {"color": BLUE}) for i in range(NUM_FOLLOWERS): blue_followers += create_follower(i) opp_group = {str(red_tsetters): blue_tsetters, str(blue_tsetters): red_tsetters, str(red_followers): blue_followers, str(blue_followers): red_followers} if DEBUG2: print(blue_followers.__repr__()) society = Env("society", members=[blue_tsetters, red_tsetters, blue_followers, red_followers]) return (blue_tsetters, red_tsetters, blue_followers, red_followers, opp_group, society)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ global population global optimal_occupancy global agents_decided init_props(MODEL_NAME, props) agents_decided = 0 drinkers = Composite(DRINKERS, {"color": RED}, member_creator=create_drinker, num_members=get_prop('population', DEF_POPULATION) // 2) non_drinkers = Composite(NON_DRINKERS, {"color": BLUE}, member_creator=create_non_drinker, num_members=get_prop('population', DEF_POPULATION) // 2) population = len(drinkers) + len(non_drinkers) optimal_occupancy = int(population * 0.6) Env("bar", height=get_prop('grid_height', DEF_HEIGHT), width=get_prop('grid_width', DEF_WIDTH), members=[drinkers, non_drinkers])
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) exec_key = init_exec_key(props) members = [] members.append( Composite(WOLF_GROUP, attrs={"color": TAN}, member_creator=create_wolf, num_members=get_prop('num_wolves', NUM_WOLVES, execution_key=exec_key), execution_key=exec_key)) members.append( Composite(SHEEP_GROUP, attrs={"color": GRAY}, member_creator=create_sheep, num_members=get_prop('num_sheep', NUM_SHEEP, execution_key=exec_key), execution_key=exec_key)) Env(MODEL_NAME, members=members, attrs={ "prey_dist": get_prop("prey_dist", PREY_DIST, execution_key=exec_key) }, height=get_prop('grid_height', MEADOW_HEIGHT, execution_key=exec_key), width=get_prop('grid_width', MEADOW_WIDTH, execution_key=exec_key), execution_key=exec_key)
def set_up(props=None): # testcase??? """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props, model_dir="ml") group = [] group.append( Composite(DEALER_GRP, {"color": BLUE}, member_creator=generate_dealer, num_members=get_prop('num_dealers', DEF_NUM_DEALER))) # can we put the testing period in to composite too? group.append( Composite(AVA_BUYER_GRP, {"color": RED}, member_creator=ava_cb, num_members=get_prop('num_buyers', DEF_NUM_BUYER))) group.append( Composite(SELINA_BUYER_GRP, {"color": RED}, member_creator=selina_cb, num_members=get_prop('num_buyers', DEF_NUM_BUYER))) Env(MODEL_NAME, height=get_prop('grid_height', DEF_HEIGHT), width=get_prop('grid_width', DEF_WIDTH), members=group)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY population_prop = \ get_prop('population', DEF_POPULATION, execution_key=execution_key) drinkers = Composite(DRINKERS, {"color": RED}, member_creator=create_drinker, num_members=population_prop // 2, execution_key=execution_key) non_drinkers = Composite(NON_DRINKERS, {"color": BLUE}, member_creator=create_non_drinker, num_members=population_prop // 2, execution_key=execution_key) Env(MODEL_NAME, height=get_prop('grid_height', DEF_HEIGHT, execution_key=execution_key), width=get_prop('grid_width', DEF_WIDTH, execution_key=execution_key), members=[drinkers, non_drinkers], pop_hist_setup=setup_attendance, execution_key=execution_key) population = len(drinkers) + len(non_drinkers) set_env_attr(POPULATION, population, execution_key=execution_key) set_env_attr(OPT_OCCUPANCY, int(population * DEF_MOTIV), execution_key=execution_key) set_env_attr(AGENTS_DECIDED, 0, execution_key=execution_key) set_env_attr(ATTENDANCE, 0, execution_key=execution_key) set_env_attrs(execution_key=execution_key)
def set_up(): """ A func to set up run that can also be used by test code. """ global on_fire global healthy healthy = Composite(HEALTHY, {"color": GREEN}) new_fire = Composite(NEW_FIRE, {"color": TOMATO}) on_fire = Composite(ON_FIRE, {"color": RED}) burned_out = Composite(BURNED_OUT, {"color": BLACK}) new_growth = Composite(NEW_GROWTH, {"color": SPRINGGREEN}) for i in range(int(FOREST_HEIGHT * FOREST_WIDTH * DENSITY)): healthy += plant_tree(i) forest = Env("Forest", height=FOREST_HEIGHT, width=FOREST_WIDTH, members=[healthy, new_fire, on_fire, burned_out, new_growth]) global group_map group_map = { HE: healthy, NF: new_fire, OF: on_fire, BO: burned_out, NG: new_growth } return (forest, group_map)
def set_up(): """ A func to set up run that can also be used by test code. """ pa = PropArgs.create_props('basic_props', ds_file='props/fashion.props.json') blue_tsetters = Composite(BLUE_TSETTERS, {"color": NAVY}) red_tsetters = Composite(RED_TSETTERS, {"color": DARKRED}) for i in range(pa.get('num_tsetters', NUM_TSETTERS)): red_tsetters += create_tsetter(i) if DEBUG2: print(red_tsetters.__repr__()) red_followers = Composite(RED_FOLLOWERS, {"color": RED}) blue_followers = Composite(BLUE_FOLLOWERS, {"color": BLUE}) for i in range(pa.get('num_followers', NUM_FOLLOWERS)): blue_followers += create_follower(i) opp_group = {str(red_tsetters): blue_tsetters, str(blue_tsetters): red_tsetters, str(red_followers): blue_followers, str(blue_followers): red_followers} if DEBUG2: print(blue_followers.__repr__()) society = Env("society", members=[blue_tsetters, red_tsetters, blue_followers, red_followers]) return (blue_tsetters, red_tsetters, blue_followers, red_followers, opp_group, society)
def set_up(): """ A func to set up run that can also be used by test code. """ global pa pa = PropArgs.create_props('wolfsheep_props', ds_file='props/wolfsheep.props.json') wolves = Composite(COMP_WOLF_NAME, {"color": TAN}) for i in range(pa.get('num_wolves', NUM_WOLVES)): wolves += create_wolf(i, pa) if DEBUG2: print(wolves.__repr__()) sheep = Composite(COMP_SHEEP_NAME, {"color": GRAY}) for i in range(pa.get('num_sheep', NUM_SHEEP)): sheep += create_sheep(i, pa) if DEBUG2: print(sheep.__repr__()) meadow = Env("meadow", members=[wolves, sheep], height=pa.get('meadow_height', MEADOW_HEIGHT), width=pa.get('meadow_width', MEADOW_WIDTH)) return (wolves, sheep, meadow)
def set_up(): """ A func to set up run that can also be used by test code. """ global on_fire global healthy ds_file = 'props/forestfire.props.json' pa = PropArgs.create_props('forest_fire_props', ds_file=ds_file) forest_height = pa.get('grid_height', DEF_DIM) forest_width = pa.get('grid_width', DEF_DIM) forest_density = pa.get('density', DEF_DENSITY) healthy = Composite(HEALTHY, {"color": GREEN}) new_fire = Composite(NEW_FIRE, {"color": TOMATO}) on_fire = Composite(ON_FIRE, {"color": RED}) burned_out = Composite(BURNED_OUT, {"color": BLACK}) new_growth = Composite(NEW_GROWTH, {"color": SPRINGGREEN}) for i in range(int(forest_height * forest_width * forest_density)): healthy += plant_tree(i) forest = Env("Forest", height=forest_height, width=forest_width, members=[healthy, new_fire, on_fire, burned_out, new_growth]) global group_map group_map = {HE: healthy, NF: new_fire, OF: on_fire, BO: burned_out, NG: new_growth} return (forest, group_map)
def set_up(): """ A func to set up run that can also be used by test code. """ pa = PropArgs.create_props('basic_props', ds_file='props/segregation.props.json') blue_agents = Composite(group_names[BLUE_TEAM] + " group", {"color": BLUE}) red_agents = Composite(group_names[RED_TEAM] + " group", {"color": RED}) for i in range(pa['num_red']): red_agents += create_agent(i, pa.get('mean_tol', DEF_TOLERANCE), pa.get('deviation', DEF_SIGMA), color=RED_TEAM) if DEBUG2: print(red_agents.__repr__()) for i in range(pa['num_blue']): blue_agents += create_agent(i, pa.get('mean_tol', DEF_TOLERANCE), pa.get('deviation', DEF_SIGMA), color=BLUE_TEAM) if DEBUG2: print(blue_agents.__repr__()) city = Env("A city", members=[blue_agents, red_agents], height=pa['grid_height'], width=pa['grid_width']) return (blue_agents, red_agents, city)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) groups = [] groups.append( Composite("value_investors", {"color": BLUE}, member_creator=create_value_investor, num_members=get_prop("value_investors", DEF_NUM_VALUE_INVESTOR))) groups.append( Composite("trend_followers", {"color": RED}, member_creator=create_trend_follower, num_members=get_prop("trend_followers", DEF_NUM_TREND_FOLLOWER))) groups.append(create_market_maker("market_maker")) Env("fmarket", members=groups, width=UNLIMITED, height=UNLIMITED, census=market_report, line_data_func=plot_asset_price) get_env().exclude_menu_item("scatter_plot")
def set_up(props=None): """ A func to set up run that can also be used by test code. """ global groups pa = get_props(MODEL_NAME, props) height = pa.get("grid_height", DEF_HEIGHT) width = pa.get("grid_width", DEF_WIDTH) simulation = pa.get("simulation", 0) black = Composite("Black", {"color": BLACK, "marker": SQUARE}) groups = [black] Env("Game of Life", action=gameoflife_action, height=height, width=width, members=groups, attrs={"size": 100, "change_grid_spacing": (0.5, 1), "hide_xy_ticks": True, "hide_legend": True}, random_placing=False, props=pa) populate_board_dict[simulation](width, height) return groups
def set_up(props=None): """ A func to set up run that can also be used by test code. """ pa = init_props(MODEL_NAME, props, model_dir="capital") execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY traders = Composite("Traders", member_creator=create_trader, props=pa, num_members=get_prop('num_traders', DEF_NUM_TRADERS, execution_key=execution_key), execution_key=execution_key) check_props(execution_key=execution_key) nature_to_traders(traders, natures_goods) Env(MODEL_NAME, height=get_prop('grid_height', DEF_HEIGHT, execution_key=execution_key), width=get_prop('grid_width', DEF_WIDTH, execution_key=execution_key), members=[traders], attrs={"goods": natures_goods}, pop_hist_setup=initial_amt, execution_key=execution_key) set_env_attrs(execution_key=execution_key)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY num_members = get_prop('num_babysitter', DEF_BABYSITTER, execution_key=execution_key) co_op_members = Composite(CO_OP_MEMBERS, {"color": RED}, num_members=num_members, member_creator=create_babysitter, execution_key=execution_key) central_bank = Composite("central_bank", {"color": GREEN}, num_members=1, member_creator=create_central_bank, execution_key=execution_key) Env(MODEL_NAME, members=[co_op_members, central_bank], action=coop_action, width=UNLIMITED, height=UNLIMITED, pop_hist_setup=initial_exchanges, attrs={ "last_per_exchg": 0, "last_per_unemp": 0, "num_rounds": 0, "CB_interven_pts": [] }, execution_key=execution_key) set_env_attrs(execution_key=execution_key)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ global max_util pa = init_props(MODEL_NAME, props, model_dir="capital") cheese_group = Composite("Cheese holders", {"color": BLUE}, member_creator=create_cagent, props=pa, num_members=get_prop('num_cagents', DEF_NUM_CAGENTS)) wine_group = Composite("Wine holders", {"color": RED}, member_creator=create_wagent, props=pa, num_members=get_prop('num_wagents', DEF_NUM_WAGENTS)) Env("EdgeworthBox", height=get_prop('grid_height', DEF_HEIGHT), width=get_prop('grid_width', DEF_WIDTH), members=[cheese_group, wine_group]) start_cheese = 0 start_wine = 0 if pa is not None: start_cheese = get_prop('start_cheese', DEF_NUM_CHEESE) start_wine = get_prop('start_wine', DEF_NUM_WINE) max_util = max(start_cheese, start_wine) else: props_max_util = max(start_cheese, start_wine) max_util = max(props_max_util, DEF_MAX_UTIL) return (cheese_group, wine_group, max_util)
def set_up(props=None): """ A func to set up run that can also be used by test code. """ global resource_holders global entrepreneurs pa = init_props(MODEL_NAME, props, model_dir="capital") entrepreneurs = Composite("Entrepreneurs", {"color": BLUE}, member_creator=create_entr, props=pa, num_members=pa.get('num_entr', DEF_NUM_ENTR)) resource_holders = Composite("Resource_holders", {"color": RED}, member_creator=create_rholder, props=pa, num_members=pa.get('num_rholder', DEF_NUM_RHOLDER)) Env("neighborhood", height=get_prop('grid_height', DEF_HEIGHT), width=get_prop('grid_width', DEF_WIDTH), members=[resource_holders, entrepreneurs]) return resource_holders, entrepreneurs
def set_up(props=None): """ A func to set up a run that can also be used by test code. """ init_props(MODEL_NAME, props) execution_key = int(props[EXEC_KEY].val) \ if props is not None else CLI_EXEC_KEY forest_height = get_prop('grid_height', DEF_DIM, execution_key=execution_key) forest_width = get_prop('grid_width', DEF_DIM, execution_key=execution_key) new_fire = get_prop('new_fire', DEF_NEW_FIRE, execution_key=execution_key) set_trans(state_trans, HE, NF, float(new_fire), HE) forest_density = get_prop('density', DEF_DENSITY, execution_key=execution_key) tree_cnt = int(forest_height * forest_width * forest_density) groups = [] groups.append( Composite(HEALTHY, { "color": GREEN, "marker": TREE }, member_creator=plant_tree, num_members=tree_cnt, execution_key=execution_key)) groups.append( Composite(NEW_FIRE, { "color": TOMATO, "marker": TREE }, execution_key=execution_key)) groups.append( Composite(ON_FIRE, { "color": RED, "marker": TREE }, execution_key=execution_key)) groups.append( Composite(BURNED_OUT, { "color": BLACK, "marker": TREE }, execution_key=execution_key)) groups \ .append(Composite(NEW_GROWTH, {"color": SPRINGGREEN, "marker": TREE}, execution_key=execution_key)) Env(MODEL_NAME, height=forest_height, width=forest_width, members=groups, execution_key=execution_key) # the next set should just be done once: set_env_attr(TRANS_TABLE, state_trans, execution_key=execution_key) # whereas these settings must be re-done every API re-load: set_env_attrs(execution_key=execution_key)