浏览代码

Don't clamp timescale to 100 outside of editor (#4867)

* Don't clamp timescale to 100 outside of editor

* fix dumb typo
/MLA-1734-demo-provider
GitHub 4 年前
当前提交
e3b868bb
共有 8 个文件被更改,包括 62 次插入2 次删除
  1. 2
      com.unity.ml-agents/CHANGELOG.md
  2. 12
      com.unity.ml-agents/Runtime/SideChannels/EngineConfigurationChannel.cs
  3. 3
      com.unity.ml-agents/Tests/Editor/SideChannels.meta
  4. 44
      com.unity.ml-agents/Tests/Editor/SideChannels/EngineConfigurationChannelTests.cs
  5. 3
      com.unity.ml-agents/Tests/Editor/SideChannels/EngineConfigurationChannelTests.cs.meta
  6. 0
      /com.unity.ml-agents/Tests/Editor/SideChannels/SideChannelTests.cs.meta
  7. 0
      /com.unity.ml-agents/Tests/Editor/SideChannels/SideChannelTests.cs

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


- `StatAggregationMethod.Sum` can now be passed to `StatsRecorder.Add()`. This
will result in the values being summed (instead of averaged) when written to
TensorBoard. Thanks to @brccabral for the contribution! (#4816)
- The upper limit for the time scale (by setting the `--time-scale` paramater in mlagents-learn) was
removed when training with a player. The Editor still requires it to be clamped to 100. (#4867)
#### ml-agents / ml-agents-envs / gym-unity (Python)

12
com.unity.ml-agents/Runtime/SideChannels/EngineConfigurationChannel.cs


/// </summary>
internal class EngineConfigurationChannel : SideChannel
{
enum ConfigurationType : int
internal enum ConfigurationType : int
{
ScreenResolution = 0,
QualityLevel = 1,

break;
case ConfigurationType.TimeScale:
var timeScale = msg.ReadFloat32();
timeScale = Mathf.Clamp(timeScale, 1, 100);
// There's an upper limit for the timeScale in the editor (but not in the player)
// Always ensure that timeScale >= 1 also,
#if UNITY_EDITOR
const float maxTimeScale = 100f;
#else
const float maxTimeScale = float.PositiveInfinity;
#endif
timeScale = Mathf.Clamp(timeScale, 1, maxTimeScale);
Time.timeScale = timeScale;
break;
case ConfigurationType.TargetFrameRate:

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


fileFormatVersion: 2
guid: 1228f198ceee45a38c7d9ff50425b65d
timeCreated: 1610760867

44
com.unity.ml-agents/Tests/Editor/SideChannels/EngineConfigurationChannelTests.cs


using NUnit.Framework;
using Unity.MLAgents.SideChannels;
using UnityEngine;
namespace Unity.MLAgents.Tests
{
public class EngineConfigurationChannelTests
{
float m_OldTimeScale = 1.0f;
[SetUp]
public void Setup()
{
m_OldTimeScale = Time.timeScale;
}
[TearDown]
public void TearDown()
{
Time.timeScale = m_OldTimeScale;
}
[Test]
public void TestTimeScaleClamping()
{
OutgoingMessage pythonMsg = new OutgoingMessage();
pythonMsg.WriteInt32((int)EngineConfigurationChannel.ConfigurationType.TimeScale);
pythonMsg.WriteFloat32(1000f);
var sideChannel = new EngineConfigurationChannel();
sideChannel.ProcessMessage(pythonMsg.ToByteArray());
#if UNITY_EDITOR
// Should be clamped
Assert.AreEqual(100.0f, Time.timeScale);
#else
// Not sure we can run this test from a player, but just in case, shouldn't clamp.
Assert.AreEqual(1000.0f, Time.timeScale);
#endif
}
}
}

3
com.unity.ml-agents/Tests/Editor/SideChannels/EngineConfigurationChannelTests.cs.meta


fileFormatVersion: 2
guid: 71aa620295f74ca5875e8e4782f08768
timeCreated: 1610760906

/com.unity.ml-agents/Tests/Editor/SideChannelTests.cs.meta → /com.unity.ml-agents/Tests/Editor/SideChannels/SideChannelTests.cs.meta

/com.unity.ml-agents/Tests/Editor/SideChannelTests.cs → /com.unity.ml-agents/Tests/Editor/SideChannels/SideChannelTests.cs

正在加载...
取消
保存