Backend

pythonabm.backend.get_neighbors_gpu(locations, bin_locations, bins, bins_help, distance, edges, if_edge, edge_count, max_neighbors)

See get_neighbors_gpu for parameter descriptions.

pythonabm.backend.cuda_magnitude(vector_1, vector_2)

Returns magnitude of vector between inputted vectors.

class pythonabm.backend.Graph(*args, **kwargs)

Bases: Graph

This class extends the Graph class from iGraph adding instance variables for the bin/bucket sort algorithm.

num_neighbors(index)

Returns the number of neighbors for the index.

Parameters:

index (int) – Index of agent in graph.

Returns:

Number of neighbors for agent at index

pythonabm.backend.assign_bins_jit(number_agents, bin_locations, bins, bins_help, max_agents)

This just-in-time compiled method performs the actual calculations for the assign_bins() method.

Parameters:
  • number_agents (int) – The current number of agents in the simulation.

  • locations (numpy.ndarray) – The locations of the agents.

  • bin_locations (numpy.ndarray) – Discretized agent locations for bin sorting.

  • bins (numpy.ndarray) – Holds the agent based on discretized locations.

  • bins_help (numpy.ndarray) – Stores the number of agents in each bin.

  • max_agents (int) – The maximum number of agents that can be stored in bin.

pythonabm.backend.check_direct(path)

Makes sure directory exists, if not make that directory

Parameters:

path (str) – The path to a directory.

pythonabm.backend.check_existing(name, output_path, new_simulation=True)

Based on the mode, checks to see if an existing simulation in the output path has the same name.

Parameters:
  • name (str) – The name of the simulation.

  • output_path (str) – Path to simulation output directory.

  • new_simulation (bool) – Whether this is a new simulation or not.

pythonabm.backend.check_output_dir(output_dir)

Checks that the output directory exists.

Parameters:

output_dir (str) – Path to ABM output directory.

Returns:

A correct output path

pythonabm.backend.commandline_param(flag, dtype)

Returns the value for option passed at the command line.

Parameters:
  • flag (str) – The command line flag.

  • dtype (type) – Data type for the parameter.

Returns:

Parameter value

Raises:

Exception

pythonabm.backend.empty_array(shape, dtype)

Create empty array based on data type.

Parameters:
  • shape (int or tuple) – Shape of the empty array.

  • dtype (type) – Data type of the array.

Returns:

An empty NumPy array

pythonabm.backend.get_end_step()

If using the continuation mode, get the last step number for the simulation.

Returns:

The simulation end step number

pythonabm.backend.get_neighbors_cpu(number_agents, locations, bin_locations, bins, bins_help, distance, edges, if_edge, edge_count, max_neighbors)

This just-in-time compiled method performs the actual calculations for the get_neighbors() method.

Parameters:
  • number_agents (int) – The current number of agents in the simulation.

  • locations (numpy.ndarray) – The locations of the agents.

  • bin_locations (numpy.ndarray) – Discretized agent locations for bin sorting.

  • bins (numpy.ndarray) – Holds the agent based on discretized locations.

  • bins_help (numpy.ndarray) – Stores the number of agents in each bin.

  • distance (float) – The radius of each agent’s neighborhood.

  • edges (numpy.ndarray) – Stores the graph edge connections between neighboring agents.

  • if_edge (numpy.ndarray) – Whether edges are a non-zero values.

  • edge_count (numpy.ndarray) – The number of neighbors per agent.

  • max_neighbors (int) – The maximum number of agents that can be stored with these arrays.

Returns:

The edge values and the number of edges (neighbors) per agent.

pythonabm.backend.normal_vector(vector)

Normalizes the vector.

Parameters:

vector (numpy.ndarray) – Vector to be normalized.

Returns:

A normalized vector

pythonabm.backend.progress_bar(progress, maximum)

Makes a progress bar to show progress of output.

Parameters:
  • progress (int) – How close the process is to the maximum.

  • maximum (int) – Maximum value for progress.

pythonabm.backend.record_time(function)

This is a decorator used to time individual methods.

Parameters:

function (func) – A function to be decorated.

Returns:

A wrapped function

pythonabm.backend.starting_params()

Returns the name and mode for the simulation either from the commandline or a text-based UI.

Returns:

The simulation name and mode

pythonabm.backend.template_params(path)

Return parameters as dict from a YAML template file.