Esempio n. 1
0
def run_mother_machine(time=5, out_dir='out'):
    mother_machine_config = get_mother_machine_config()
    experiment = mother_machine_experiment(mother_machine_config)

    # simulate
    settings = {
        'emit_step': 5,
        'total_time': time,
        'return_raw_data': True}
    data = simulate_experiment(experiment, settings)

    # agents plot
    plot_settings = {
        'agents_key': 'agents'}
    plot_agents_multigen(data, plot_settings, out_dir)

    # snapshot plot
    multibody_config = mother_machine_config['environment']['multibody']
    agents = {time: time_data['agents'] for time, time_data in data.items()}
    fields = {time: time_data['fields'] for time, time_data in data.items()}
    snapshot_data = {
        'agents': agents,
        'fields': fields,
        'config': multibody_config}
    plot_config = {
        'out_dir': out_dir,
        'filename': 'snapshots'}

    plot_snapshots(snapshot_data, plot_config)
Esempio n. 2
0
def run_lattice_experiment(agent_config=get_gd_minimal_config,
                           filename='agents'):
    n_agents = 1

    experiment_config = get_lattice_config()
    experiment_config['n_agents'] = n_agents
    experiment_config['agent'] = agent_config()
    experiment = lattice_experiment(experiment_config)

    # simulate
    settings = {'timestep': 1, 'total_time': 200, 'return_raw_data': True}
    data = simulate_experiment(experiment, settings)

    # extract data
    multibody_config = experiment_config['environment']['multibody']
    agents = {time: time_data['agents'] for time, time_data in data.items()}
    fields = {time: time_data['fields'] for time, time_data in data.items()}

    # agents plot
    plot_settings = {'agents_key': 'agents'}
    plot_agents_multigen(data, plot_settings, out_dir, filename)

    # snapshot plot
    data = {'agents': agents, 'fields': fields, 'config': multibody_config}
    plot_config = {'out_dir': out_dir, 'filename': filename + '_snapshots'}
    plot_snapshots(data, plot_config)
def run_experiment():
    experiment = glucose_phosphorylation_experiment()
    settings = {
        'return_raw_data': True,
    }
    data = simulate_experiment(experiment, settings)
    experiment.end()
    return data
Esempio n. 4
0
def run_chemotaxis_experiment(agents_config=None,
                              environment_config=None,
                              initial_state=None,
                              simulation_settings=None,
                              experiment_settings=None):

    if not initial_state:
        initial_state = {}
    if not experiment_settings:
        experiment_settings = {}

    total_time = simulation_settings['total_time']
    emit_step = simulation_settings['emit_step']

    # agents ids
    agent_ids = []
    for config in agents_config:
        number = config['number']
        if 'name' in config:
            name = config['name']
            if number > 1:
                new_agent_ids = [
                    name + '_' + str(num) for num in range(number)
                ]
            else:
                new_agent_ids = [name]
        else:
            new_agent_ids = [str(uuid.uuid1()) for num in range(number)]
        config['ids'] = new_agent_ids
        agent_ids.extend(new_agent_ids)

    initial_agent_body = agent_body_config({
        'bounds': DEFAULT_BOUNDS,
        'agent_ids': agent_ids,
        'location': DEFAULT_AGENT_LOCATION
    })
    initial_state.update(initial_agent_body)

    # make the experiment
    experiment = agent_environment_experiment(agents_config,
                                              environment_config,
                                              initial_state,
                                              experiment_settings)

    # simulate
    settings = {
        'total_time': total_time,
        'emit_step': emit_step,
        'return_raw_data': True
    }
    return simulate_experiment(experiment, settings)
def run_mother_machine(time=10, out_dir='out'):
    config = get_mother_machine_config()

    # configure the experiment
    agent_ids = config.get('agent_ids', ['0'])

    # get the environment composite
    environment = Lattice(config.get('environment', {}))
    composite = environment.generate({})

    # add the agents
    growth_division = GrowDivide(config.get('growth_division', {}))
    for agent_id in agent_ids:
        agent = growth_division.generate({'agent_id': agent_id})
        composite.merge(composite=agent, path=('agents', agent_id))

    experiment = Engine(
        **{
            'processes': composite['processes'],
            'topology': composite['topology'],
            'initial_state': config.get('initial_state', {}),
            'progress_bar': True,
        })

    # simulate
    settings = {'total_time': time, 'return_raw_data': True}
    data = simulate_experiment(experiment, settings)

    # agents plot
    plot_settings = {'agents_key': 'agents'}
    plot_agents_multigen(data, plot_settings, out_dir)

    # snapshot plot
    agents, fields = format_snapshot_data(data)
    bounds = config['environment']['multibody']['bounds']
    plot_snapshots(bounds,
                   agents=agents,
                   fields=fields,
                   n_snapshots=4,
                   out_dir=out_dir,
                   filename=f"mother_machine")

    # make snapshot video
    make_video(
        data,
        bounds,
        plot_type='fields',
        step=100,
        out_dir=out_dir,
        filename=f"mother_machine",
    )
def test_multibody(config={'n_agents': 1}, time=10):
    n_agents = config.get('n_agents', 1)
    agent_ids = [str(agent_id) for agent_id in range(n_agents)]

    body_config = agent_body_config({'agent_ids': agent_ids})
    multibody = Multibody(body_config)

    # initialize agent's boundary state
    initial_agents_state = body_config['agents']
    experiment = process_in_experiment(multibody)
    experiment.state.set_value({'agents': initial_agents_state})

    # run experiment
    settings = {'timestep': 1, 'total_time': time, 'return_raw_data': True}
    return simulate_experiment(experiment, settings)
def run_lattice_experiment(
        agents_config=None,
        environment_config=None,
        initial_state=None,
        initial_agent_state=None,
        experiment_settings=None,
):
    if experiment_settings is None:
        experiment_settings = {}
    if initial_state is None:
        initial_state = {}
    if initial_agent_state is None:
        initial_agent_state = {}

    # agents ids
    agent_ids = []
    for config in agents_config:
        number = config.get('number', 1)
        if 'name' in config:
            name = config['name']
            if number > 1:
                new_agent_ids = [name + '_' + str(num) for num in range(number)]
            else:
                new_agent_ids = [name]
        else:
            new_agent_ids = [str(uuid.uuid1()) for num in range(number)]
        config['ids'] = new_agent_ids
        agent_ids.extend(new_agent_ids)

    # make the experiment
    experiment = agent_environment_experiment(
        agents_config=agents_config,
        environment_config=environment_config,
        initial_state=initial_state,
        initial_agent_state=initial_agent_state,
        settings=experiment_settings,
    )

    # simulate
    return simulate_experiment(
        experiment,
        experiment_settings,
    )
def test_convenience_kinetics(end_time=2520):
    config = get_glc_lct_config()
    kinetic_process = ConvenienceKinetics(config)

    initial_state = kinetic_process.initial_state()
    initial_state['external'] = {'glc__D_e': 1.0, 'lcts_e': 1.0}
    settings = {
        'environment': {
            'volume': 1e-14 * units.L,
            'concentrations': initial_state['external'],
        },
        'timestep': 1,
        'total_time': end_time
    }

    experiment = process_in_experiment(process=kinetic_process,
                                       settings=settings,
                                       initial_state=initial_state)

    return simulate_experiment(experiment, settings)
def test_multibody(n_agents=1, time=10):
    agent_ids = [
        str(agent_id)
        for agent_id in range(n_agents)]
    multibody_config = {
        'agents': agent_body_config({
            'bounds': DEFAULT_BOUNDS,
            'agent_ids': agent_ids})}

    multibody = Multibody(multibody_config)

    # initialize agent's boundary state
    initial_agents_state = multibody_config['agents']
    initial_state = {'agents': initial_agents_state}
    experiment = process_in_experiment(multibody, initial_state=initial_state)

    # run experiment
    settings = {
        'timestep': 1,
        'total_time': time,
        'return_raw_data': True}
    return simulate_experiment(experiment, settings)
Esempio n. 10
0
def test_growth_rate(total_time=1350):
    initial_mass = 100
    growth_rate = 0.0005
    config = {
        'variables': ['mass'],
        'default_growth_rate': growth_rate,
        'time_step': 2,
    }

    growth_rate_process = GrowthRate(config)
    initial_state = {'variables': {'mass': initial_mass}}
    experiment = process_in_experiment(
        growth_rate_process,
        initial_state=initial_state)
    output = simulate_experiment(experiment, {'total_time': total_time})

    # asserts
    final_mass = output['variables']['mass'][-1]
    expected_mass = initial_mass * np.exp(growth_rate * total_time)
    decimal_precision = 11
    assert abs(expected_mass - final_mass) < \
           1.5 * 10 ** (-decimal_precision)
    return output
def run_experiment(runtime=2400,
                   n_agents=2,
                   start_locations=None,
                   growth_rate=0.000275):
    '''Run a Colony Metrics Experiment

    Arguments:
        runtime (int): Experiment duration
        n_agents (int): Number of agents to create at the start
        start_locations (list): List of initial agent coordinates. If
            you do not provide enough locations, the remaining locations
            will be random. Coordinates range from 0 to 1 and represent
            fractions of environment bounds.

    Returns:
        Simulation data as :term:`raw data`.
    '''
    agent_config = agents_library['growth_division_minimal']
    agent_config['config']['growth_rate_noise'] = 0
    agent_config['growth_rate'] = growth_rate

    experiment_config = get_lattice_with_metrics_config()
    experiment_config.update({
        'n_agents': n_agents,
        'agent': agent_config,
        'locations': start_locations,
    })
    experiment = colony_metrics_experiment(experiment_config)

    # simulate
    settings = {
        'emit_step': DEFAULT_EMIT_STEP,
        'total_time': runtime,
        'return_raw_data': True,
    }
    return simulate_experiment(experiment, settings), experiment_config