浏览代码

Merge branch 'master' into develop-sac-apex

/develop/sac-apex
GitHub 5 年前
当前提交
24b387d3
共有 29 个文件被更改,包括 291 次插入178 次删除
  1. 9
      Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
  2. 11
      Project/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs
  3. 14
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs
  4. 12
      Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
  5. 18
      Project/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs
  6. 18
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs
  7. 18
      Project/Assets/ML-Agents/Examples/Pyramids/Scripts/PyramidAgent.cs
  8. 16
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  9. 11
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
  10. 14
      Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs
  11. 4
      com.unity.ml-agents/CHANGELOG.md
  12. 57
      com.unity.ml-agents/Runtime/Agent.cs
  13. 51
      com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
  14. 8
      com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  15. 11
      com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
  16. 4
      com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs
  17. 3
      com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs
  18. 8
      com.unity.ml-agents/Tests/Runtime/RuntimeAPITest.cs
  19. 2
      com.unity.ml-agents/package.json
  20. 2
      docs/Getting-Started.md
  21. 8
      docs/Learning-Environment-Create-New.md
  22. 3
      docs/Learning-Environment-Design-Agents.md
  23. 12
      docs/Migrating.md
  24. 63
      ml-agents-envs/mlagents_envs/environment.py
  25. 31
      ml-agents-envs/mlagents_envs/tests/test_envs.py
  26. 3
      com.unity.ml-agents/Tests/Editor/Communicator.meta
  27. 55
      com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs
  28. 3
      com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs.meta

9
Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs


SetResetParameters();
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
var action = new float[2];
action[0] = -Input.GetAxis("Horizontal");
action[1] = Input.GetAxis("Vertical");
return action;
actionsOut[0] = -Input.GetAxis("Horizontal");
actionsOut[1] = Input.GetAxis("Vertical");
}
public void SetBall()

11
Project/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs


}
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
var action = new float[3];
action[0] = Input.GetAxis("Horizontal");
action[1] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
action[2] = Input.GetAxis("Vertical");
return action;
actionsOut[0] = Input.GetAxis("Horizontal");
actionsOut[1] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
actionsOut[2] = Input.GetAxis("Vertical");
}
void Update()

14
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs


MoveAgent(vectorAction);
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
var action = new float[4];
action[2] = 2f;
actionsOut[2] = 2f;
action[0] = 1f;
actionsOut[0] = 1f;
action[2] = 1f;
actionsOut[2] = 1f;
action[0] = 2f;
actionsOut[0] = 2f;
action[3] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
return action;
actionsOut[3] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
}
public override void OnEpisodeBegin()

12
Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs


}
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
actionsOut[0] = k_NoAction;
return new float[] { k_Right };
actionsOut[0] = k_Right;
return new float[] { k_Up };
actionsOut[0] = k_Up;
return new float[] { k_Left };
actionsOut[0] = k_Left;
return new float[] { k_Down };
actionsOut[0] = k_Down;
return new float[] { k_NoAction };
}
// to be implemented by the developer

18
Project/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs


}
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
actionsOut[0] = 0;
return new float[] { 3 };
actionsOut[0] = 3;
if (Input.GetKey(KeyCode.W))
else if (Input.GetKey(KeyCode.W))
return new float[] { 1 };
actionsOut[0] = 1;
if (Input.GetKey(KeyCode.A))
else if (Input.GetKey(KeyCode.A))
return new float[] { 4 };
actionsOut[0] = 4;
if (Input.GetKey(KeyCode.S))
else if (Input.GetKey(KeyCode.S))
return new float[] { 2 };
actionsOut[0] = 2;
return new float[] { 0 };
}
public override void OnEpisodeBegin()

18
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs


AddReward(-1f / maxStep);
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
actionsOut[0] = 0;
return new float[] { 3 };
actionsOut[0] = 3;
if (Input.GetKey(KeyCode.W))
else if (Input.GetKey(KeyCode.W))
return new float[] { 1 };
actionsOut[0] = 1;
if (Input.GetKey(KeyCode.A))
else if (Input.GetKey(KeyCode.A))
return new float[] { 4 };
actionsOut[0] = 4;
if (Input.GetKey(KeyCode.S))
else if (Input.GetKey(KeyCode.S))
return new float[] { 2 };
actionsOut[0] = 2;
return new float[] { 0 };
}
/// <summary>

18
Project/Assets/ML-Agents/Examples/Pyramids/Scripts/PyramidAgent.cs


MoveAgent(vectorAction);
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
actionsOut[0] = 0;
return new float[] { 3 };
actionsOut[0] = 3;
if (Input.GetKey(KeyCode.W))
else if (Input.GetKey(KeyCode.W))
return new float[] { 1 };
actionsOut[0] = 1;
if (Input.GetKey(KeyCode.A))
else if (Input.GetKey(KeyCode.A))
return new float[] { 4 };
actionsOut[0] = 4;
if (Input.GetKey(KeyCode.S))
else if (Input.GetKey(KeyCode.S))
return new float[] { 2 };
actionsOut[0] = 2;
return new float[] { 0 };
}
public override void OnEpisodeBegin()

16
Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs


MoveAgent(vectorAction);
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
var action = new float[3];
action[0] = 1f;
actionsOut[0] = 1f;
action[0] = 2f;
actionsOut[0] = 2f;
action[2] = 1f;
actionsOut[2] = 1f;
action[2] = 2f;
actionsOut[2] = 2f;
action[1] = 1f;
actionsOut[1] = 1f;
action[1] = 2f;
actionsOut[1] = 2f;
return action;
}
/// <summary>
/// Used to provide a "kick" to the ball.

11
Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs


m_TextComponent.text = score.ToString();
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
var action = new float[3];
action[0] = Input.GetAxis("Horizontal"); // Racket Movement
action[1] = Input.GetKey(KeyCode.Space) ? 1f : 0f; // Racket Jumping
action[2] = Input.GetAxis("Vertical"); // Racket Rotation
return action;
actionsOut[0] = Input.GetAxis("Horizontal"); // Racket Movement
actionsOut[1] = Input.GetKey(KeyCode.Space) ? 1f : 0f; // Racket Jumping
actionsOut[2] = Input.GetAxis("Vertical"); // Racket Rotation
}
public override void OnEpisodeBegin()

14
Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs


}
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
var action = new float[4];
action[1] = 2f;
actionsOut[1] = 2f;
action[0] = 1f;
actionsOut[0] = 1f;
action[1] = 1f;
actionsOut[1] = 1f;
action[0] = 2f;
actionsOut[0] = 2f;
action[3] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
return action;
actionsOut[3] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
}
// Detect when the agent hits the goal

4
com.unity.ml-agents/CHANGELOG.md


- 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 signature of `Agent.Heuristic()` was changed to take a `float[]` as a parameter, instead of returning the array. This was done to prevent a common source of error where users would return arrays of the wrong size.
- 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.
- The obsolete `Agent` methods `GiveModel`, `Done`, `InitializeAgent`, `AgentAction` and `AgentReset` have been removed.
### Minor Changes
- Format of console output has changed slightly and now matches the name of the model/summary directory. (#3630, #3616)

- Fixed an issue where exceptions from environments provided a returncode of 0. (#3680)
- Running `mlagents-learn` with the same `--run-id` twice will no longer overwrite the existing files. (#3705)
- `StackingSensor` was changed from `internal` visibility to `public`
- Updated Barracuda to 0.6.3-preview.
- Model updates now happen asynchronously with environment steps. (#3690)
- `num_updates` and `train_interval` for SAC were replaced with `steps_per_update`. (#3690)

57
com.unity.ml-agents/Runtime/Agent.cs


m_RequestDecision = false;
}
[Obsolete("GiveModel() has been deprecated, use SetModel() instead.")]
public void GiveModel(
string behaviorName,
NNModel model,
InferenceDevice inferenceDevice = InferenceDevice.CPU)
{
SetModel(behaviorName, model, inferenceDevice);
}
/// <summary>
/// Updates the Model for the agent. Any model currently assigned to the
/// agent will be replaced with the provided one. If the arguments are

TimerStack.Instance.SetGauge(gaugeName, GetCumulativeReward());
}
[Obsolete("Done() has been deprecated, use EndEpisode() instead.")]
public void Done()
{
EndEpisode();
}
/// <summary>
/// Sets the done flag to true.
/// </summary>

}
}
[Obsolete("InitializeAgent() has been deprecated, use Initialize() instead.")]
public virtual void InitializeAgent()
{
}
/// <summary>
/// Initializes the agent, called once when the agent is enabled. Can be
/// left empty if there is no special, unique set-up behavior for the

/// One sample use is to store local references to other objects in the
/// scene which would facilitate computing this agents observation.
/// </remarks>
public virtual void Initialize()
{
#pragma warning disable 0618
InitializeAgent();
#pragma warning restore 0618
}
public virtual void Initialize(){}
/// <summary>
/// When the Agent uses Heuristics, it will call this method every time it

/// <returns> A float array corresponding to the next action of the Agent
/// </returns>
public virtual float[] Heuristic()
public virtual void Heuristic(float[] actionsOut)
var param = m_PolicyFactory.brainParameters;
return new float[param.numActions];
Array.Clear(actionsOut, 0, actionsOut.Length);
}
/// <summary>

{
}
[Obsolete("AgentAction() has been deprecated, use OnActionReceived() instead.")]
public virtual void AgentAction(float[] vectorAction)
{
}
/// <summary>
/// Specifies the agent behavior at every step based on the provided
/// action.

/// will be of length 1.
/// </param>
public virtual void OnActionReceived(float[] vectorAction)
{
#pragma warning disable 0618
AgentAction(m_Action.vectorActions);
#pragma warning restore 0618
}
[Obsolete("AgentReset() has been deprecated, use OnEpisodeBegin() instead.")]
public virtual void AgentReset()
{
}
public virtual void OnActionReceived(float[] vectorAction){}
/// <summary>
/// Specifies the agent behavior when being reset, which can be due to

public virtual void OnEpisodeBegin()
{
#pragma warning disable 0618
AgentReset();
#pragma warning restore 0618
}
public virtual void OnEpisodeBegin(){}
/// <summary>
/// Returns the last action that was decided on by the Agent

51
com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs


#region Initialization
internal static bool CheckCommunicationVersionsAreCompatible(
string unityCommunicationVersion,
string pythonApiVersion,
string pythonLibraryVersion)
{
var unityVersion = new Version(unityCommunicationVersion);
var pythonVersion = new Version(pythonApiVersion);
if (unityVersion.Major == 0)
{
if (unityVersion.Major != pythonVersion.Major || unityVersion.Minor != pythonVersion.Minor)
{
return false;
}
}
else if (unityVersion.Major != pythonVersion.Major)
{
return false;
}
else if (unityVersion.Minor != pythonVersion.Minor)
{
// Even if we initialize, we still want to check to make sure that we inform users of minor version
// changes. This will surface any features that may not work due to minor version incompatibilities.
Debug.LogWarningFormat(
"WARNING: The communication API versions between Unity and python differ at the minor version level. " +
"Python API: {0}, Unity API: {1} Python Library Version: {2} .\n" +
"This means that some features may not work unless you upgrade the package with the lower version." +
"Please find the versions that work best together from our release page.\n" +
"https://github.com/Unity-Technologies/ml-agents/releases",
pythonApiVersion, unityCommunicationVersion, pythonLibraryVersion
);
}
return true;
}
/// <summary>
/// Sends the initialization parameters through the Communicator.
/// Is used by the academy to send initialization parameters to the communicator.

},
out input);
var pythonCommunicationVersion = initializationInput.RlInitializationInput.CommunicationVersion;
var pythonPackageVersion = initializationInput.RlInitializationInput.PackageVersion;
var unityCommunicationVersion = initParameters.unityCommunicationVersion;
var communicationIsCompatible = CheckCommunicationVersionsAreCompatible(unityCommunicationVersion,
pythonCommunicationVersion,
pythonPackageVersion);
var pythonCommunicationVersion = initializationInput.RlInitializationInput.CommunicationVersion;
var pythonPackageVersion = initializationInput.RlInitializationInput.PackageVersion;
if (pythonCommunicationVersion != initParameters.unityCommunicationVersion)
if (!communicationIsCompatible)
"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 " +
"versions which make them incompatible. Python library version: {2}.",
pythonCommunicationVersion, initParameters.unityCommunicationVersion,
pythonPackageVersion
);

8
com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs


get { return m_BehaviorName + "?team=" + TeamId; }
}
internal IPolicy GeneratePolicy(Func<float[]> heuristic)
internal IPolicy GeneratePolicy(HeuristicPolicy.ActionGenerator heuristic)
return new HeuristicPolicy(heuristic);
return new HeuristicPolicy(heuristic, m_BrainParameters.numActions);
case BehaviorType.InferenceOnly:
{
if (m_Model == null)

}
else
{
return new HeuristicPolicy(heuristic);
return new HeuristicPolicy(heuristic, m_BrainParameters.numActions);
return new HeuristicPolicy(heuristic);
return new HeuristicPolicy(heuristic, m_BrainParameters.numActions);
}
}

11
com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs


/// </summary>
internal class HeuristicPolicy : IPolicy
{
Func<float[]> m_Heuristic;
public delegate void ActionGenerator(float[] actionsOut);
ActionGenerator m_Heuristic;
int m_numActions;
WriteAdapter m_WriteAdapter = new WriteAdapter();
NullList m_NullList = new NullList();

public HeuristicPolicy(Func<float[]> heuristic)
public HeuristicPolicy(ActionGenerator heuristic, int numActions)
m_numActions = numActions;
}
/// <inheritdoc />

if (!info.done)
{
m_LastDecision = m_Heuristic.Invoke();
// Reset m_LastDecision each time.
m_LastDecision = new float[m_numActions];
m_Heuristic.Invoke(m_LastDecision);
}
}

4
com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs


[TestFixture]
public class BehaviorParameterTests
{
static float[] DummyHeuristic()
static void DummyHeuristic(float[] actionsOut)
return null;
// No-op
}
[Test]

3
com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs


agentActionCallsForEpisode = 0;
}
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
return new float[0];
}
}

8
com.unity.ml-agents/Tests/Runtime/RuntimeAPITest.cs


{
public int numHeuristicCalls;
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
return base.Heuristic();
base.Heuristic(actionsOut);
}// Simple SensorComponent that sets up a StackingSensor
}
// Simple SensorComponent that sets up a StackingSensor
public class StackingComponent : SensorComponent
{
public SensorComponent wrappedComponent;

2
com.unity.ml-agents/package.json


"unity": "2018.4",
"description": "Add interactivity to your game with Machine Learning Agents trained using Deep Reinforcement Learning.",
"dependencies": {
"com.unity.barracuda": "0.6.1-preview"
"com.unity.barracuda": "0.6.3-preview"
}
}

2
docs/Getting-Started.md


step.
* `Agent.Heuristic()` - When the `Behavior Type` is set to `Heuristic Only` in the Behavior
Parameters of the Agent, the Agent will use the `Heuristic()` method to generate
the actions of the Agent. As such, the `Heuristic()` method returns an array of
the actions of the Agent. As such, the `Heuristic()` method takes an array of
floats. In the case of the Ball 3D Agent, the `Heuristic()` method converts the
keyboard inputs into actions.

8
docs/Learning-Environment-Create-New.md


The `Heuristic()` method will look like this :
```csharp
public override float[] Heuristic()
public override void Heuristic(float[] actionsOut)
var action = new float[2];
action[0] = Input.GetAxis("Horizontal");
action[1] = Input.GetAxis("Vertical");
return action;
actionsOut[0] = Input.GetAxis("Horizontal");
actionsOut[1] = Input.GetAxis("Vertical");
}
```

3
docs/Learning-Environment-Design-Agents.md


Note that when you are programming actions for an agent, it is often helpful to
test your action logic using the `Heuristic()` method of the Agent,
which lets you map keyboard
commands to actions.
which lets you map keyboard commands to actions.
The [3DBall](Learning-Environment-Examples.md#3dball-3d-balance-ball) and
[Area](Learning-Environment-Examples.md#push-block) example environments are set

12
docs/Migrating.md


* Running with the same `--run-id` twice will now throw an error.
* Removed the multi-agent gym option from the gym wrapper. For multi-agent scenarios, use the [Low Level Python API](Python-API.md).
* The low level Python API has changed. You can look at the document [Low Level Python API documentation](Python-API.md) for more information. If you use `mlagents-learn` for training, this should be a transparent change.
* The `play_against_current_self_ratio` self-play trainer hyperparameter has been renamed to `play_against_latest_model_ratio`
* The Jupyter notebooks have been removed from the repository.
* `Academy.FloatProperties` was removed.
* `Academy.RegisterSideChannel` and `Academy.UnregisterSideChannel` were removed.
* The obsolete `Agent` methods `GiveModel`, `Done`, `InitializeAgent`, `AgentAction` and `AgentReset` have been removed.
* The signature of `Agent.Heuristic()` was changed to take a `float[]` as a parameter, instead of returning the array. This was done to prevent a common source of error where users would return arrays of the wrong size.
* The Jupyter notebooks have been removed from the repository.
* `Academy.FloatProperties` was removed.
* `Academy.RegisterSideChannel` and `Academy.UnregisterSideChannel` were removed.
* If your Agent class overrides `Heuristic()`, change the signature to `public override void Heuristic(float[] actionsOut)` and assign values to `actionsOut` instead of returning an array.
## Migrating from 0.14 to 0.15

63
ml-agents-envs/mlagents_envs/environment.py


import atexit
from distutils.version import StrictVersion
import glob
import uuid
import numpy as np

import signal
import struct
logger = get_logger(__name__)

# Command line argument used to pass the port to the executable environment.
PORT_COMMAND_LINE_ARG = "--mlagents-port"
@staticmethod
def _raise_version_exception(unity_com_ver: str) -> None:
raise UnityEnvironmentException(
f"The communication API version is not compatible between Unity and python. "
f"Python API: {UnityEnvironment.API_VERSION}, Unity API: {unity_com_ver}.\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."
)
@staticmethod
def check_communication_compatibility(
unity_com_ver: str, python_api_version: str, unity_package_version: str
) -> bool:
unity_communicator_version = StrictVersion(unity_com_ver)
api_version = StrictVersion(python_api_version)
if unity_communicator_version.version[0] == 0:
if (
unity_communicator_version.version[0] != api_version.version[0]
or unity_communicator_version.version[1] != api_version.version[1]
):
# Minor beta versions differ.
return False
elif unity_communicator_version.version[0] != api_version.version[0]:
# Major versions mismatch.
return False
elif unity_communicator_version.version[1] != api_version.version[1]:
# Non-beta minor versions mismatch. Log a warning but allow execution to continue.
logger.warning(
f"WARNING: The communication API versions between Unity and python differ at the minor version level. "
f"Python API: {python_api_version}, Unity API: {unity_communicator_version}.\n"
f"This means that some features may not work unless you upgrade the package with the lower version."
f"Please find the versions that work best together from our release page.\n"
"https://github.com/Unity-Technologies/ml-agents/releases"
)
else:
logger.info(
f"Connected to Unity environment with package version {unity_package_version} "
f"and communication version {unity_com_ver}"
)
return True
def __init__(
self,
file_name: Optional[str] = None,

self._close(0)
raise
unity_communicator_version = aca_params.communication_version
if unity_communicator_version != UnityEnvironment.API_VERSION:
if not UnityEnvironment.check_communication_compatibility(
aca_params.communication_version,
UnityEnvironment.API_VERSION,
aca_params.package_version,
):
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"Please go to https://github.com/Unity-Technologies/ml-agents/releases/tag/latest_release "
f"to download the latest version of ML-Agents."
)
else:
logger.info(
f"Connected to Unity environment with package version {aca_params.package_version} "
f"and communication version {aca_params.communication_version}"
)
UnityEnvironment._raise_version_exception(aca_params.communication_version)
self._env_state: Dict[str, Tuple[DecisionSteps, TerminalSteps]] = {}
self._env_specs: Dict[str, BehaviorSpec] = {}
self._env_actions: Dict[str, np.ndarray] = {}

31
ml-agents-envs/mlagents_envs/tests/test_envs.py


assert comm.has_been_closed
def test_check_communication_compatibility():
unity_ver = "1.0.0"
python_ver = "1.0.0"
unity_package_version = "0.15.0"
assert UnityEnvironment.check_communication_compatibility(
unity_ver, python_ver, unity_package_version
)
unity_ver = "1.1.0"
assert UnityEnvironment.check_communication_compatibility(
unity_ver, python_ver, unity_package_version
)
unity_ver = "2.0.0"
assert not UnityEnvironment.check_communication_compatibility(
unity_ver, python_ver, unity_package_version
)
unity_ver = "0.16.0"
python_ver = "0.16.0"
assert UnityEnvironment.check_communication_compatibility(
unity_ver, python_ver, unity_package_version
)
unity_ver = "0.17.0"
assert not UnityEnvironment.check_communication_compatibility(
unity_ver, python_ver, unity_package_version
)
unity_ver = "1.16.0"
assert not UnityEnvironment.check_communication_compatibility(
unity_ver, python_ver, unity_package_version
)
def test_returncode_to_signal_name():
assert UnityEnvironment.returncode_to_signal_name(-2) == "SIGINT"
assert UnityEnvironment.returncode_to_signal_name(42) is None

3
com.unity.ml-agents/Tests/Editor/Communicator.meta


fileFormatVersion: 2
guid: da8f640243c749388a0329393c8fce64
timeCreated: 1586386315

55
com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs


using System;
using System.Collections;
using System.Text.RegularExpressions;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace MLAgents.Tests.Communicator
{
[TestFixture]
public class RpcCommunicatorTests
{
[Test]
public void TestCheckCommunicationVersionsAreCompatible()
{
var unityVerStr = "1.0.0";
var pythonVerStr = "1.0.0";
var pythonPackageVerStr = "0.16.0";
Assert.IsTrue(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr,
pythonVerStr,
pythonPackageVerStr));
LogAssert.NoUnexpectedReceived();
pythonVerStr = "1.1.0";
Assert.IsTrue(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr,
pythonVerStr,
pythonPackageVerStr));
// Ensure that a warning was printed.
LogAssert.Expect(LogType.Warning, new Regex("(.\\s)+"));
unityVerStr = "2.0.0";
Assert.IsFalse(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr,
pythonVerStr,
pythonPackageVerStr));
unityVerStr = "0.15.0";
pythonVerStr = "0.15.0";
Assert.IsTrue(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr,
pythonVerStr,
pythonPackageVerStr));
unityVerStr = "0.16.0";
Assert.IsFalse(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr,
pythonVerStr,
pythonPackageVerStr));
unityVerStr = "1.15.0";
Assert.IsFalse(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr,
pythonVerStr,
pythonPackageVerStr));
}
}
}

3
com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs.meta


fileFormatVersion: 2
guid: 251fab8dff424abb95b2b381c7c924c3
timeCreated: 1586386329
正在加载...
取消
保存