kernel package

Submodules

kernel.actions module

Definition of the class ActionSet

class kernel.actions.ActionSet[source]

Bases: object

The action set of the agent

kernel.agentCreation module

Agent Creation

The agents are created using dependency injection The definitions of the agents that will be used in the simulation are in the yaml file

class kernel.agentCreation.AgentPopulationCreator(simulation, model, agents_def)[source]

Bases: object

Agent Population Generator Agent Implemented Subclass must be used

class kernel.agentCreation.AgentProvider[source]

Bases: dependency_injector.providers.Factory

Agent Provider Class

kernel.basicAgents module

Definition of the class Agent

class kernel.basicAgents.Agent(simulation, model, agent_number, agent_def)[source]

Bases: object

This is the basic agent class

alive()[source]

Agent set to alive

dead()[source]

Agent set to dead

enter_space(space_name)[source]

Agent enter space

executionLoop()[source]

An Agent execution loop

get_attribute(attribute_name)[source]

Get an agent attribute

step()[source]

Agent standard step - can be specialized by subclass

class kernel.basicAgents.DiscreteEventAgent(simulation, model, agent_number, agent_def)[source]

Bases: kernel.basicAgents.Agent

dev_step(this_step)[source]

Discrete Event Step - Updates the step for the agent

my_step()[source]

Returns the agent step

step()[source]

Dev Agent standard step - can be specialized by subclass – The code below is only an example

class kernel.basicAgents.EventAgent(simulation, model, agent_number, agent_def)[source]

Bases: kernel.basicAgents.Agent

step(this_step)[source]

Agent standard step - can be specialized by subclass ] – The code below is only an example

kernel.basicObservers module

Definition of the class Observer

class kernel.basicObservers.Observer(name, model, simulation, entity_class, agent_vars, path_to_results)[source]

Bases: object

The observer classs - This class observe the agents and collects data

add_observables_keys()[source]

Add general observable variables from the agent (model, simulation, scenario, run, step, time, agent_name)

append_observation()[source]

Append an observation in the observables dictionary

basic_observation()[source]

Observer the agent variables

create_dataframe()[source]
create_observables()[source]

Create the dictionary of observable variables (for the observation file)

define_observable_entity(entity_class)[source]

Defines the type of agent that will be observed by this observer

define_observable_vars()[source]

Define the variables that observe will update in the observation (defined in the yaml file)

observe(step)[source]

Observe the variables

save_dataframe(df_name)[source]

Create a dataframe to update the observations

set_observation()[source]

Set an observation in the observables dictionary

update_observation_keys()[source]

Updates the general observable variables at each observation (step)

kernel.basicScenarios module

Definition of the class Scenario

class kernel.basicScenarios.AgentVar(name, var_type, var_dist, value)[source]

Bases: object

An agent var

generate_value()[source]

Generates the value for the agent stochastic variable using the definition in the variable object

class kernel.basicScenarios.Scenario(simulation, model, name, parameters, variables, agents_init)[source]

Bases: object

Class that contains
the definitions of a scenario
execute_scenario()[source]

Execute the scenario The simulation executes an pre-scenario and a post-scenario for each scenario

initialize_agents_vars()[source]

The scenario object initializes the variables dict from the yaml agent variables definition (for each scenario)

initialize_parameters()[source]

Initialize the scenario parameters The parameters (names and values) come from scenario yaml definition

initialize_schedule()[source]

Initialize the schedule depending on type of schedule

initialize_variables()[source]

Initialize scenario variables The scenario variables come from the yaml scenario definition

post_scenario()[source]

In post scenario, the observation dataframe is saved

pre_scenario()[source]

Initializes the scenario parameters, variable, shcedule, agents vars etc.

run(run_nr)[source]

This method executes the schedule

run_threaded(run_nr)[source]

This method executes the schedule

set_an_agent_vars()[source]

Using the variables dict, the scenario object initializes the variables for each agent (by agent type)

kernel.basicSchedule module

Definition of the class Schedule

class kernel.basicSchedule.EventSchedule(name, model)[source]

Bases: kernel.basicSchedule.Schedule

An Event Schedule

collect_event(an_event)[source]
execute(scenario_name, step_unit, step_interval, no_of_steps, run_nr)[source]

Interface for executing methods of schedule objects Implemented by subclass

class kernel.basicSchedule.MixedSchedule(name, model)[source]

Bases: kernel.basicSchedule.Schedule

A mixed schedule for random execution

execute(scenario_name, step_unit, step_interval, no_of_steps, run_nr)[source]

Executes the Mixed Schedule

class kernel.basicSchedule.PoolSchedule(name, model)[source]

Bases: kernel.basicSchedule.Schedule

A pool schedule

execute(scenario_name, step_unit, step_interval, no_of_steps, run_nr)[source]

Executes the Pool Schedule

class kernel.basicSchedule.Schedule(name, model)[source]

Bases: object

Schedule Class

execute(scenario_name, step_unit, step_interval, no_of_steps, run_nr)[source]

Interface for executing methods of schedule objects Implemented by subclass

kernel.basicSpaces module

The space class and the associated classes

class kernel.basicSpaces.Space(model, name, actions_set_file, action_class)[source]

Bases: object

The space class

enter(agent_name, agent)[source]

An agent enter the a space object

exit(agent_name)[source]

An agent exits a space object

update()[source]

A Space updates its values and execute methods This method is impmented by space subclass

kernel.decision_mechanism module

Definition of the class Decision_Mechanism

class kernel.decision_mechanism.Decision_Mechanism(an_agent)[source]

Bases: object

The agent Decision Mechanism

decides()[source]

Uses sensors in space-time to capture env variables

set_actions(agent_role, space)[source]

Set agent actions

set_rules(agent_role, space)[source]

Set rules for the agent dm

kernel.ecos_p_config module

kernel.ecos_p_config.get_paths(print_results=False, config_file='config.json')[source]

kernel.event module

Definition of the class Event

class kernel.event.Event(an_agent, a_space, an_action)[source]

Bases: object

The events handled by the agent and the space

generate_event_id()[source]

Generates an unique ID for and event

set_status(new_status)[source]

Set status for an event

kernel.main module

Model Creation

This method reads a json file, creates de Simulation object The simulation object has all classes and specifications to execute de simulation The agents, schedule, spaces, observers, scenarios, initial values (for the scenarios) are all defined in the yaml file After the simulation object is created, the simulation is executed (all scenarios, and all runs in each scenario) The results of the scenarios are writen in files in the folder runs

kernel.main.execute_simulation(path_to_model, model_config, simulation_defs)[source]

This is the main simulation method without a graphical interface. This method receives 3 parameters: path_to_model - The path to the model that is executing model_config - The configuration file for the model that is executing simulation_defs - The model and simulation definition file

kernel.memory module

Definition of the class Memory

class kernel.memory.Memory(an_agent)[source]

Bases: object

The agent memory

initialize_state_events(events)[source]

Initialize state variables

initialize_state_variables(state_variables)[source]

Initialize state variables

perceives()[source]

Uses sensors in space-time to capture env variables

set_data(agent_role, space)[source]

Set data used in agent memory

update_event(event)[source]

Update agent events

update_state_variable(state_variable)[source]

Update agent state variables

kernel.model module

Definition of the class Model

This class receives a json file with the definition of the simulation scenario and then creates the simulation with all simulation objects

class kernel.model.Model(simulation, json_simulation_defs, path_to_results)[source]

Bases: object

Model Basic Class Receives the json file name and read it Creates all objects in the Simulation

agents_by_type()[source]

Returns a dict with all agents in the simulation ordered by type (agent specific class)

agents_number()[source]

Returns how many agents we have in the simulation (size of agents dict)

agents_of_type(agent_type)[source]

Returns a dict with the agents with an specific type

agents_of_type_number(agent_type)[source]

Returns how many agents of an specific type

create_agents()[source]

Access the AgentFactory (AgentPopulationCreator). Create the agents

create_observers(path_to_results)[source]

Access the ObserverFactory (ObserverCreator). Create the Observers

create_schedule(schedule_def)[source]

Creates the model schedule using the json schedule definition

create_spaces()[source]

Access SpaceFactory (SpaceCreator) and create space objects for the simulation from the json definition

enter_model(agent_name, agent)[source]

An agent enters the model (is included in agents dict)

exit_model(agent_name)[source]

An agent exits the model (is deleted from agents dict)

mixed_agents()[source]

Returns a randomly shuffled list of agents (from agents dict)

mixed_spaces()[source]

Returns a randomly shuffled list of spaces (from spaces dict)

no_of_agents()[source]

Returns how many agents we have in the simulation (size of agents dict)

kernel.observerCreation module

Definition of the class Observer Inspired on datacollection.py from mesa abm https://mesa.readthedocs.io/en/master/

class kernel.observerCreation.ObserverCreator(model, simulation, observer_def, path_to_results)[source]

Bases: object

Observer Generator - Observer Implemented Subclass must be used

class kernel.observerCreation.ObserverProvider[source]

Bases: dependency_injector.providers.Factory

Observer Provider Class

provided_type

Used by autodoc_mock_imports.

kernel.scenarioCreation module

Scenario Creation

The Scenarios are created using dependency injection The definition of the Scenarios that will be used in the simulation are in the yaml file

class kernel.scenarioCreation.ScenarioCreator(simulation, model, scenarios_def)[source]

Bases: object

Scenario Generator - Scenario Implemented Subclass must be used

class kernel.scenarioCreation.ScenarioProvider[source]

Bases: dependency_injector.providers.Factory

Scenario Provider Class

provided_type

Used by autodoc_mock_imports.

kernel.scheduleCreation module

Schedule Creation

The schedule is created using dependency injection The definition of the schedule that will be used in the simulation is in the yaml file

class kernel.scheduleCreation.ScheduleCreator(model, schedule_def)[source]

Bases: object

Schedule Generator - Schedule Implemented Subclass must be used

class kernel.scheduleCreation.ScheduleProvider[source]

Bases: dependency_injector.providers.Factory

Schedule Provider Class

provided_type

Used by autodoc_mock_imports.

kernel.simulation module

Simulation Class (This implements a batch simulation)

class kernel.simulation.Simulation(simulation_config_file, simulation_file)[source]

Bases: object

This class implements a simulation

create_scenarios()[source]

Scenario creation

execute_simulation()[source]

Executes a Simulation.

This method gets all scenarios in the json definition and executes the defined number of runs for each scenario

initialize_simulation()[source]

Factory pattern to create a simulation

intialize_run()[source]

Run initialization - Initialize main variables for run agents variables and space variables

kernel.spaceCreation module

Space Creation

The spaces are created using dependency injection The definition of the spaces that will be used in the simulation is in the yaml file

class kernel.spaceCreation.SpaceCreator(model, spaces_def)[source]

Bases: object

Space Creator This is the general Space class implementation Space implemented subclass must be used

class kernel.spaceCreation.SpaceProvider[source]

Bases: dependency_injector.providers.Factory

Space Provider Class

provided_type

Used by autodoc_mock_imports.

Module contents

Python Economic ABM

This is an abm engine for economic simulation in python