Monitoring Console Messages

Example file: docs/examples/api/example_get_messages.py

When run as a command line tool (as has always been done until the addition of the API), GridLAB-D™ prints a variety of messages to the console including messages about the state of objects in the model (e.g. "waterheater is boiling"). There are two mechanisms by which these console messages can be made visible to API users.

Printing Console Messages to Console

The first and most direct mechanism is to set the GridLAB-D™ object to print these messages out to the console as if you were using the stand-alone command-line application. By default these messages are supressed from being printed to the console but that default can be changed when creating the GridLAB-D™ object.

gld = gridlabd.Gridlabd(verbose=True)

When running the example_sim_start_stop.py model with verbose=True produces the following output which looks very similar to what you would see when running GridLAB-D™ itself.

Worker non-protocol stdout during RUN: WARNING  [INIT] : randunit() introducing extra randomness to prevent state stagnation and infinite loops
Worker non-protocol stdout during RUN: WARNING  [INIT] : last warning message was repeated 8 times
Worker non-protocol stdout during RUN: WARNING  [INIT] : power_convergence_value not set - defaulting to 0.01 base_power
Worker non-protocol stdout during RUN: WARNING  [INIT] : waterheater::init() : height and diameter were not specified, defaulting to 3.78 ft
Worker non-protocol stdout during RUN: WARNING  [INIT] : last warning message was repeated 4 times
Worker non-protocol stdout during RUN: WARNING  [INIT] : The PV is over rated for its parent inverter.
Worker non-protocol stdout during RUN: WARNING  [INIT] : waterheater::init() : height and diameter were not specified, defaulting to 3.78 ft
Worker non-protocol stdout during RUN: WARNING  [INIT] : last warning message was repeated 1 times
Worker non-protocol stdout during RUN: WARNING  [INIT] : The PV is over rated for its parent inverter.
Worker non-protocol stdout during RUN: WARNING  [INIT] : waterheater::init() : height and diameter were not specified, defaulting to 3.78 ft
Worker non-protocol stdout during RUN: WARNING  [INIT] : last warning message was repeated 1 times
Worker non-protocol stdout during RUN: WARNING  [INIT] : The external solver solver_KLU could not be found, defaulting to superLU
Worker non-protocol stdout during RUN: Processing 2023-06-30 23:01:30 PDT...
Worker non-protocol stdout during EXIT_GLD: Core profiler results
Worker non-protocol stdout during EXIT_GLD: ======================
Worker non-protocol stdout during EXIT_GLD: Total objects                122 objects
Worker non-protocol stdout during EXIT_GLD: Parallelism                    1 thread
Worker non-protocol stdout during EXIT_GLD: Total time                   2.0 seconds
Worker non-protocol stdout during EXIT_GLD: Core time                  1.8 seconds (87.7%)
Worker non-protocol stdout during EXIT_GLD: Compiler                 0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Instances                0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Random variables         0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Schedules                0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Loadshapes               0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Enduses                  0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Transforms               0.0 seconds (0.1%)
Worker non-protocol stdout during EXIT_GLD: Objects                  0.1 seconds (5.4%)
Worker non-protocol stdout during EXIT_GLD: Model time                 0.2 seconds/thread (12.3%)
Worker non-protocol stdout during EXIT_GLD: Simulation time                0 days
Worker non-protocol stdout during EXIT_GLD: Simulation speed             183 object.hours/second
Worker non-protocol stdout during EXIT_GLD: Passes completed             254 passes
Worker non-protocol stdout during EXIT_GLD: Time steps completed         126 timesteps
Worker non-protocol stdout during EXIT_GLD: Convergence efficiency      2.02 passes/timestep
Worker non-protocol stdout during EXIT_GLD: Read lock contention        0.0%
Worker non-protocol stdout during EXIT_GLD: Write lock contention       0.0%
Worker non-protocol stdout during EXIT_GLD: Average timestep             86 seconds/timestep
Worker non-protocol stdout during EXIT_GLD: Simulation rate            5400 x realtime
Worker non-protocol stdout during EXIT_GLD: Model profiler results
Worker non-protocol stdout during EXIT_GLD: ======================
Worker non-protocol stdout during EXIT_GLD: Class            Time (s) Time (%) msec/obj
Worker non-protocol stdout during EXIT_GLD: ---------------- -------- -------- --------
Worker non-protocol stdout during EXIT_GLD: climate            0.137     55.7%    137.2
Worker non-protocol stdout during EXIT_GLD: substation         0.029     11.7%     28.8
Worker non-protocol stdout during EXIT_GLD: triplex_meter      0.018      7.4%      0.7
Worker non-protocol stdout during EXIT_GLD: house              0.011      4.5%      1.2
Worker non-protocol stdout during EXIT_GLD: inverter           0.007      2.8%      0.8
Worker non-protocol stdout during EXIT_GLD: waterheater        0.006      2.6%      0.7
Worker non-protocol stdout during EXIT_GLD: triplex_line       0.006      2.5%      0.7
Worker non-protocol stdout during EXIT_GLD: solar              0.006      2.4%      0.7
Worker non-protocol stdout during EXIT_GLD: triplex_node       0.006      2.3%      1.9
Worker non-protocol stdout during EXIT_GLD: node               0.004      1.7%      1.1
Worker non-protocol stdout during EXIT_GLD: ZIPload            0.004      1.5%      0.2
Worker non-protocol stdout during EXIT_GLD: overhead_line      0.003      1.4%      1.1
Worker non-protocol stdout during EXIT_GLD: transformer        0.003      1.3%      0.8
Worker non-protocol stdout during EXIT_GLD: meter              0.003      1.2%      2.9
Worker non-protocol stdout during EXIT_GLD: regulator          0.002      0.9%      2.2
Worker non-protocol stdout during EXIT_GLD: transformer_conf   0.000      0.0%      0.0
Worker non-protocol stdout during EXIT_GLD: regulator_config   0.000      0.0%      0.0
Worker non-protocol stdout during EXIT_GLD: triplex_line_con   0.000      0.0%      0.0
Worker non-protocol stdout during EXIT_GLD: overhead_line_co   0.000      0.0%      0.0
Worker non-protocol stdout during EXIT_GLD: triplex_line_con   0.000      0.0%      0.0
Worker non-protocol stdout during EXIT_GLD: ================ ======== ======== ========
Worker non-protocol stdout during EXIT_GLD: Total              0.246    100.0%      2.0
Worker non-protocol stdout during EXIT_GLD: Core profiler results
Worker non-protocol stdout during EXIT_GLD: ======================
Worker non-protocol stdout during EXIT_GLD: Total objects                122 objects
Worker non-protocol stdout during EXIT_GLD: Parallelism                    1 thread
Worker non-protocol stdout during EXIT_GLD: Total time              1781026157.0 seconds
Worker non-protocol stdout during EXIT_GLD: Core time             1781026156.8 seconds (100.0%)
Worker non-protocol stdout during EXIT_GLD: Compiler                 0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Instances                0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Random variables         0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Schedules                0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Loadshapes               0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Enduses                  0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Transforms               0.0 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Objects                  0.1 seconds (0.0%)
Worker non-protocol stdout during EXIT_GLD: Model time                 0.2 seconds/thread (0.0%)
Worker non-protocol stdout during EXIT_GLD: Simulation time                0 days
Worker non-protocol stdout during EXIT_GLD: Simulation speed               0 object.hours/second
Worker non-protocol stdout during EXIT_GLD: Passes completed             254 passes
Worker non-protocol stdout during EXIT_GLD: Time steps completed         126 timesteps
Worker non-protocol stdout during EXIT_GLD: Convergence efficiency      2.02 passes/timestep
Worker non-protocol stdout during EXIT_GLD: Read lock contention        0.0%
Worker non-protocol stdout during EXIT_GLD: Write lock contention       0.0%
Worker non-protocol stdout during EXIT_GLD: Average timestep             86 seconds/timestep
Worker non-protocol stdout during EXIT_GLD: Simulation rate               0 x realtime

Accessing Console Messages Programmatically

Alternatively, and likely more usefully when using the API, GridLAB-D™ provides an API that allows console messages to be accessed programmatically. This allows API users to evaluate console messages while stepping through simulation to catch messages that may be important when evaluating a specific model. The API to perform this is get_messages() and it returns a JSON object as a list of message dictionaries where each message dictionary is structured as

{
  'timestamp': 'ISO8601 timestamp string or INIT',
  'type': 'type string: INFO, WARNING, ERROR',
  'message': 'message string'
}

The structure of the message allows you to determine if a given message is relevant; this is particuarly useful for "chatty" objects that tend to print often to the console at, say, the "INFO" level. After calling get_messages() you can filter out all the messages where "type" is "INFO" and just look at those that are, say, "WARNING" or "ERROR" messages.

Lastly, the GridLAB-D™ retains messages in its internal message list even after get_messages() are called. To remove these messages from the list (under the assumption that they have been addressed), call clear_messages().