Skip to content
1 change: 1 addition & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added ability to start training (initialize model weights) from a previous run ID. (#3710)
- The internal event `Academy.AgentSetStatus` was renamed to `Academy.AgentPreStep` and made public.
- The offset logic was removed from DecisionRequester.
- The communication API version has been bumped up to 1.0.0 and will use [Semantic Versioning](https://semver.org/) to do compatibility checks for communication between Unity and the Python process.

### Minor Changes
- Format of console output has changed slightly and now matches the name of the model/summary directory. (#3630, #3616)
Expand Down
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Academy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class Academy : IDisposable
/// on each side, although we may allow some flexibility in the future.
/// This should be incremented whenever a change is made to the communication protocol.
/// </summary>
const string k_ApiVersion = "0.16.0";
const string k_ApiVersion = "1.0.0";

/// <summary>
/// Unity package version of com.unity.ml-agents.
Expand Down
14 changes: 11 additions & 3 deletions com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ public RpcCommunicator(CommunicatorInitParameters communicatorInitParameters)

#region Initialization

internal static bool CheckCommunicationVersionsAreCompatible(string unityCommunicationVersion, string pythonApiVersion)
{
var unityVersion = new Version(unityCommunicationVersion);
var pythonVersion = new Version(pythonApiVersion);
return unityVersion.Major == pythonVersion.Major;
}

/// <summary>
/// Sends the initialization parameters through the Communicator.
/// Is used by the academy to send initialization parameters to the communicator.
Expand Down Expand Up @@ -93,11 +100,12 @@ public UnityRLInitParameters Initialize(CommunicatorInitParameters initParameter
{
var pythonCommunicationVersion = initializationInput.RlInitializationInput.CommunicationVersion;
var pythonPackageVersion = initializationInput.RlInitializationInput.PackageVersion;
if (pythonCommunicationVersion != initParameters.unityCommunicationVersion)
var unityCommunicationVersion = initParameters.unityCommunicationVersion;
if (!CheckCommunicationVersionsAreCompatible(unityCommunicationVersion, pythonCommunicationVersion))
{
Debug.LogWarningFormat(
"Communication protocol between python ({0}) and Unity ({1}) don't match. " +
"Python library version: {2}.",
"Communication protocol between python ({0}) and Unity ({1}) have different " +
"major versions and are incompatible. Python library version: {2}.",
pythonCommunicationVersion, initParameters.unityCommunicationVersion,
pythonPackageVersion
);
Expand Down
3 changes: 3 additions & 0 deletions com.unity.ml-agents/Tests/Editor/Communicator.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using NUnit.Framework;

namespace MLAgents.Tests.Communicator
{
[TestFixture]
public class RpcCommunicatorTests
{
[Test]
public void TestCheckCommunicationVersionsAreCompatible()
{
var unityVerStr = "1.0.0";
var pythonVerStr = "1.0.0";
Assert.IsTrue(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr, pythonVerStr));
unityVerStr = "2.0.0";
Assert.IsFalse(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr, pythonVerStr));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions ml-agents-envs/mlagents_envs/environment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import atexit
from distutils.version import StrictVersion
import glob
import uuid
import numpy as np
Expand Down Expand Up @@ -58,7 +59,7 @@ class UnityEnvironment(BaseEnv):
# Currently we require strict equality between the communication protocol
# on each side, although we may allow some flexibility in the future.
# This should be incremented whenever a change is made to the communication protocol.
API_VERSION = "0.16.0"
API_VERSION = "1.0.0"

# Default port that the editor listens on. If an environment executable
# isn't specified, this port will be used.
Expand Down Expand Up @@ -153,12 +154,13 @@ def __init__(
self._close(0)
raise

unity_communicator_version = aca_params.communication_version
if unity_communicator_version != UnityEnvironment.API_VERSION:
unity_communicator_version = StrictVersion(aca_params.communication_version)
api_version = StrictVersion(UnityEnvironment.API_VERSION)
if unity_communicator_version.version[0] != api_version.version[0]:
self._close(0)
raise UnityEnvironmentException(
f"The communication API version is not compatible between Unity and python. "
f"Python API: {UnityEnvironment.API_VERSION}, Unity API: {unity_communicator_version}.\n "
f"Python API: {UnityEnvironment.API_VERSION}, Unity API: {aca_params.communication_version}.\n "
f"Please go to https://github.com/Unity-Technologies/ml-agents/releases/tag/latest_release "
f"to download the latest version of ML-Agents."
)
Expand Down