How to use the indra.utils.gen_file_names function in indra

To help you get started, we’ve selected a few indra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gcallah / indras_net / models / stance_run.py View on Github external
#!/usr/bin/env python3
"""
Runs a model with leaders and followers.
"""

import indra.utils as utils
import indra.prop_args as props
import stance_model as sm

# set up some file names:
MODEL_NM = "stance_model"
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

# We store basic parameters in a "property" file; this allows us to save
#  multiple parameter sets, which is important in simulation work.
#  We can read these in from file or set them here.
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    utils.get_grid_dims(pa, 16)
    utils.get_agent_num(pa, "num_followers", "followers", 48)
    utils.get_agent_num(pa, "num_linvest", "leaders", 16)
    utils.get_max_move(pa, "fmax_move", "follower", 4)
    utils.get_max_move(pa, "lmax_move", "leader", 4)

# Now we create a minimal environment for our agents to act within:
env = sm.StanceEnv("Stance Environment",
                   pa.get("grid_height"),
github gcallah / indras_net / models / archive / menu_run.py View on Github external
def run():
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
    
    # We store menu parameters in a
    # "property" file; this allows us to save
    #  multiple parameter sets, which is important in simulation work.
    #  We can read these in from file or set them here.
    pa = utils.read_props(MODEL_NM)
    if pa is None:
        pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    
    # Now we create a minimal environment for our agents to act within:
    env = mm.MenuEnv(model_nm=MODEL_NM, props=pa)
    
    # Now we loop creating multiple agents
    #  with numbered names based on the loop variable:
    for i in range(pa.get("num_agents")):
        env.add_agent(mm.MenuAgent(name="agent" + str(i),
github gcallah / indras_net / schelling / auditorium_run.py View on Github external
def run(prop_dict=None):
    (prog_file, log_file, 
     prop_file, results_file) = utils.gen_file_names(MODEL_NM)
    
    global pa

    # Now we create an environment for our agents to act within:
    env = am.Auditorium("Auditorium",
                        height=pa["grid_height"],
                        width=pa["grid_width"],
                        torus=False,
                        model_nm=MODEL_NM,
                        num_agents=pa["num_agents"],
                        props=pa)
    
    return utils.run_model(env, prog_file, results_file)
github gcallah / indras_net / models / grid_run.py View on Github external
def run(prop_dict=None):
    pa = props.PropArgs.create_props(MODEL_NM, prop_dict)

    import indra.utils as utils
    import indra.grid_env as ge
    import models.grid as gm
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

    if pa["user_type"] == props.WEB:
        pa["base_dir"] = os.environ["base_dir"]

    # Now we create a minimal environment for our agents to act within:
    env = ge.GridEnv("Test grid env",
                     pa["grid_width"],
                     pa["grid_height"],
                     torus=False,
                     model_nm=MODEL_NM,
                     preact=True,
                     postact=True,
                     props=pa)

    # Now we loop creating multiple agents with numbered names
    # based on the loop variable:
github gcallah / indras_net / models / bacterium_run.py View on Github external
#!/usr/bin/env python3
"""
A script to run the bacterium model.
"""

import indra.utils as utils
import indra.prop_args as props
import indra.grid_env as ge
import models.bacterium_model as bm

# set up some file names:
MODEL_NM = "grid_model"
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

# We store basic parameters in a "property" file; this allows us to save
#  multiple parameter sets, which is important in simulation work.
#  We can read these in from file or set them here.
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    pa.set("num_agents", 1)
    pa.set("grid_width", 4)
    pa.set("grid_height", 4)

# Now we create a minimal environment for our agents to act within:
env = ge.GridEnv("Test grid env",
                 pa.get("grid_height"),
                 pa.get("grid_width"),
                 torus=False,
github gcallah / indras_net / models / menu_run.py View on Github external
def run():
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)
    
    # We store menu parameters in a
    # "property" file; this allows us to save
    #  multiple parameter sets, which is important in simulation work.
    #  We can read these in from file or set them here.
    pa = utils.read_props(MODEL_NM)
    if pa is None:
        pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
        pa.set("num_agents", 10)
    
    # Now we create a minimal environment for our agents to act within:
    env = mm.MenuEnv(model_nm=MODEL_NM, props=pa)
    
    # Now we loop creating multiple agents
    #  with numbered names based on the loop variable:
    for i in range(pa.get("num_agents")):
github gcallah / indras_net / schelling / height_run.py View on Github external
def run(prop_dict=None):
    pa = props.PropArgs.create_props(MODEL_NM, prop_dict)
    import indra.utils as utils
    import schelling.height as hm
    (prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

    env = hm.HeightEnv(model_nm=MODEL_NM, props=pa)
    for i in range(pa["num_agents"]):
            env.add_agent(
                hm.HeightAgentEng('Eng agent' + str(i),
                                  START_HEIGHT, START_HEIGHT))
            env.add_agent(
                hm.HeightAgent('agent' + str(i), START_HEIGHT, START_HEIGHT))
    
    return utils.run_model(env, prog_file, results_file)
github gcallah / indras_net / models / basic_run.py View on Github external
def run(prop_dict=None):
    # We need to create props before we import the basic model,
    # as our choice of display_method is dependent on the user_type.

    pa = props.PropArgs.create_props(MODEL_NM, prop_dict)

    import models.basic as bm
    import indra.utils as utils
    (prog_file, log_file, prop_file,
     results_file) = utils.gen_file_names(MODEL_NM)

    # test prop_args as an iterable:
    for prop, val in pa.items():
        print(prop + ": " + str(val))

    # test that props work as a dictionary:
    if "num_agents" in pa:
        print("In is working!")

    # test what pa["num_agents"] is:
    num_agents = pa["num_agents"]
    print("num_agents = " + str(num_agents))

    # make sure we can get props length:
    print("Props length = " + str(len(pa)))
github gcallah / indras_net / models / coop_run.py View on Github external
def run(prop_dict=None):
    (prog_file, log_file,
     prop_file, results_file) = utils.gen_file_names(MODEL_NM)

    global pa

    env = cm.CoopEnv(model_nm=MODEL_NM, props=pa)

    for i in range(pa["num_agents"]):
        env.add_agent(
            cm.CoopAgent('agent' + str(i), 5, 0))

    return utils.run_model(env, prog_file, results_file)
github gcallah / indras_net / models / fashion2_run.py View on Github external
#!/usr/bin/env python3
"""
A fashion model with hipsters and followers.
"""

import indra.utils as utils
import indra.prop_args as props
import fashion2_model as fm

# set up some file names:
MODEL_NM = "fashion2_model"
(prog_file, log_file, prop_file, results_file) = utils.gen_file_names(MODEL_NM)

# We store basic parameters in a "property" file; this allows us to save
#  multiple parameter sets, which is important in simulation work.
#  We can read these in from file or set them here.
pa = utils.read_props(MODEL_NM)
if pa is None:
    pa = props.PropArgs(MODEL_NM, logfile=log_file, props=None)
    pa.set("model", MODEL_NM)
    pa.set("num_followers", 48)
    pa.set("num_hipsters", 16)
    pa.set("grid_width", 16)
    pa.set("grid_height", 16)
    pa.ask("fmax_move", "What is the follower's max move?", int)
    pa.ask("hmax_move", "What is the hipster's max move?", int)
    pa.ask("min_adv_periods", "What are the minimum adverse periods?", int)