vivarium.core.composition module

class vivarium.core.composition.TestSimulateProcess[source]

Bases: object

test_process_deletion()[source]

Check that processes are successfully deleted

class vivarium.core.composition.ToyCompartment(config)[source]

Bases: vivarium.core.process.Generator

a toy compartment for testing

generate_processes(config)[source]
generate_topology(config)[source]
class vivarium.core.composition.ToyDeath(initial_parameters={})[source]

Bases: vivarium.core.process.Process

name = 'toy_death'
next_update(timestep, states)[source]
ports_schema()[source]
class vivarium.core.composition.ToyDeriveVolume(initial_parameters={})[source]

Bases: vivarium.core.process.Deriver

name = 'toy_derive_volume'
next_update(timestep, states)[source]
ports_schema()[source]
class vivarium.core.composition.ToyLinearGrowthDeathProcess(initial_parameters={})[source]

Bases: vivarium.core.process.Process

GROWTH_RATE = 1.0
THRESHOLD = 6.0
name = 'toy_linear_growth_death'
next_update(timestep, states)[source]
ports_schema()[source]
class vivarium.core.composition.ToyMetabolism(initial_parameters={})[source]

Bases: vivarium.core.process.Process

name = 'toy_metabolism'
next_update(timestep, states)[source]
ports_schema()[source]
class vivarium.core.composition.ToyTransport(initial_parameters={})[source]

Bases: vivarium.core.process.Process

name = 'toy_transport'
next_update(timestep, states)[source]
ports_schema()[source]
vivarium.core.composition.agent_environment_experiment(agents_config=None, environment_config=None, initial_state=None, initial_agent_state=None, settings=None, invoke=None)[source]

Make an experiment with agents placed in an environment under an agents store. :param * agents_config: the configuration for the agents :param * environment_config: the configuration for the environment :param * initial_state: the initial state for the hierarchy, with environment at the

top level.

Parameters
  • initial_agent_state (*) – the initial_state for agents, set under each agent_id.

  • settings (*) – settings include emitter and agent_names.

  • invoke (*) – is the invoke object for calling updates.

vivarium.core.composition.agent_timeseries_from_data(data, agents_key='cells')[source]
vivarium.core.composition.assert_timeseries_close(timeseries1, timeseries2, keys=None, default_tolerance=0.9999999999, tolerances={}, required_frac_checked=0.9)[source]

Check that two timeseries are similar.

Ensures that each pair of data points between the two timeseries are within a tolerance of each other, after filtering out timepoints not common to both timeseries.

Parameters
  • timeseries1 – One timeseries. Must be flattened and include times under the ‘time’ key.

  • timeseries2 – The other timeseries. Same requirements as timeseries1.

  • keys – Keys of the timeseries whose values will be checked for correlation. If not specified, all keys present in both timeseries are used.

  • default_tolerance – The tolerance to use when not specified in tolerances.

  • tolerances – Dictionary of key-value pairs where the key is a key in both timeseries and the value is the tolerance to use when checking that key.

  • required_frac_checked – The required fraction of timepoints in a timeseries that must be checked. If this requirement is not satisfied, which might occur if the two timeseries share few timepoints, the test wll fail.

Raises

AssertionError – If a pair of data points have a difference strictly above the tolerance threshold or if too few timepoints are common to both timeseries.

vivarium.core.composition.assert_timeseries_correlated(timeseries1, timeseries2, keys=None, default_threshold=0.9999999999, thresholds={}, required_frac_checked=0.9)[source]

Check that two timeseries are correlated.

Uses a Pearson correlation coefficient. Only the data from timepoints common to both timeseries are compared.

Parameters
  • timeseries1 – One timeseries. Must be flattened and include times under the ‘time’ key.

  • timeseries2 – The other timeseries. Same requirements as timeseries1.

  • keys – Keys of the timeseries whose values will be checked for correlation. If not specified, all keys present in both timeseries are used.

  • default_threshold – The threshold correlation coefficient to use when a threshold is not specified in thresholds.

  • thresholds – Dictionary of key-value pairs where the key is a key in both timeseries and the value is the threshold correlation coefficient to use when checking that key

  • required_frac_checked – The required fraction of timepoints in a timeseries that must be checked. If this requirement is not satisfied, which might occur if the two timeseries share few timepoints, the test wll fail. This is also the fraction of timepoints for each variable that must be non-nan in both timeseries. Note that the denominator of this fraction is the number of shared timepoints that are non-nan in either of the timeseries.

Raises

AssertionError – If a correlation is strictly below the threshold or if too few timepoints are common to both timeseries.

vivarium.core.composition.compartment_in_experiment(compartment, settings={})[source]
vivarium.core.composition.load_timeseries(path_to_csv)[source]

Load a timeseries saved as a CSV using save_timeseries.

The timeseries is returned in flattened form.

vivarium.core.composition.make_agents(agent_ids, compartment, config=None)[source]
vivarium.core.composition.make_experiment_from_compartment_dicts(environment_dict, agents_dict, emitter_dict, initial_state)[source]
vivarium.core.composition.make_experiment_from_configs(agents_config={}, environment_config={}, initial_state={}, settings={})[source]
vivarium.core.composition.order_list_of_paths(path_list)[source]
vivarium.core.composition.plot_agents_multigen(data, settings={}, out_dir='out', filename='agents')[source]

Plot multi-agent simulation output, with all agents data combined for every corresponding path in their stores. Arguments:

data (dict): This is raw_data obtained from simulation output
settings (dict): Accepts the following keys:

    * **max_rows** (:py:class:`int`): ports with more states
      than this number of states get wrapped into a new column
    * **remove_zeros** (:py:class:`bool`): if True, timeseries
      with all zeros get removed
    * **remove_flat** (:py:class:`bool`): if True, timeseries
      with all the same value get removed
    * **skip_paths** (:py:class:`list`): entire path, including subpaths
      that won't be plotted
    * **include_paths** (:py:class:`list`): list of full paths
      to include. Overridden by skip_paths.
    * **titles_map** (:py:class:`dict`): Map from path tuples to
      strings to use as the figure titles for each path's plot.
      If not provided, the path is shown as the title.
    * **ylabels_map** (:py:class:`dict`): Map from path tuples to
      strings to use as the y-axis labels for each path's plot.
      If not specified, no y-axis label is used.

TODO – add legend with agent color

vivarium.core.composition.plot_compartment_topology(compartment, settings, out_dir='out', filename='topology')[source]
Make a plot of the topology
  • compartment: a compartment

vivarium.core.composition.plot_simulation_output(timeseries_raw, settings={}, out_dir='out', filename='simulation')[source]

Plot simulation output, with rows organized into separate columns.

Arguments::

timeseries (dict): This can be obtained from simulation output with convert_to_timeseries() settings (dict): Accepts the following keys:

  • max_rows (int): ports with more states than this number of states get wrapped into a new column

  • remove_zeros (bool): if True, timeseries with all zeros get removed

  • remove_flat (bool): if True, timeseries with all the same value get removed

  • remove_first_timestep (bool): if True, skips the first timestep

  • skip_ports (list): entire ports that won’t be plotted

  • show_state (list): with [('port_id', 'state_id')] for all states that will be highlighted, even if they are otherwise to be removed

vivarium.core.composition.process_in_compartment(process, topology={})[source]

put a lone process in a compartment

vivarium.core.composition.process_in_experiment(process, settings={})[source]
vivarium.core.composition.save_flat_timeseries(timeseries, out_dir='out')[source]

Save a timeseries as a CSV in out_dir

vivarium.core.composition.save_timeseries(timeseries, out_dir='out')[source]
vivarium.core.composition.set_axes(ax, show_xaxis=False)[source]
vivarium.core.composition.simulate_compartment_in_experiment(compartment, settings={})[source]
vivarium.core.composition.simulate_experiment(experiment, settings={})[source]
run an experiment simulation

Requires: - a configured experiment

Returns

  • a timeseries of variables from all ports.

  • if ‘return_raw_data’ is True, it returns the raw data instead

vivarium.core.composition.simulate_process(process, settings={})[source]
vivarium.core.composition.simulate_process_in_experiment(process, settings={})[source]
vivarium.core.composition.test_compartment()[source]
vivarium.core.composition.timeseries_to_ndarrays(timeseries, keys=None)[source]

After filtering by keys, convert timeseries to dict of ndarrays

Returns

Mapping from timeseries variables to an ndarray of the

variable values.

Return type

dict