Query episode logs

Bonsai can collect episode, iteration, and simulation data during training and assessment. Bonsai provisions an Azure Log Analytics workspace whenever you create a new Bonsai workspace, and writes log data to Azure Log Analytics so you can query the information along side any other log data you may be collecting.

Before you start

  • You must enable logging to capture log data from brain training. To enable logging with the Bonsai UI or CLI, follow the instructions in Log simulation data.

Tip

Bonsai automatically logs iteration data for all simulator instances associated with custom assessments. You only need to configure logging manually if you want to capture system information.

Step 1: Open your Log Analytics workspace

  1. Sign into the Azure Portal.
  2. Open the list of Bonsai workspaces associated with your account.
  3. Click on the workspace you want to query logs for.

    Logs workspace link in Azure portal

  4. Select Logs from the General section of the portal navigation.

Note

The first time you open the Logs page, Azure will present you with an overlay full of pre-package queries. To avoid seeing this panel every time, make sure the slider at the top of the panel labeled "Show every time" is turned off.

Step 2: Write an Azure log query

Bonsai data is stored in the following custom logs:

  • EpisodeLog_CL: Episode-level data. A single training run will have multiple episode entries.
  • IterationLog_CL: Iteration-level data. A single episode will have multiple iteration entries.
  • ContainerEvent_CL: System-level data about interactions between Azure Container Registry and the container instances used for simulation. Only available when the include-system-logs flag is used.
  • ContainerInstanceLog_CL: System level data about the individual simulator instances logged during training. Only available when the include-system-logs flag is used.

The most important Bonsai log columns for each table are noted below.

Bonsai logging tables and key columns

EpisodeLog_CL

Column name Description
AssessmentId_s Azure object ID of the assessment the episode was a part of. Only set if logging occurred during an assessment.
AssessmentName_s Custom name of the assessment the episode was a part of. Only set if logging occurred during an assessment.
BrainDisplayName_s Case-sensitive name of the Bonsai brain. Also listed in the Bonsai UI.
BrainName_s Case-insensitive name of the Bonsai brain. Also used to reference brains with the Bonsai CLI.
BrainVersionId_g Azure object ID of the brain version.
BrainVersion_d Brain version as an integer.
ConceptName_s Inkling concept trained.
CumulativeReward_d Final reward score for the episode.
EndTime_t UTC timestamp when the episode ended.
EpisodeId_g Azure object ID of the data object that contains the raw episode data.
EpisodeType_s Whether the episode was logged during training or assessment (Unspecified).
FinishReason_s Indicates why the episode ended.
GoalMetrics_s JSON object with iteration-level metrics for Inkling objectives avoid, drive, and reach. Unused objectives are empty.
LessonIndex_d Increasing index of the lesson for the given training or assessment session, starting from 1.
SessionId_s Azure object ID of the managed simulator.
SimConfig_s JSON object with the starting sim configuration information for this episode.
SimId_s Container IP address of the managed simulator.
StartTime_t UTC timestamp when the episode began.
TenantId The Azure tenant under which the log entry was generated.
TimeGenerated UTC timestamp when the log entry occurred.
Type The log entry type. Always set to "EpisodeLog_CL".
WorkspaceId_g Azure object ID of the Bonsai workspace.

IterationLog_CL

Column name Description
BrainAction_s The per-iteration actions returned by the brain, after SimState transformation.
BrainDisplayName_s Display name of the Bonsai brain. Listed in the Bonsai UI.
BrainName_s Internal name of the Bonsai brain. Used to reference brains with the Bonsai CLI.
BrainVersionId_g Azure object ID of the brain version.
BrainVersion_d Brain version as displayed in the Bonsai UI.
EpisodeId_g Azure object ID of the data object that contains the raw episode data.
EpisodeIndex_d Increasing index of the episode for the given lesson, starting from 1.
Halted_b Indicates if the associated episode was halted by the user.
IterationIndex_d Increasing index of the iteration for the given episode, starting from 1.
ObservableState_s State values passed to the brain for the iteration, after SimState transformation.
Reward_d Incremental reward assigned to the brain for the iteration..
SessionId_s Azure object ID of the managed simulator.
SimAction_s Action values sent by the brain to the simulator.
SimState_s State values sent by the simulator to the brain.
TenantId Azure tenant under which the Bonsai workspace was provisioned.
Terminal_b Boolean indicating if the given iteration was a terminal iteration.
TimeGenerated UTC timestamp automatically set by Log Analytics when the log entry occurred.
Timestamp_t UTC timestamp when the log data was generated by Bonsai.
Type The log entry type. Always set to "IterationLog_CL".
WorkspaceId_g Azure object ID of the Bonsai workspace.

ContainerEvent_CL

Column name Description
ContainerGroupInstanceId_g Azure object ID of the ACR container group instance used for simulation.
ContainerGroup_s Case-sensitive name of the ACR container group instance used for simulation.
ContainerName_s Case-sensitive name of the individual ACR container for the associated simulator instance.
Location_s Microsoft service region where the container was deployed.
Message Logged message from the Azure container registry.
OSType_s Operating system type of the associated container instances.
Reason_s ACR event that triggered a system message.
ResourceGroup Azure object ID of the resource group the container group belongs to.
SubscriptionId Azure subscription ID to which the cost of running the container group was charged.
TimeGenerated UTC timestamp when the log entry occurred.
Type The log entry type. Always set to "ContainerEvent_CL".

ContainerInstanceLog_CL

Column name Description
ContainerGroup_s Case-sensitive name of the associated ACR container group instance in ContainerEvent_CL.
ContainerID_s Azure object ID of the ACR container instance.
ContainerImage_s Azure Container Registry name of the container instance.
ContainerName_s Short name of the container instance.
Location_s Microsoft service region where the instance was deployed.
Message Logged message from the container instance.
OSType_s Operating system type of the container instance (for example, Linux).
ResourceGroup Azure object ID of the resource group the container instance belongs to.
Source_s Indicates how the log data was captured.
SubscriptionId Azure subscription ID to which the cost of running the container instance was charged.
TimeGenerated UTC timestamp when the log entry occurred.
Type The log entry type. Always set to "ContainerEvent_CL".

Example queries

List all the unique session IDs in the iterations data:

IterationLog_CL | distinct SessionId_s

Link high-level episode data with the associated iterations using session ID:

IterationLog_CL |
join kind = leftouter (
  EpisodeLog_CL |
  project
    BrainName_s,
    CumulativeReward_d,
    SimConfig_s,
    GoalMetrics_s,
    EpisodeType_s,
    EpisodeId_g
) on EpisodeId_g |
project
  WorkspaceId = WorkspaceId_g, 
  BrainName = BrainName_s,
  BrainVersion = BrainVersion_d, 
  Timestamp = Timestamp_t, 
  SimAction = parse_json(SimAction_s),
  SimState = parse_json(SimState_s), 
  IterationIndex = IterationIndex_d, 
  EpisodeIndex = EpisodeIndex_d, 
  Reward = Reward_d, 
  CumulativeReward = CumulativeReward_d, 
  SimConfig = parse_json(SimConfig_s), 
  GoalMetrics = parse_json(EpisodeType_s), 
  EpisodeType = EpisodeType_s, 
  EpisodeId = EpisodeId_g1 |
order by
  EpisodeIndex asc,
  IterationIndex asc,
  BrainName asc

Next steps

To learn more about standard Azure log columns and Azure log query syntax, refer to the Azure Log Analytics documentation.