backend package

Submodules

backend.backend module

Backend for AGE-ABM Visual Interface @Author Max Hall @Co-Authors Meghan Ireland and Matthew Fleischman

class backend.backend.ModelEnv(name: str = 'Custom', exist_proj: str = None)[source]

Bases: object

This is a base class which will store all the data relating to an instance of creating a new model using the GUI this includes storing dictionaries containing imports, components, agents, systems and data collection systems classes as well as a model details class

get_list_imports()[source]

Gets a list of all imports added to the model.

Returns

Attributelist[str]
Returns a list of imports names.
get_list_components()[source]

Gets a list of all components added to the model.

Returns

Attributelist[str]
Returns a list of components names.
get_list_attributes(relevent_component: str)[source]

Gets a list of attributes which a relevent_component has.

Parameters

relevent_componentstr

The relevent_component having the attributes names.

Returns

Attributelist[str]
Returns a list of that components attributes names.
get_list_agents()[source]

Gets a list of all agents added to the model.

Returns

Attributelist[str]
Returns a list of agents names
get_list_systems()[source]

Gets a list of all systems added to the model.

Returns

Attributelist[str]
Returns a list of systems names
get_list_gen_attributes(relevent_system: str, relevent_generator: str)[source]

Gets a list of attributes which a relevent_generator has.

Parameters

relevent_systemstr

The relevent_system having the generators names.

relevent_generatorstr

The relevent_generator having the attributes names.

Returns

Attributeslist[str]
Returns a list of that generators attributes names
get_list_generators(relevent_system: str)[source]

Gets a list of generators which a relevent_system has.

Parameters

relevent_systemstr

The relevent_system having the generators names.

Returns

Generatorslist[str]
Returns a list of that components attributes
get_list_agents_of_interest()[source]

Gets a list of all agents_of_interest added to the model.

Returns

Attributelist[str]
Returns a list of agents_of_interest names
add_import(library: str, nickname: str, import_type: str = '*', list_of_methods: list[str] = None)[source]

Stores the newly created import into the models imports dictionary.

Parameters

librarystr

The library

library: str

The nickname for the library being imported

import_typestr

“as” implies it has an alias, “from” implies it is a list of things being imported from the library, “*” imports everything from the library and is the default

list_of_methodslist[str], Optional

If import_type is “from”, then this is the list of things to be imported from the library

Returns

error termint
Returns 0 on success
Returns 1 if library import already exist
Returns 2 if invalid import_type used
Returns 3 if type is from and no methods selected
Returns 4 if nickname already in use
edit_import(library: str, nickname: str = None, import_type: str = None, list_of_methods: list[str] = None)[source]

Edits the provided named import into the models imports dictionary. Must specify what import you would like to edit.

Parameters

librarystr

The library

nickname: str, Optional

The nickname for the library being imported

import_typestr, Optional

“as” implies it has an alias, “from” implies it is a list of things being imported from the library, “*” imports everything from the library and is the default

list_of_methodslist[str], Optional

If import_type is “from”, then this is the list of things to be imported from the library

Returns

error termint
Returns 0 on success
Returns 1 if library import doesn’t already exist
Returns 2 if nickname already in use
Returns 3 if invalid import_type used
Returns 4 if type is from and no methods selected
get_import(library: str)[source]

Gets the requested import from the models imports dictionary.

Parameters

librarystr

The import’s library.

Returns

libraryImportDetails
Returns an ImportDetails object containing the details from the requested import.
Returns None if library import doesn’t already exist.
remove_import(library: str)[source]

Removes a set import from the models imports dictionary.

Parameters

librarystr

The library of the import to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if library import doesn’t already exist
add_attribute(relevent_component: str, name: str, type_attr: str, define_level: str, default_value: int = None)[source]

Stores the newly created attribute into the models attributes dictionary.

Parameters

relevent_componentstr

The relevent_component having the attributes name.

namestr

The attribute’s name.

type_attr: str [“int”, “float”, “bool”]

The primitive type expected.

default_valueint, Optional

If there is a default value for the attribute, else it defaults to ‘None’

define_levelstr, Optional [‘comp_lvl’, ‘agent_lvl’, ‘model_lvl’]

If there is a user defined level, else it defaults to ‘None’

Returns

error termint
Returns 0 on success
Returns 1 if attribute name already exists
Returns 2 if invalid characters used in attribute name
Returns 3 if type attribute not valid
Returns 4 if no default value provided
Returns 5 if invalid define level used
add_agent_lvl_default_value(agent_name: str, component_name: str, attribute_name: str, default_value: str)[source]

Edits the provided default value for the named attribute into the models attribute’s default value dictionary.

Parameters

agent_namestr

The agent_name having the attribute_name.

component_namestr

The component_name having the attribute_name.

attribute_namestr

The attribute_name having the default_value.

default_valueint

The default value code for the attribute.

Returns

error termint
Returns 0 on success
Returns 1 if name doesn’t already exists
Returns 2 if invalid characters used in name
Returns 3 if agent level define level not used
edit_attribute(relevent_component: str, name: str, type_attr: str = None, define_level: str = None, default_value: int = None)[source]

Edits the provided named attribute into the models attributes dictionary. Must specify what attribute you would like to edit.

Parameters

relevent_componentstr

The relevent_component having the attributes name.

namestr

The attribute’s name.

type_attr: str, Optional

The primitive type expected.

default_valueint, Optional

If there is a default value for the attribute.

define_levelstr, Optional [‘comp_lvl’, ‘agent_lvl’, ‘model_lvl’]

If there is a user defined level, else it defaults to ‘None’.

Returns

error termint
Returns 0 on success
Returns 1 if attribute name doesn’t already exists
Returns 2 if invalid characters used in attribute name
Returns 3 if invalid attribute type
Returns 4 if invalid define level
Returns 5 if define level is component, but no default value given
get_attribute(relevent_component: str, name: str)[source]

Gets the requested attribute from the models attributes dictionary.

Parameters

relevent_componentstr

The relevent_component having the attributes name.

namestr

The attribute’s name.

Returns

Attributedict
Returns a dictionary containing the details from the requested attribute.
Returns None if attribute doesn’t already exist.
remove_attribute(relevent_component: str, name: str)[source]

Removes a set attribute from the models attributes dictionary.

Parameters

relevent_componentstr

The relevent_component having the attributes name.

namestr

The name of the attribute to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if attribute name doesn’t already exists
Returns 2 if invalid characters used in attribute name
add_component(name: str, description: str, is_class_component: bool = False, attributes: dict = None)[source]

Stores the newly created component into the models components dictionary.

Parameters

namestr

The component’s name.

descriptionstr

A description of the component.

is_class_componentbool, Optional

User can specify if this is a class component or not.

attributesdict

User provided attributes of the components.

Returns

error termint
Returns 0 on success
Returns 1 if component name already exists
Returns 2 if invalid characters used in component name
edit_component(name: str, description: str = None, is_class_component: bool = None)[source]

Edits the provided named component into the models components dictionary.

Parameters

namestr

The component’s name.

descriptionstr, Optional

A description of the component.

attributesdict, Optional

User provided attributes for the component.

is_class_componentbool, Optional

Tells the viewer if the component is a class component.

Returns

error termint
Returns 0 on success
Returns 1 if component name doesn’t already exists
Returns 2 if invalid characters used in component name
get_component(name: str)[source]

Gets the requested component from the models components dictionary.

Parameters

namestr

The component’s name.

Returns

componentComponent
Returns the component object correlating to the given name.
Returns None if name doesn’t correspond to existing component
remove_component(name: str)[source]

Removes a set component from the models component dictionary.

Parameters

namestr

The name of the component to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if component name doesn’t already exists
Returns 2 if invalid characters used in component name
add_agent(name: str, description: str, given_components: list[str], init_coordinates: list[str] = None)[source]

Stores the newly created agent into the models agents dictionary. Gets parameters from components

Parameters

namestr

The agent’s name.

descriptionstr

A description of the agent.

given_componentsstr[]

User provided attributes of the agents.

Returns

error termint
Returns 0 on success
Returns 1 if agent name already exists
Returns 2 if invalid characters used in agent name
Returns 3 if invalid component name supplied
Returns 4 if gridworld and no initial co-ordinates supplied
edit_agent(name: str, description: str = None, given_components: list[str] = None, init_coordinates: list[str] = None)[source]

Edits the provided named agent into the models agents dictionary.

Parameters

namestr

The agent’s name.

descriptionstr, Optional

A description of the agent.

given_componentslist[str], Optional

User provided components for the agent.

Returns

error termint
Returns 0 on success
Returns 1 if agent name doesn’t already exists
Returns 2 if invalid characters used in agent name
Returns 3 if invalid component name given
Returns 4 if gridworld and no initial co-ordinates supplied
get_agent(name: str)[source]

Gets the requested agent from the models agents dictionary.

Parameters

namestr

The agent’s name.

Returns

agentAgent
Returns an Agent object corresponding to the given name.
Returns None if no match.
remove_agent(name: str)[source]

Removes a set agent from the models agents dictionary.

Parameters

namestr

The name of the agent to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if agent name doesn’t already exists
Returns 2 if invalid characters used in agent name
add_system(name: str, description: str, start: int = None, end: int = None, frequency: int = None, generators: dict = None)[source]

Stores the newly created system into the models systems dictionary.

Parameters

namestr

The system’s name.

descriptionstr

A description of the system.

startint, Optional

The iteration that the system must start on

endint, Optional

The iteration that the end must start on

frequencyint, Optional

Per how many iterations must the system execute

generatorsdict[Generator], Optional

Rather use add, edit, get, remove generator

Returns

error termint
Returns 0 on success
Returns 1 if system name already exists
Returns 2 if invalid characters used in system name
edit_system(name: str, description: str = None, execute_function_body: str = None, start: int = None, end: int = None, frequency: int = None, generators: dict = None)[source]

Edits the provided named system into the models system dictionary.

Parameters

namestr

The system’s name.

descriptionstr, Optional

A description of the system.

execute_function_bodystr, Optional

User provided execute function for the system.

startint, Optional

The iteration that the system must start on.

endint, Optional

The iteration that the end must start on.

frequencyint, Optional

Per how many iterations must the system execute.

Returns

error termint
Returns 0 on success
Returns 1 if system name doesn’t already exists
Returns 2 if invalid characters used in system name
get_system(name: str)[source]

Gets the requested system from the models systems dictionary.

Parameters

namestr

The system’s name.

Returns

systemSystem
Returns a System object which matches the provided name.
Returns None if no match.
remove_system(name: str)[source]

Removes a set system from the models system dictionary.

Parameters

namestr

The name of the system to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if system name doesn’t already exists
Returns 2 if invalid characters used in system name
add_gen_attribute(relevent_system: str, relevent_generator: str, name: str, type_attr: str)[source]

Stores the newly created attribute into the system generators attributes dictionary.

Parameters

relevent_systemstr

The relevent_system having the relevent_generator.

relevent_componentstr

The relevent_generator having the attribute.

namestr

The attribute’s name.

type_attrstr [“int”, “bool”, “float”]

The type of the attribute

Returns

error termint
Returns 0 on success
Returns 1 if names already exists
Returns 2 if invalid characters used in the names
Returns 3 if invalid type_attr
get_gen_attribute(relevent_system: str, relevent_generator: str, name: str)[source]

Gets the requested attribute from the system generators attributes dictionary.

Parameters

relevent_systemstr

The relevent_system having the relevent_generator.

relevent_componentstr

The relevent_generator having the attribute.

namestr

The attribute’s name.

Returns

gen_attributeAttribute
Returns the Attribute object corresponding the the provided names.
Returns None if no match.
remove_gen_attribute(relevent_system: str, relevent_generator: str, name: str)[source]

Removes a set attribute from the generators attribute dictionary of a specific system.

Parameters

namestr

The name of the system to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if names don’t already exists
Returns 2 if invalid characters used in names
add_generator(relevent_system: str, name: str, description: str, nickname: str = None, return_value: str = None, attributes: dict = None)[source]

Stores the newly created generator into the systems generators dictionary.

Parameters

relevent_systemstr

The relevent_system having the generator name.

namestr

The generator’s name.

description: str

A description of the generator.

nicknamestr, Optional

The nickname for cells using this type.

return_valuestr, Optional

The code used to generate the return value.

attributesdict, Optional

User provided attributes of the generator.

Returns

error termint
Returns 0 on success
Returns 1 if names already exists
Returns 2 if invalid characters used in the names
Returns 3 if nickname already in use in this system
edit_generator(relevent_system: str, name: str, description: str = None, nickname: str = None, return_value: str = None)[source]

Stores the newly created generator into the systems generators dictionary.

Parameters

relevent_systemstr

The relevent_system having the generator name.

namestr

The generator’s name.

description: str, Optional

A description of the generator.

nicknamestr, Optional

The nickname for cells using this type.

return_valuestr, Optional

The code used to generate the return value.

attributesdict, Optional

User provided attributes of the generator.

Returns

error termint
Returns 0 on success
Returns 1 if names don’t already exists
Returns 2 if invalid characters used in the names
Returns 3 if nickname already in use in this system
get_generator(relevent_system: str, name: str)[source]

Gets the requested generator from the systems generators dictionary.

Parameters

relevent_systemstr

Name of system the generator belongs to.

namestr

Name of generator.

Returns

generatorGenerator
Returns the Generator object matching the provided names
Returns None if no Match
remove_generator(relevent_system: str, name: str)[source]

Removes a set generator from the systems generators dictionary.

Parameters

relevent_systemstr

Name of system the generator belongs to.

namestr

Name of generator.

Returns

error termint
Returns 0 on success
Returns 1 if names don’t already exists
Returns 2 if invalid characters used in the names
edit_model_details(name: str = None, description: str = None, gridworld: bool = None, sim_length: int = None, sim_seed: int = None)[source]

Stores the provided data about the model.

Parameters

namestr, Optional

Changes the model’s name.

descriptionstr, Optional

Changes the description of the model.

initial_parametersdict, Optional

Store the initial parameters the user wants for the model.

sim_lengthint, Optional

Changes the number of iterations of the model will be executed.

sim_seedint, Optional

Changes the seed for the random generator for the model.

Returns

error termint
Returns 0 on success
Returns 1 if same name as before
Returns 2 on invalid name
get_model_details()[source]

Gets the requested system from the models systems dictionary.

Returns

model_detailsModelDetails
Returns an Model Details Class.
add_execute(parent_system: str, execute_function_body: str)[source]

Stores an execute function into the respective parent system models system dictionary.

Parameters

parent_systemstr

The parent system’s name.

execute_function_bodystr

User provided execute function for the system.

Returns

error termint
Returns 0 on success
Returns 1 if name doesn’t already exists
get_execute(parent_system: str)[source]

Gets the execute function from the respective parent system models system dictionary.

Parameters

parent_systemstr

The parent system’s name.

execute_function_bodystr

User provided execute function for the system.

Returns

executestr
Returns execute function body.
Returns None if system name is invalid or doesn’t match.
add_agent_of_interest(name: str, comp_of_interest: list[str] = None, count: bool = False, position: bool = False, individual: bool = False, mean_val: bool = False, median_val: bool = False, total_val: bool = False, max_val: bool = False, min_val: bool = False, variance: bool = False, std_dev: bool = False)[source]

Adds the agent of interest to the agents of interest dictionary.

Parameters

namestr

The name of the agent of interest to be added.

comp_of_interestlist[str], Optional

The list of desired components for the agent of interest.

countbool, Optional

Specifies if the number of agents must be collected.

positionbool, Optional

Specifies is the user wants to keep the postions of the agent ids

individualbool, Optional

Specifies if component values must be collected per individual agent id.

mean_valbool, Optional

Specifies if the mean of the component values for the agent type must be collected.

median_valbool, Optional

Specifies if the median of the component values for the agent type must be collected.

total_valbool, Optional

Specifies if the total of the component values for the agent type must be collected.

max_valbool, Optional

Specifies if the maximum of the component values for the agent type must be collected.

min_valbool, Optional

Specifies if the minimum of the component values for the agent type must be collected.

variancebool, Optional

Specifies if the variance of the component values for the agent type must be collected.

std_devbool, Optional

Specifies if the standard deviation of the component values for the agent type must be collected.

Returns

error termint
Returns 0 on success
Returns 1 if name error
Returns 2 if invalid characters used in the name
Returns 3 if no components of interest provided
get_list_valid_agents(agent_of_focus: str, comp_of_focus: str = None, count: bool = False)[source]

Gets a list of all valid compatible agents_of_interest in the model, needed for visualisation.

Parameters

agent_of_focusstr

The main agent which is being visualised

comp_of_focusstr, Optional

The main component which is being visualised, Defaults to None for if count True

countbool, Optional

Defaults to False, relates to if just checking for count as no comp_of_focus needed

Returns

Agents_of_Interestlist[str]
Returns a list of compatible agents of interest
Returns an empty list if invalid names provided or no valid agents of interest
get_list_valid_plot_data_types(agents_of_focus: list[str])[source]

Gets a list of all valid plot_data_types needed for visualisation.

Parameters

agents_of_focusstr

The agents being evaluated

Returns

plot_data_typeslist[str]
Returns a list of compatible plot_data_types.
Returns an empty list if invalid agent names or no possible plot_data_types.
get_agent_of_interest(name: str)[source]

Gets the requested agent of interest object from the agents of interest dictionary.

Parameters

namestr

The agent of interest’s name.

Returns

agent_of_interest[name]AgentOfInterest
Returns the agent of interest object to return.
remove_agent_of_interest(name: str)[source]

Removes the provided data collection system from the data collection dictionary.

Parameters

namestr

The name of the agent of interest to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if name doesn’t already exists
Returns 2 if invalid characters used in the name
create_model(file_name: str, visualise_model=False)[source]

Generates a python file(s) necessary for the model to run.

Parameters

file_namestr

The file_name of the model to be written to.

visualise_modelbool

The specifies if the main file will be used for visualisation or not.

Returns

error termint
Returns 0 on success
Returns 1 if file generation fails
store_model()[source]

Stores the current model as a json file which allows us to reload in an existing project.

Returns

error termint
Returns 0 on success
Returns 1 if model storing fails

backend.backend_classes module

Backend Classes for AGE-ABM Visual Interface @Author Max Hall @Co-Authors Meghan Ireland and Matthew Fleischman

class backend.backend_classes.ParentAgent(description: str)[source]

Bases: object

This acts as a super class which all the ‘agents’ of the agent based system can inherit from allowing them to store a description of the ‘agent’ as this the only common attribute

edit_description(description: str)[source]

Edits the description of whatever class this represents.

Parameters

descriptionstr

A description of the created class.

get_description()[source]

Gets agents description as string. Parameters ———-

Returns

descriptionstr
Returns an agents description.
class backend.backend_classes.ImportDetails(nickname: str, import_type: str, list_of_methods: list[str] = None)[source]

Bases: object

This class stores details about an import, it stores the libraries nickname, import type and if required, a list of the methods to be imported

edit_nickname(nickname: str)[source]

Edits the nickname of the import.

Parameters

nicknamestr

The new nickname for the import.

edit_import_type(import_type: str)[source]

Edits the import_type of the import.

Parameters

import_typestr

The new import_type for the import.

edit_list_of_methods(list_of_methods: list[str])[source]

Edits the list of methods of the import.

Parameters

list_of_methodslist[str]

The new list of methods for the import.

get_nickname()[source]

Gets imports nickname as string.

Returns

nicknamestr
Returns an imports nickname.
get_import_type()[source]

Gets imports import_type as string.

Returns

import_typestr
Returns an imports import_type.
get_list_of_methods()[source]

Gets imports list_of_methods as list.

Returns

list_of_methodslist[str]
Returns an imports list of methods.
class backend.backend_classes.Attribute(type_attr: str, define_level: str, default_value: int = None)[source]

Bases: ParentAgent

This class stores details about an attribute, it inherits the ParentAgent class and additionally stores the data type the attribute is, if it’s user defined as well as a default value

edit_type_attr(type_attr: str)[source]

Edits the type_attr of the attribute.

Parameters

type_attrstr

The new type_attr for the attribute.

edit_default_value(default_value: int)[source]

Edits the default_value of the attribute.

Parameters

default_valueint

The new default_value value for the attribute.

edit_define_level(define_level: str)[source]

Edits the define_level of the attribute.

Parameters

define_levelstr

The new define_level value for the attribute.

get_type_attr()[source]

Gets attributes type_attr as string. Parameters ———-

Returns

type_attrstr
Returns an attributes type.
get_default_value()[source]

Gets attributes default_value type of type_attr. Parameters ———-

Returns

default_valuestr
Returns an attributes default value.
get_define_level()[source]

Gets attributes of define_level as string. Parameters ———-

Returns

define_levelstr
Returns an attributes define level.
class backend.backend_classes.Component(description: str, is_class_component: bool, attributes: dict)[source]

Bases: ParentAgent

This class stores details about a component, it inherits the ParentAgent class and additionally stores if it’s a class components and a list of attributes it has

edit_is_class_component(is_class_component: bool)[source]

Edits the is_class_component value of the component.

Parameters

is_class_componentbool

The new is_class_component boolean value for the component.

edit_attributes(attributes: dict)[source]

Edits the attributes dictionary of the component.

Parameters

attributesdict

The new attributes dictionary for the component.

get_is_class_component()[source]

Gets components boolean is_class_component.

Returns

is_class_componentbool
Returns if a components is a class component.
get_attributes()[source]

Gets component’s dictionary of attribute classes, with the keys being the name of the class.

Returns

attributesdict[Attribute]
Returns a dictionary containing the components attributes.
class backend.backend_classes.Agent(description: str, given_components: list[str], init_coordinates: list[str] = None)[source]

Bases: ParentAgent

This class stores details about an agent, it inherits the ParentAgent class and additionally stores a list of component names that it has been given

edit_given_components(given_components: list[str])[source]

Edits the given_components list of the agent.

Parameters

given_componentslist[str]

The new given_components list for the agent.

edit_init_coordinates(init_coordinates: list[str])[source]

Edits the init_coordinates list of the agent.

Parameters

init_coordinateslist[str]

The new init_coordinates list for the agent.

get_given_components()[source]

Gets agents list of given components names as list of strings. Parameters ———-

Returns

given_componentslist[str]
Returns a list containing the agents components.
get_init_coordinates()[source]

Gets agents list of given init_coordinates names as list of strings. Parameters ———-

Returns

init_coordinateslist[str]
Returns a list containing the agents initial coordinates.
class backend.backend_classes.System(description: str, execute_function_body: str = None, start: int = None, end: int = None, frequency: int = None, generators: dict = None)[source]

Bases: ParentAgent

This class stores details about an agent, it inherits the ParentAgent class and additionally stores the execute function body

edit_execute_function_body(execute_function_body: str)[source]

Edits the execute_function_body of the system.

Parameters

execute_function_bodystr

The new execute_function_body for the system.

edit_start(start: int)[source]

Edits the start iteration of the system.

Parameters

startint

The new start iteration for the system.

edit_end(end: int)[source]

Edits the end iteration of the system.

Parameters

endint

The new end iteration for the system.

edit_frequency(frequency: int)[source]

Edits the frequency of the system.

Parameters

frequencyint

The new frequency for the system.

edit_generators(generators: dict)[source]

Edits the generators dictionary of the system.

Parameters

generatorsdict

The new generators for the system.

get_execute_function_body()[source]

Gets systems execute_function_body as string. Parameters ———-

Returns

execute_function_bodystr
Returns the systems execute function body.
get_start()[source]

Gets systems start iteration as int. Parameters ———-

Returns

startint
Returns the systems starting iteration.
get_end()[source]

Gets systems end iteration as int. Parameters ———-

Returns

endint
Returns the systems ending iteration.
get_frequency()[source]

Gets systems frequency as int. Parameters ———-

Returns

frequencyint
Returns the systems frequency of being run.
get_generators()[source]

Gets systems generators as a dict. Parameters ———-

Returns

generatorsdict[Generator]
Returns a dictionary of the systems generator objects.
remove_start()[source]

Makes the start iteration of the system the default again. Parameters ———-

remove_end()[source]

Makes the end iteration of the system the default again. Parameters ———-

remove_frequency()[source]

Makes the systems frequency the default again. Parameters ———-

class backend.backend_classes.Generator(description: str, nickname: str, return_value: str, attributes: dict)[source]

Bases: ParentAgent

This class stores details about a system generator, it inherits the ParentAgent class and additionally stores the attributes it requires as well as the code used to generate the return value

edit_nickname(nickname: str)[source]

Edits the nickname of the Generator.

Parameters

nicknamestr

The new nickname for the Generator.

edit_return_value(return_value: str)[source]

Edits the return_value code of the Generator.

Parameters

return_valuestr

The new return_value code for the Generator.

edit_attributes(attributes: dict)[source]

Edits the attributes dictionary of the Generator.

Parameters

attributesdict

The new attributes dictionary for the Generator.

get_nickname()[source]

Gets Generator’s nickname.

Returns

nicknamestr
Returns the nickname for the generator.
get_return_value()[source]

Gets Generator’s return_value.

Returns

return_valuestr
Returns the return value code for the generator.
get_attributes()[source]

Gets Generator’s dictionary of attribute classes, with the keys being the name of the class.

Returns

attributesdict[Attribute]
Returns a dictionary of the generators attribute objects.
class backend.backend_classes.AgentOfInterest(comp_of_interest: list[str], count: bool, position: bool, individual: bool, mean_val: bool, median_val: bool, total_val: bool, max_val: bool, min_val: bool, variance: bool, std_dev: bool)[source]

Bases: object

This class is for data collection purposes and stores details about an agent of interests and its desired components

edit_comp_of_interest(comp_of_interest: list[str])[source]

Edits the components of interest for the agent.

Parameters

comp_of_interestlist[str]

The new list of components of interest.

edit_count(count: bool)[source]

Edits the keep count boolean.

Parameters

countbool

The new keep count boolean.

edit_position(position: bool)[source]

Edits the position boolean.

Parameters

positionbool

The new postion boolean.

edit_individual(individual: bool)[source]

Edits the individual boolean.

Parameters

individualbool

The new individual boolean.

edit_mean_val(mean_val: bool)[source]

Edits the mean value boolean.

Parameters

mean_valbool

The new mean value boolean.

edit_median_val(median_val: bool)[source]

Edits the median value boolean.

Parameters

median_valbool

The new median value boolean.

edit_total_val(total_val: bool)[source]

Edits the total value boolean.

Parameters

total_valbool

The new total value boolean.

edit_max_val(max_val: bool)[source]

Edits the max value boolean.

Parameters

max_valbool

The new max value boolean.

edit_min_val(min_val: bool)[source]

Edits the min value boolean.

Parameters

min_valbool

The new min value boolean.

edit_variance(variance: bool)[source]

Edits the variance boolean.

Parameters

variancebool

The new variance boolean.

edit_std_dev(std_dev: bool)[source]

Edits the standard deviation boolean.

Parameters

std_devbool

The new standard deviation boolean.

get_comp_of_interest()[source]

Gets the components of interest list for the agent.

Returns

comp_of_interestlist[str]
Returns List of components of interest to return.
get_count()[source]

Gets the keep count boolean for the agent.

Returns

countbool
Returns keep count boolean to return.
get_position()[source]

Gets the position boolean for the agent.

Returns

positionbool
Returns postion boolean to return.
get_individual()[source]

Reurns the individual boolean for the agent.

Returns

individualbool
Returns individual boolean to return.
get_mean_val()[source]

Reurns the mean boolean for the agent.

Returns

mean_valbool
Returns mean value boolean to return.
get_median_val()[source]

Reurns the median boolean for the agent.

Returns

median_valbool
Returns median value boolean to return.
get_total_val()[source]

Reurns the total boolean for the agent.

Returns

total_valbool
Returns total value boolean to return.
get_max_val()[source]

Reurns the max boolean for the agent.

Returns

max_valbool
Returns max value boolean to return.
get_min_val()[source]

Reurns the min boolean for the agent.

Returns

min_valbool
Returns min value boolean to return.
get_variance()[source]

Reurns the variance boolean for the agent.

Returns

variancebool
Returns variance boolean to return.
get_std_dev()[source]

Reurns the standard deviation boolean for the agent.

Returns

std_devbool
Returns standard deviation boolean to return.
class backend.backend_classes.ModelDetails(name: str, description: str, initial_parameters: dict = None, gridworld: bool = False, sim_length: int = 1, sim_seed: int = None)[source]

Bases: ParentAgent

This class stores details about the model, it inherits the ParentAgent class and additionally stores the models name, description, a dictionary of initial parameters as well as the length of the simulation and the seed for its random generator

get_list_initial_parameters()[source]

Gets a list of all initial parameters for to the model.

Parameters

Returns

initial_parameterslist[str]
Returns a list of initial_parameters
get_list_num_agents()[source]

Gets a list of all number of agents names for to the model.

Parameters

Returns

num_agent_nameslist[str]
Returns a list of num_agent_names
add_initial_parameter(initial_parameter_name: str, initial_parameter_type: str, initial_parameter_value: int = None)[source]

Adds an initial_parameter to the model.

Parameters

initial_parameter_namestr

The name of the initial_parameter in the model.

initial_parameter_typestr

The new type for an initial_parameter for in the model.

initial_parameter_valueint

The new value for an initial_parameter for in the model.

Returns

error termint
Returns 0 on success
Returns 1 if initial parameter already exist
add_num_agent(agent_name: str, init_num: int = None)[source]

Adds an agents initial count to the model.

Parameters

agent_namestr

The name of the agent in the model.

init_numint, Optional

The new initial value for the agent.

Returns

error termint
Returns 0 on success
Returns 1 if num_agent already exist
edit_name(name: str)[source]

Edits the name of the model.

Parameters

namestr

The new name for the model.

edit_initial_parameter(initial_parameter_name: str, initial_parameter_type: str = None, initial_parameter_value: int = None)[source]

Edits an initial_parameter of the model.

Parameters

initial_parameter_namestr

The name of the initial_parameter in the model.

initial_parameter_typestr, Optional

The new type for an initial_parameter for in the model.

initial_parameter_valueint, Optional

The new value for an initial_parameter for in the model.

Returns

error termint
Returns 0 on success
Returns 1 if initial parameter doesn’t exist
edit_num_agent(agent_name: str, init_num: int)[source]

Edits an agents initial count for the model.

Parameters

agent_namestr

The name of the agent in the model.

init_numint

The new initial value for the agent.

Returns

error termint
Returns 0 on success
Returns 1 if num_agent doesn’t already exist
edit_gridworld(gridworld: bool)[source]

Edits the gridworld boolean of the model.

Parameters

gridworldbool

The new gridworld boolean for the model.

edit_sim_length(sim_length: int)[source]

Edits the sim_length of the model.

Parameters

sim_lengthint

The new sim_length for the model.

edit_sim_seed(sim_seed: int)[source]

Edits the sim_seed of the model.

Parameters

sim_seedint

The new sim_seed for the model.

get_name()[source]

Gets name of the model as string. Parameters ———-

Returns

namestr
Returns the name for the model.
get_initial_parameter(initial_parameter_name: str)[source]

Gets an array of an initial_parameter of the model, a list of [parameter type, parameter value].

Parameters

initial_parameter_namestr

The name of the initial_parameter in the model.

Returns

initial_parameterlist[str,int]
Returns the details about the initial parameter.
error termint
Returns 1 if initial parameter doesn’t already exist
get_num_agent(agent_name: str)[source]

Gets an int of an agent_name’s number of agents at the start of the model.

Parameters

agent_namestr

The agent_name of the initial count of that agent in the model.

Returns

num_agentint
Returns the initial value for the num_agent.
error termint
Returns 1 if num_agent doesn’t already exist
get_gridworld()[source]

Gets the gridworld boolean value. Parameters ———-

Returns

gridworldbool
Returns if the model is a gridworld.
get_sim_length()[source]

Gets the length of the simulation as an int. Parameters ———-

Returns

sim_lengthint
Returns the number of iterations of the model.
get_sim_seed()[source]

Gets the seed of the simulation as an int. Parameters ———-

Returns

sim_seedint
Returns the seed of the model.
remove_initial_parameter(initial_parameter_name: str)[source]

Removes an initial_parameter of the model.

Parameters

initial_parameter_namestr

The name of the initial_parameter in the model to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if initial_parameter doesn’t already exist
remove_num_agent(agent_name: str)[source]

Removes a number of agents at the start of the model.

Parameters

agent_namestr

The agent_name of the initial count of that agent in the model to be removed.

Returns

error termint
Returns 0 on success
Returns 1 if num_agent doesn’t already exist

backend.backendutils module

Backend Utility functions for creating AGE-ABM file @Author Max Hall @Co-Authors Meghan Ireland and Matthew Fleischman

class backend.backendutils.WriteModelFile(file_name: str = 'Custom')[source]

Bases: object

This is a base class which will store all the data relating to an instance of writing a model to a file this includes storing strings containing the code to be written into the imports, components, agents, systems and data collection and model sections as well as the main file

create_imports_section(model)[source]

Writes the required imports in the file desired format.

Parameters

modelmodel_env

This allows the function to access the necessary info to write to the file

Returns

error termint
Returns 0 on success
Returns 1 if creation fails, prints error message in terminal
create_components_section(model)[source]

Writes the components into the section.

Parameters

modelmodel_env

This allows the function to access the necessary info to write to the file

Returns

error termint
Returns 0 on success
Returns 1 if creation fails, prints error message in terminal
create_agents_section(model)[source]

Writes the agents into the section.

Parameters

modelmodel_env

This allows the function to access the necessary info to write to the file

Returns

error termint
Returns 0 on success
Returns 1 if creation fails, prints error message in terminal
create_systems_section(model)[source]

Writes the agents into the section.

Parameters

modelmodel_env

This allows the function to access the necessary info to write to the file

Returns

error termint
Returns 0 on success
Returns 1 if creation fails, prints error message in terminal
create_data_collection_section(model)[source]

Writes data collection into the section.

Parameters

modelmodel_env

This allows the function to access the necessary info to write to the file

Returns

error termint
Returns 0 on success
Returns 1 if creation fails, prints error message in terminal
create_model_section(model)[source]

Writes the model into its section.

Parameters

modelmodel_env

This allows the function to access the necessary info to write to the file

Returns

error termint
Returns 0 on success
Returns 1 if creation fails, prints error message in terminal
create_main_file_section(model, visualise_model: bool = False)[source]

Writes the code required for the user to execute the model.

Parameters

modelmodel_env

This allows the function to access the necessary info to write to the file

Returns

error termint
Returns 0 on success
Returns 1 if creation fails, prints error message in terminal
create_model_file()[source]

Writes the model into the file.

Returns

error termint
Returns 0 on success
Returns 1 if write fails, prints error message in terminal
create_main_file()[source]

Writes the main/runtime into the file.

Returns

error termint
Returns 0 on success
Returns 1 if write fails, prints error message in terminal

Module contents