Skip to main content
Version: 1.5.0

Metrics

A simulation wouldn't be worth doing if it's just a black box that doesn't output anything. The main method for outputting in V1 is Metrics. The Metric system has been designed with a few prebuilt methods that can be turned on and configured to collect at certain steps. But mainly allows the creator of the simulation to collect data themselves by coding it into the code sections of the simulation configuration.

Each section of the code section gets the metric_collector class provided. This class can be used to collect metrics using the collect function. This function takes two arguments:

  • metric_name which is the name of the metric that you're trying to log.
  • arguments which is an object of arguments.
metric_collector.collect('balance', {'value': 100000, 'token': 'ETH', 'address': '0x6429FEe053768Ffa90a59cAfb98Ca9E8F6471211'})

This will add a structured log entry to the log file which will available for you to download at the end of the simulation. The log entry when calling it like this in your custom code will automatically populate some other fields about the current environment step and when the metric was collected. The amount of arguments here is unlimited, feel free to add as much data as you'd like.

Metrics are processed asynchronously in a Queue. If there's an issue with the metrics being processed the simulator will wait for 30 seconds after the simulation to see if the amount of yet to process metrics decreases. If it doesn't it will throw a Timeout error and mark the simulation as Failed (even though there was a result).

Prebuild

Currently there are two prebuilt metric collectors. These will be collected at a certain runsOn. The runsOn argument is optional, if not provided and the metric is enabled it will collect at all supported steps.

balance

Balance will add a log entry with the balance of an agent for every token that is currently configured (see the tokens section).

Supported runsOn:

  • agentInitialization
  • agentPreStep
  • agentStep
  • agentPostStep

step_action:

Will log which step has been performed by the agent in a very raw format. You might want to do this yourself and add more detailed information.

Supported runsOn:

  • agentStep

Format

nametype
typeobject
requiredtrue

transactions:

Will log all transactions that are sent from every agent. Only transactions that are sent by registered agents will be logged, any other transactions for management purposes will be left out since these won't be visible on any block explorer for example anyways.

Does not support runsOn.

Format

nametype
typeobject
requiredtrue

Example

metrics:
prebuild:
balance:
enabled: true
runsOn: ["agentPreStep"]
step_action:
enabled: true
runsOn: ["agentStep"]
transactions:
enabled: true