By using the Bonsai Connector object, you can train Bonsai brains from a single animated run that is hosted from your local machine; this is optimal for verifying everything is setup correctly.
Edit me

To start training brains, the simulation model can either be hosted from your local machine or scaled on the Azure platform – this page focuses on the former, referred to as “locally hosted” here; Bonsai refers to the simulation models in this case being “unmanaged”.

About

With an RL-ready simulation model, and possibly some pre-written Inkling code, you have the option to start the training process and run through iterations on your local machine before uploading your model for scaled training.

Communication cycle during locally hosted training

As the diagram shows, your model runs from your machine and sends/receives information from the Bonsai platform - a process automated from the end-users via the Bonsai Connector object.

When the model is setup for locally hosted training, the general execution goes as follows:

  1. You launch a Simulation experiment

  2. The model window appears; once run, the enabled Bonsai Connector starts to take control over your model and it does the following (automatically):

    1. Register the simulator with the Bonsai platform (waiting until it passes or stopping if it fails)

    2. Run your model until the iteration trigger occurs

    3. Pause your model and send an observation to Bonsai

    4. Waits for a reply from Bonsai with an action or a terminal condition

    5. If an action, executes it and continues to the next iteration trigger; if a terminal indicator, stops and restarts the run

Instructions

Start in your AnyLogic environment:

  1. In your top-level agent, verify you have a Bonsai Connector object, that it will be enabled, and is filled out with your Bonsai Workspace ID and Access Key

  2. Verify you have a Simulation experiment with the following properties:

    a. The mode parameter (if present) is set to perform training

    b. Under the “Model time” section, “Execution mode” is set to “Virtual time” & the stop time is set to “Never” (this is controlled by the platform)

    c. The seed option in the “Randomness” section is assigned to your preferences

  3. Start the experiment.

    Graphical user interface, text, application, chat or text message
Description automatically
generated

  4. Switch to the Bonsai portal. You should see your locally hosted model listed under the “Simulators” section (possibly at the end). Clicking on it will show information about it.

    Example

    Example

  5. Prepare a new brain or configure an existing one to your preferences. For help, consult the Inkling Basics.

  6. Once your training regimen is ready, click the green “Train” button. In the pop-up, select your simulator under the “Unmanaged Simulators” section that matches both in name and appropriate timestamp for when it connected.

  7. After some time (typically under a minute) training will commence. On the simulation side, you’ll see the simulation animation starting, ending, and restarting automatically. After a while you’ll be able to see the results of the training under the “Train” tab in Bonsai.

As previously stated, this method of training is only capable of running one simulation at a time (i.e., sequential episodes) and should be primarily used for debugging purposes or to be able to visually monitor the training process. For scaling the training process, it’s advised to upload your model to Azure – a process described in the next section.