Simulation
- class pythonabm.simulation.Simulation
Bases:
ABCThis class defines the necessary behavior for any Simulation subclass.
- add_agents(number, agent_type=None)
Adds number of agents to the simulation.
- Parameters:
number_agents (int) – The current number of agents in the simulation.
- agent_array(dtype=<class 'float'>, vector=None, initial=None)
Generate NumPy array that is used to hold agent values. This allows one to specify initial conditions based on agent types.
- agent_graph()
Create a graph correct number of agents.
- assign_bins(max_agents, distance)
Generalizes agent locations to a bins within lattice imposed on the agent space, used for accelerating neighbor searches.
- create_video()
Write all of the step images from a simulation to a video file in the main simulation directory.
- data()
Adds a new line to a running CSV holding data about the simulation such as memory, step time, number of agents and method profiling.
- end()
Specify any methods to be called after all the simulation steps have run. Can be overridden.
- full_setup()
In addition to how the setup() method has been defined, this adds further hidden functionality.
- get_neighbors(graph, distance, clear=True)
Finds all neighbors, within fixed radius, for each each agent.
- indicate_arrays(*args)
Adds agent array names to list to indicate which instance variables are agent arrays.
- Parameters:
args (str) – A series of instance variable names to indicate agent arrays.
- indicate_graphs(*args)
Adds graph names to list to indicate which instance variables are agent graphs.
- Parameters:
args (str) – A series of instance variable names to indicate agent graphs.
- info()
Prints out info about the simulation.
- classmethod make(name, output_dir)
Creates a new brand new simulation and partially sets it up for running within a separate script. Would need to call full_setup() and run_simulation() on sim object.
- mark_to_hatch(index)
Mark the corresponding index of the array with True to indicate that the agent should hatch a new agent.
- Parameters:
index (int) – The unique index of an agent.
- mark_to_remove(index)
Mark the corresponding index of the array with True to indicate that the agent should be removed.
- Parameters:
index (int) – The unique index of an agent.
- random_vector()
Computes a random vector on the unit sphere centered at the origin.
- run_simulation()
Defines how a simulation is run and what code is run after the simulation.
- set_paths(output_dir)
Updates simulation paths to various output directories.
- Parameters:
output_dir (str) – Simulation output directory.
- abstract setup()
Initialize the simulation prior to running the steps. Must be overridden.
- classmethod simulation_mode_0(name, output_dir)
Creates a new brand new simulation and runs it through all defined steps.
- static simulation_mode_1(name, output_dir)
Opens an existing simulation and runs it for a newly specified number of steps.
- classmethod simulation_mode_2(name, output_dir)
Turns existing simulation images into a video.
- static simulation_mode_3(name, output_dir)
Archives existing simulation to a ZIP file.
- classmethod start(output_dir)
Configures/runs the model based on the specified simulation mode.
- Parameters:
output_dir (str) – Path to simulation output directory.
- abstract step()
Specify which methods are called during the simulation step. Must be overridden.
- step_image(background=(0, 0, 0), origin_bottom=True)
Creates an image of the simulation space.
- step_image_3d()
Creates an image of the 3D simulation space.
- step_values(arrays=None)
Outputs a CSV file containing values from the agent arrays with each row corresponding to a particular agent index.
- Parameters:
arrays (list) – A list of strings of agent values to record.
- temp()
Pickle the current state of the simulation which can be used to continue a past simulation without losing information.
- update_populations()
Adds/removes agents to/from the simulation by adding/removing indices from the cell arrays and any graphs.