|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using UnityEngine; |
|
|
|
using Unity.MLAgents.Analytics; |
|
|
|
using Unity.MLAgents.CommunicatorObjects; |
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
{ |
|
|
|
|
|
|
{ |
|
|
|
// Unparseable - this also catches things like "0.20.0-dev0" which we don't want to support
|
|
|
|
// 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; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Check if the package is in the supported range. Note that some versions might be unsupported but
|
|
|
|
/// still compatible.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="pythonLibraryVersion"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
internal static bool CheckPythonPackageVersionIsSupported(string pythonLibraryVersion) |
|
|
|
{ |
|
|
|
Version pythonVersion; |
|
|
|
try |
|
|
|
{ |
|
|
|
pythonVersion = new Version(pythonLibraryVersion); |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
// Unparseable - this also catches things like "0.20.0.dev0" which we don't want to support
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
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( |
|
|
|