Graphical User Interface

python -m abce.show shows the simulation results in ./result/*

abcegui.gui(parameters, names=None, title=None, text=None, self_hosted=True, truncate_initial_rounds=0)

gui is a decorator that can be used to add a graphical user interface to your simulation.

Args:

parameters:

a dictionary with the parameter name as key and an example value as value. Instead of the example value you can also put a tuple: (min, default, max)

parameters can be:
  • float:
    {‘exponent’: (0.0, 0.5, 1.1)}
  • int:
    {‘num_firms’: (0, 100, 100000)}
  • dict or list, which should be strings of a dict or a list (see example):
    {‘list_to_edit’: “[‘brd’, ‘mlk’, ‘add’]”}
  • everything else that can be evaluated as a string, see (eval)[https://docs.python.org/2/library/functions.html#eval]
  • a list of options:
    {‘several_options’: [‘opt_1’, ‘opt_2’, ‘opt_3’]}
  • a string:
    {‘name’: ‘2x2’}
names (optional):
a dictionary with the parameter name as key and an alternative text to be displayed instead.
title:
a string with the name of the simulation.
text:
a description text of the simulation. Can be html.
truncate_initial_periods:
Does not display the initial x rounds
self_hosted:
If you run this on your local machine self_hosted must be True. If used with an uWSGI/Nginx or different web server must be False

Example:

simulation_parameters = {'name': 'name',
                     'trade_logging': 'off',
                     'random_seed': None,
                     'num_rounds': 40,
                     'num_firms': (0, 100, 100000),
                     'num_household': (0, 100, 100000),
                     'exponent': (0.0, 0.5, 1.1),
                     'several_options': ['opt_1', 'opt_2', 'opt_3']
                     'list_to_edit': "['brd', 'mlk', 'add']",
                     'dictionary_to_edit': "{'v1': 1, 'v2': 2}"}

names = {'num_firms': 'Number of Firms'}

@gui(parameters, simulation_parameters, names=names)
def main(simulation_parameters):
    w = Simulation(simulation_parameters)
    action_list = [
    ('household', 'sell_labor'),
    ('firm', 'buy_inputs'),
    ('firm', 'production')]
    w.add_action_list(action_list)

    w.build_agents(Firm, simulation_parameters['num_firms'])
    w.build_agents(Household, simulation_parameters['num_households'])
    w.run()

if __name__ == '__main__':
    main(simulation_parameters)
Simulation.graphs(open=True, new=1)[source]

after the simulation is run, graphs() shows graphs of all data collected in the simulation. Shows the same output as the @gui decorator shows.

Args:

open (True/False):
whether to open a new window
new:
If new is 0, the url is opened in the same browser window if possible. If new is 1, a new browser window is opened if possible. If new is 2, a new browser page (tab) is opened if possible.

Example:

simulation = Simulation(...)
for r in range(100):
    simulation.advance_round(r)
    agents.do_something()
    ...

simulation.graphs()

It is possible to add text frames between the simulation results. In order to add a text frame to the simulation output, simply add a text file .txt or .html in either your source code directory or if generated during the simulation in the simulation.path directory (where the .csv are). The first line of the text file is the title the rest the text. The text can be formatted as html, the first line is separate from the rest. In the simulation results all frames are displayed in alphabetical order, the title in the first line of the text-file determines the position where the text frame is displayed. In order to display a text before all graphs, you have to put leading space (‘ ‘) in front of the title.