浏览代码

Merge branch 'master' into asymm-envs

/asymm-envs
Andrew Cohen 5 年前
当前提交
22786526
共有 33 个文件被更改,包括 63 次插入50 次删除
  1. 2
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
  2. 2
      Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs
  3. 1
      com.unity.ml-agents/.npmignore
  4. 8
      com.unity.ml-agents/CHANGELOG.md
  5. 2
      com.unity.ml-agents/Editor/BehaviorParametersEditor.cs
  6. 4
      com.unity.ml-agents/Editor/Unity.ML-Agents.Editor.asmdef
  7. 2
      com.unity.ml-agents/Runtime/Academy.cs
  8. 2
      com.unity.ml-agents/Runtime/Agent.cs
  9. 2
      com.unity.ml-agents/Runtime/Inference/ApplierImpl.cs
  10. 10
      com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs
  11. 2
      com.unity.ml-agents/Runtime/Inference/GeneratorImpl.cs
  12. 2
      com.unity.ml-agents/Runtime/Inference/ModelRunner.cs
  13. 2
      com.unity.ml-agents/Runtime/Inference/TensorApplier.cs
  14. 2
      com.unity.ml-agents/Runtime/Inference/TensorGenerator.cs
  15. 2
      com.unity.ml-agents/Runtime/Inference/TensorProxy.cs
  16. 2
      com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs
  17. 2
      com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  18. 2
      com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs
  19. 4
      com.unity.ml-agents/Runtime/Unity.ML-Agents.asmdef
  20. 2
      com.unity.ml-agents/Tests/Editor/DiscreteActionOutputApplierTest.cs
  21. 2
      com.unity.ml-agents/Tests/Editor/EditModeTestInternalBrainTensorApplier.cs
  22. 2
      com.unity.ml-agents/Tests/Editor/EditModeTestInternalBrainTensorGenerator.cs
  23. 2
      com.unity.ml-agents/Tests/Editor/ModelRunnerTest.cs
  24. 2
      com.unity.ml-agents/Tests/Editor/ParameterLoaderTest.cs
  25. 2
      com.unity.ml-agents/Tests/Editor/Sensor/ObservationWriterTests.cs
  26. 2
      com.unity.ml-agents/Tests/Editor/TensorUtilsTest.cs
  27. 4
      com.unity.ml-agents/Tests/Editor/Unity.ML-Agents.Editor.Tests.asmdef
  28. 2
      com.unity.ml-agents/Tests/Runtime/Unity.ML-Agents.Runtime.Tests.asmdef
  29. 4
      com.unity.ml-agents/package.json
  30. 17
      ml-agents/mlagents/trainers/ghost/controller.py
  31. 3
      ml-agents/mlagents/trainers/tests/simple_test_envs.py
  32. 9
      ml-agents/mlagents/trainers/tests/test_trainer_controller.py
  33. 5
      ml-agents/mlagents/trainers/trainer_controller.py

2
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using Barracuda;
using Unity.Barracuda;
using System.IO;
using MLAgents;
using MLAgents.Policies;

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


using System.Collections;
using UnityEngine;
using MLAgents;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Sensors;
using MLAgents.SideChannels;

1
com.unity.ml-agents/.npmignore


build.sh.meta
build.bat
build.bat.meta
upm-ci.log

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


## [Unreleased]
### Major Changes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
## [1.0.0-preview] - 2020-05-06

C# style conventions. All public fields and properties now use "PascalCase"
instead of "camelCase"; for example, `Agent.maxStep` was renamed to
`Agent.MaxStep`. For a full list of changes, see the pull request. (#3828)
- Update Barracuda to 0.7.0-preview which has breaking namespace and assembly name changes.
### Minor Changes

- `StackingSensor` was changed from `internal` visibility to `public`
- Academy.InferenceSeed property was added. This is used to initialize the
random number generator in ModelRunner, and is incremented for each ModelRunner. (#3823)
- Updated Barracuda to 0.6.3-preview.
- Added `Agent.GetObservations(), which returns a read-only view of the observations
added in `CollectObservations()`. (#3825)
- Model updates can now happen asynchronously with environment steps for better performance. (#3690)

2
com.unity.ml-agents/Editor/BehaviorParametersEditor.cs


using MLAgents.Sensors;
using UnityEditor;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Policies;
using UnityEngine;

4
com.unity.ml-agents/Editor/Unity.ML-Agents.Editor.asmdef


"name": "Unity.ML-Agents.Editor",
"references": [
"Unity.ML-Agents",
"Barracuda",
"Unity.Barracuda",
"Unity.ML-Agents.CommunicatorObjects"
],
"optionalUnityReferences": [],

"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": []
}
}

2
com.unity.ml-agents/Runtime/Academy.cs


using MLAgents.Inference;
using MLAgents.Policies;
using MLAgents.SideChannels;
using Barracuda;
using Unity.Barracuda;
/**
* Welcome to Unity Machine Learning Agents (ML-Agents).

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


using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Sensors;
using MLAgents.Demonstrations;
using MLAgents.Policies;

2
com.unity.ml-agents/Runtime/Inference/ApplierImpl.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference.Utils;
using UnityEngine;

10
com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs


using System;
using System.Collections.Generic;
using System.Linq;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Sensors;
using MLAgents.Policies;

"suggest Continuous Control.");
return failedModelChecks;
}
var tensorTester = new Dictionary<string, Func<BrainParameters, TensorShape, int, string>>();
var tensorTester = new Dictionary<string, Func<BrainParameters, TensorShape?, int, string>>();
if (brainParameters.VectorActionSpaceType == SpaceType.Continuous)
{
tensorTester[TensorNames.ActionOutput] = CheckContinuousActionOutputShape;

{
if (tensorTester.ContainsKey(name))
{
var tester = tensorTester[name];
Func<BrainParameters, TensorShape?, int, string> tester = tensorTester[name];
var error = tester.Invoke(brainParameters, model.GetShapeByName(name), modelActionSize);
if (error != null)
{

/// check failed. If the check passed, returns null.
/// </returns>
static string CheckDiscreteActionOutputShape(
BrainParameters brainParameters, TensorShape shape, int modelActionSize)
BrainParameters brainParameters, TensorShape? shape, int modelActionSize)
{
var bpActionSize = brainParameters.VectorActionSize.Sum();
if (modelActionSize != bpActionSize)

/// <returns>If the Check failed, returns a string containing information about why the
/// check failed. If the check passed, returns null.</returns>
static string CheckContinuousActionOutputShape(
BrainParameters brainParameters, TensorShape shape, int modelActionSize)
BrainParameters brainParameters, TensorShape? shape, int modelActionSize)
{
var bpActionSize = brainParameters.VectorActionSize[0];
if (modelActionSize != bpActionSize)

2
com.unity.ml-agents/Runtime/Inference/GeneratorImpl.cs


using System.Collections.Generic;
using System;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference.Utils;
using UnityEngine;
using MLAgents.Sensors;

2
com.unity.ml-agents/Runtime/Inference/ModelRunner.cs


using System.Collections.Generic;
using Barracuda;
using Unity.Barracuda;
using UnityEngine.Profiling;
using MLAgents.Sensors;
using MLAgents.Policies;

2
com.unity.ml-agents/Runtime/Inference/TensorApplier.cs


using System.Collections.Generic;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Policies;
namespace MLAgents.Inference

2
com.unity.ml-agents/Runtime/Inference/TensorGenerator.cs


using System.Collections.Generic;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Sensors;
namespace MLAgents.Inference

2
com.unity.ml-agents/Runtime/Inference/TensorProxy.cs


using System;
using System.Collections.Generic;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference.Utils;
namespace MLAgents.Inference

2
com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs


using Barracuda;
using Unity.Barracuda;
using System.Collections.Generic;
using MLAgents.Inference;
using MLAgents.Sensors;

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


using Barracuda;
using Unity.Barracuda;
using System;
using UnityEngine;
using UnityEngine.Serialization;

2
com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs


using System;
using System.Collections.Generic;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference;
namespace MLAgents.Sensors

4
com.unity.ml-agents/Runtime/Unity.ML-Agents.asmdef


{
"name": "Unity.ML-Agents",
"references": [
"Barracuda",
"Unity.Barracuda",
"Unity.ML-Agents.CommunicatorObjects"
],
"optionalUnityReferences": [],

],
"autoReferenced": true,
"defineConstraints": []
}
}

2
com.unity.ml-agents/Tests/Editor/DiscreteActionOutputApplierTest.cs


using System;
using Barracuda;
using Unity.Barracuda;
using NUnit.Framework;
using UnityEngine;
using MLAgents.Inference;

2
com.unity.ml-agents/Tests/Editor/EditModeTestInternalBrainTensorApplier.cs


using System.Collections.Generic;
using NUnit.Framework;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference;
using MLAgents.Policies;

2
com.unity.ml-agents/Tests/Editor/EditModeTestInternalBrainTensorGenerator.cs


using System.Collections.Generic;
using Barracuda;
using Unity.Barracuda;
using NUnit.Framework;
using UnityEngine;
using MLAgents.Inference;

2
com.unity.ml-agents/Tests/Editor/ModelRunnerTest.cs


using NUnit.Framework;
using UnityEngine;
using UnityEditor;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference;
using MLAgents.Sensors;
using System.Linq;

2
com.unity.ml-agents/Tests/Editor/ParameterLoaderTest.cs


using NUnit.Framework;
using UnityEngine;
using UnityEditor;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference;
using MLAgents.Sensors;
using System.Linq;

2
com.unity.ml-agents/Tests/Editor/Sensor/ObservationWriterTests.cs


using NUnit.Framework;
using MLAgents.Sensors;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference;

2
com.unity.ml-agents/Tests/Editor/TensorUtilsTest.cs


using System;
using Barracuda;
using Unity.Barracuda;
using MLAgents.Inference;
using MLAgents.Inference.Utils;
using NUnit.Framework;

4
com.unity.ml-agents/Tests/Editor/Unity.ML-Agents.Editor.Tests.asmdef


"references": [
"Unity.ML-Agents.Editor",
"Unity.ML-Agents",
"Barracuda",
"Unity.Barracuda",
"Unity.ML-Agents.CommunicatorObjects"
],
"optionalUnityReferences": [

"defineConstraints": [
"UNITY_INCLUDE_TESTS"
]
}
}

2
com.unity.ml-agents/Tests/Runtime/Unity.ML-Agents.Runtime.Tests.asmdef


"name": "Tests",
"references": [
"Unity.ML-Agents",
"Barracuda",
"Unity.Barracuda",
"Unity.ML-Agents.CommunicatorObjects",
"Unity.ML-Agents.Editor"
],

4
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.3-preview"
"com.unity.barracuda": "0.7.0-preview"
}
}

17
ml-agents/mlagents/trainers/ghost/controller.py


self._learning_team: int = -1
# Dict from team id to GhostTrainer for ELO calculation
self._ghost_trainers: Dict[int, GhostTrainer] = {}
# Signals to the trainer control to perform a hard reset
self._reset = False
# Signals to the trainer control to perform a hard change_training_team
self._changed_training_team = False
@property
def get_learning_team(self) -> int:

"""
return self._learning_team
@property
def reset(self) -> bool:
def should_reset(self) -> bool:
change_team = self._reset
if self._reset:
self._reset = False
return change_team
changed_team = self._changed_training_team
if self._changed_training_team:
self._changed_training_team = False
return changed_team
def subscribe_team_id(self, team_id: int, trainer: GhostTrainer) -> None:
"""

logger.debug(
"Learning team {} swapped on step {}".format(self._learning_team, step)
)
self._reset = True
self._changed_training_team = True
# Adapted from https://github.com/Unity-Technologies/ml-agents/pull/1975 and
# https://metinmediamath.wordpress.com/2013/11/27/how-to-calculate-the-elo-rating-including-example/

3
ml-agents/mlagents/trainers/tests/simple_test_envs.py


self.goal[name] = self.random.choice([-1, 1])
self.positions[name] = [0.0 for _ in range(self.action_size)]
self.step_count[name] = 0
self.final_rewards[name].append(self.rewards[name])
self.rewards[name] = 0
self.agent_id[name] = self.agent_id[name] + 1

decision_step = DecisionSteps(m_vector_obs, m_reward, m_agent_id, action_mask)
terminal_step = TerminalSteps.empty(self.behavior_spec)
if done:
self.final_rewards[name].append(self.rewards[name])
self._reset_agent(name)
new_vector_obs = self._make_obs(self.goal[name])
(

decision_step = DecisionSteps(m_vector_obs, m_reward, m_agent_id, action_mask)
terminal_step = TerminalSteps.empty(self.behavior_spec)
if done:
self.final_rewards[name].append(self.rewards[name])
self._reset_agent(name)
recurrent_obs_val = (
self.goal[name] if self.step_count[name] <= self.num_show_steps else 0

9
ml-agents/mlagents/trainers/tests/test_trainer_controller.py


from mlagents.tf_utils import tf
from mlagents.trainers.trainer_controller import TrainerController
from mlagents.trainers.ghost.controller import GhostController
trainer_factory_mock = MagicMock()
trainer_factory_mock.ghost_controller = GhostController()
trainer_factory=None,
trainer_factory=trainer_factory_mock,
model_path="test_model_path",
summaries_dir="test_summaries_dir",
run_id="test_run_id",

@patch.object(tf, "set_random_seed")
def test_initialization_seed(numpy_random_seed, tensorflow_set_seed):
seed = 27
trainer_factory_mock = MagicMock()
trainer_factory_mock.ghost_controller = GhostController()
trainer_factory=None,
trainer_factory=trainer_factory_mock,
model_path="",
summaries_dir="",
run_id="1",

5
ml-agents/mlagents/trainers/trainer_controller.py


self.meta_curriculum = meta_curriculum
self.sampler_manager = sampler_manager
self.resampling_interval = resampling_interval
self.ghost_controller = ghost_controller
self.ghost_controller = self.trainer_factory.ghost_controller
self.trainer_threads: List[threading.Thread] = []
self.kill_trainers = False

and (self.resampling_interval)
and (steps % self.resampling_interval == 0)
)
if meta_curriculum_reset or generalization_reset or self.ghost_controller.reset:
ghost_controller_reset = self.ghost_controller.should_reset()
if meta_curriculum_reset or generalization_reset or ghost_controller_reset:
self.end_trainer_episodes(env, lessons_incremented)
@timed

正在加载...
取消
保存