Custom Side Channel of MLagents (Release 3)


SEDRo aims to provide automated evaluations of developmental skills in agents. Users can choose to evaluate their model using a Python API. In order to return the results of evaluations to the user, we have made use of custom side channels.

A side channel is used to exchange data between C# (Unity) and Python (API). While there are specific side channels for datatypes such as FloatPropertiesChannel, a custom side channel allows for the exchange of custom data structures.

While following the official documentation for creating a custom side channel by Unity, the current documentation highlights the use of a custom side channel to communicate a floatlist from C# to Python and a String  from Python to C#.

The most common errors while implementing side channels are due to version differences. Make sure to follow the releases document to ensure the use of compatible versions. In its current version SEDRo uses MLAgents Release 3. For compatibility with this release, the following packages and corresponding versions are used.

Untitled Database

Untitled Database

To download com.unity.ml-agents and communicator, install the mlagents package inside Unity. To install ml-agents, ml-agents-envs and gym-unity use the following command in the terminal.

$ pip3 install mlagents==0.17.0

For our use case, on the Unity side the following script is implemented

1.  Create the FloatChannel class in Unity project. The FloatChannel class contains methods to both listen to messages from Python and send messages to Python.

https://lh3.googleusercontent.com/KHG9Om2ANwWk8XyTYylRsoF9blMHfZG-LYZlbEj7zDrC-LP63DImGJTbGMakzzO0mPs3iy8J41TlDkSvTmEQ5tN63hFT4eK6fs259rH-JnVCRZy561X_ywq8ZfohXHDiWYaujwUv

The FloatChannel class has to implement the SideChannel abstract class.

OnMessageReceived(IncomingMessage msg) method is implemented to read data from IncomingMessage.

The ChannelID, which is used to uniquely identify a channel, should be assigned in the constructor.

An OutgoingMessage instance is created, followed by a call to QueueMessageToSend(msg) in order to send messages to Python.

Please note that msgOut.WriteFloatList is used to support the floatlist data structure that we want to send to Python API. Other datastructures can be float, int, string etc.

With this the custom side channel class has been created.