From 027d527f6c287f6f37f09bbbb78fef11bb9705c0 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 14 May 2021 15:17:56 -0700 Subject: [PATCH 1/3] Don't connect to new python trainers --- Project/Packages/manifest.json | 4 +- Project/ProjectSettings/ProjectVersion.txt | 2 +- .../Runtime/Communicator/RpcCommunicator.cs | 54 ++++++++++++++++++- com.unity.ml-agents/Runtime/Constants.cs | 6 ++- .../Communicator/RpcCommunicatorTests.cs | 32 +++++++++-- 5 files changed, 87 insertions(+), 11 deletions(-) diff --git a/Project/Packages/manifest.json b/Project/Packages/manifest.json index f17ead7de1..2b4ac65432 100644 --- a/Project/Packages/manifest.json +++ b/Project/Packages/manifest.json @@ -4,9 +4,9 @@ "com.unity.analytics": "3.2.3", "com.unity.collab-proxy": "1.2.15", "com.unity.ml-agents": "file:../../com.unity.ml-agents", - "com.unity.package-manager-ui": "2.0.8", + "com.unity.package-manager-ui": "2.0.13", "com.unity.package-validation-suite": "0.7.15-preview", - "com.unity.purchasing": "2.0.3", + "com.unity.purchasing": "2.2.1", "com.unity.textmeshpro": "1.4.1", "com.unity.modules.ai": "1.0.0", "com.unity.modules.animation": "1.0.0", diff --git a/Project/ProjectSettings/ProjectVersion.txt b/Project/ProjectSettings/ProjectVersion.txt index aac939d2ad..760ea9aaab 100644 --- a/Project/ProjectSettings/ProjectVersion.txt +++ b/Project/ProjectSettings/ProjectVersion.txt @@ -1 +1 @@ -m_EditorVersion: 2018.4.17f1 +m_EditorVersion: 2018.4.32f1 diff --git a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs index 3817e25c22..95935bcb64 100644 --- a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs +++ b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using UnityEngine; using Unity.MLAgents.Analytics; using Unity.MLAgents.CommunicatorObjects; @@ -99,6 +100,41 @@ internal static bool CheckCommunicationVersionsAreCompatible( } internal static bool CheckPythonPackageVersionIsCompatible(string pythonLibraryVersion) + { + // Try to extract the numerical values from the pythonLibraryVersion, e.g. remove the ".dev0" suffix + var versionMatch = Regex.Match(pythonLibraryVersion, @"[0-9]+\.[0-9]+\.[0-9]"); + if (versionMatch.Success) + { + pythonLibraryVersion = versionMatch.Value; + } + + Version pythonVersion; + try + { + pythonVersion = new Version(pythonLibraryVersion); + } + catch + { + // Unparseable version. + // Anything like 0.42.0.dev0 should have been caught with the regex above, so anything here + // is totally bogus. For now, ignore these and let CheckPythonPackageVersionIsSupported handle it. + return true; + } + + if (pythonVersion > PythonTrainerVersions.s_MaxCompatibleVersion) + { + return false; + } + return true; + } + + /// + /// Check if the package is in the supported range. Note that some versions might be unsupported but + /// still compatible. + /// + /// + /// + internal static bool CheckPythonPackageVersionIsSupported(string pythonLibraryVersion) { Version pythonVersion; try @@ -107,7 +143,7 @@ internal static bool CheckPythonPackageVersionIsCompatible(string pythonLibraryV } catch { - // Unparseable - this also catches things like "0.20.0-dev0" which we don't want to support + // Unparseable - this also catches things like "0.20.0.dev0" which we don't want to support return false; } @@ -182,7 +218,21 @@ public UnityRLInitParameters Initialize(CommunicatorInitParameters initParameter throw new UnityAgentsException("ICommunicator.Initialize() failed."); } - var packageVersionSupported = CheckPythonPackageVersionIsCompatible(pythonPackageVersion); + var packageVersionCompatible = CheckPythonPackageVersionIsCompatible(pythonPackageVersion); + if (!packageVersionCompatible) + { + Debug.LogErrorFormat( + "Python package version ({0}) will produce model files that are incompatible with this " + + "version of the com.unity.ml-agents Unity package. Please downgrade to a Python package " + + "between {1} and {2}, or update to a new version of com.unity.ml-agents.", + pythonPackageVersion, + PythonTrainerVersions.s_MinSupportedVersion, + PythonTrainerVersions.s_MaxSupportedVersion + ); + throw new UnityAgentsException("Incompatible trainer version."); + } + + var packageVersionSupported = CheckPythonPackageVersionIsSupported(pythonPackageVersion); if (!packageVersionSupported) { Debug.LogWarningFormat( diff --git a/com.unity.ml-agents/Runtime/Constants.cs b/com.unity.ml-agents/Runtime/Constants.cs index 633d31deab..f3ea8677ac 100644 --- a/com.unity.ml-agents/Runtime/Constants.cs +++ b/com.unity.ml-agents/Runtime/Constants.cs @@ -13,10 +13,14 @@ internal enum MenuGroup internal static class PythonTrainerVersions { - // The python package version must be >= s_MinSupportedVersion + // The python package version should be >= s_MinSupportedVersion // and <= s_MaxSupportedVersion. internal static Version s_MinSupportedVersion = new Version("0.16.1"); internal static Version s_MaxSupportedVersion = new Version("0.20.0"); + + // Any version > to this is known to be incompatible and we will block training. + // Covers any patch to the release before the 2.0.0 package release. + internal static Version s_MaxCompatibleVersion = new Version("0.25.999"); } } diff --git a/com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs b/com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs index d802a97d18..060e5171ad 100644 --- a/com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs +++ b/com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs @@ -54,17 +54,39 @@ public void TestCheckCommunicationVersionsAreCompatible() [Test] public void TestCheckPythonPackageVersionIsCompatible() { - Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.13.37")); // too low - Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.42.0")); // too high + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.13.37")); // low is OK + Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.26.0")); // too high // These are fine Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.16.1")); Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.17.17")); - Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.20.0")); + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.25.0")); + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.25.1")); + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.25.2")); + + // "dev" strings should get removed before parsing + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.17.0.dev0")); + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.25.0.dev0")); + Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.26.0.dev0")); + + // otherwise unparseable - keep support for these + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsCompatible("the airspeed velocity of an unladen swallow")); + } + + [Test] + public void TestCheckPythonPackageVersionIsSupported() + { + Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.13.37")); // too low + Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.42.0")); // too high + + // These are fine + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.16.1")); + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.17.17")); + Assert.IsTrue(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.20.0")); // "dev" string or otherwise unparseable - Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("0.17.0-dev0")); - Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsCompatible("oh point seventeen point oh")); + Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsSupported("0.17.0.dev0")); + Assert.IsFalse(RpcCommunicator.CheckPythonPackageVersionIsSupported("oh point seventeen point oh")); } } } From d597467344fec8bfcd20dc4dff606a59449c75f6 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 14 May 2021 15:30:09 -0700 Subject: [PATCH 2/3] changelog and docs --- com.unity.ml-agents/CHANGELOG.md | 1 + com.unity.ml-agents/Documentation~/com.unity.ml-agents.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 3edf66857c..369953fb52 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to #### com.unity.ml-agents (C#) - Fixed a null reference exception that occurred when loading an ONNX model file that was generated with a new version of the Python trainer (0.26.0 or newer). +- Added checked to prevent training with incompatible versions of the python trainer (0.26.0 or newer). ## [1.0.7] - 2021-03-04 ### Minor Changes diff --git a/com.unity.ml-agents/Documentation~/com.unity.ml-agents.md b/com.unity.ml-agents/Documentation~/com.unity.ml-agents.md index fb41eed439..725ae7a65e 100755 --- a/com.unity.ml-agents/Documentation~/com.unity.ml-agents.md +++ b/com.unity.ml-agents/Documentation~/com.unity.ml-agents.md @@ -48,7 +48,7 @@ Manager documentation]. To install the companion Python package to enable training behaviors, follow the [installation instructions] on our [GitHub repository]. It is strongly recommended that you use the Python package that corresponds to this release (version 0.16.1) for the best experience; -versions between 0.16.1 and 0.20.0 are supported. +versions between 0.16.1 and 0.20.0 are supported. Versions after 0.25.1 cannot be used. ## Requirements From a781729660a9f6402a95dceecd12ff0808bcce61 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Fri, 14 May 2021 15:34:56 -0700 Subject: [PATCH 3/3] PR #s --- com.unity.ml-agents/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 369953fb52..e3a43ddf6f 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -10,8 +10,8 @@ and this project adheres to ### Bug Fixes #### com.unity.ml-agents (C#) - Fixed a null reference exception that occurred when loading an ONNX model file that was generated with a new -version of the Python trainer (0.26.0 or newer). -- Added checked to prevent training with incompatible versions of the python trainer (0.26.0 or newer). +version of the Python trainer (0.26.0 or newer). (#5350) +- Added checked to prevent training with incompatible versions of the python trainer (0.26.0 or newer). (#5370) ## [1.0.7] - 2021-03-04 ### Minor Changes