Ervin Teng
5 年前
当前提交
06fa3d39
共有 113 个文件被更改,包括 1991 次插入 和 966 次删除
-
2.pylintrc
-
4.yamato/standalone-build-test.yml
-
7.yamato/training-int-tests.yml
-
8Dockerfile
-
30Project/Assets/ML-Agents/Editor/Tests/StandaloneBuildTest.cs
-
2Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
-
2Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs
-
2Project/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs
-
5Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs
-
12Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorSettings.cs
-
18Project/Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity
-
3Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
-
2Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridArea.cs
-
3Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridSettings.cs
-
5Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs
-
3Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAgent.cs
-
3Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ProjectSettingsOverrides.cs
-
3Project/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerFieldArea.cs
-
2Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
-
2Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs
-
13Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs
-
4README.md
-
22com.unity.ml-agents/CHANGELOG.md
-
43com.unity.ml-agents/Runtime/Academy.cs
-
3com.unity.ml-agents/Runtime/Agent.cs
-
13com.unity.ml-agents/Runtime/Communicator/ICommunicator.cs
-
184com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
-
5com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
-
20com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs
-
7com.unity.ml-agents/Runtime/SideChannels/EngineConfigurationChannel.cs
-
2com.unity.ml-agents/Runtime/SideChannels/SideChannel.cs
-
8com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs
-
30com.unity.ml-agents/Tests/Editor/PublicAPI/PublicApiValidation.cs
-
16com.unity.ml-agents/Tests/Editor/SideChannelTests.cs
-
6config/trainer_config.yaml
-
10docs/Custom-SideChannels.md
-
23docs/Getting-Started.md
-
3docs/Installation.md
-
7docs/Learning-Environment-Create-New.md
-
1docs/Learning-Environment-Design-Agents.md
-
1docs/Learning-Environment-Examples.md
-
8docs/Learning-Environment-Executable.md
-
17docs/Migrating.md
-
11docs/Python-API.md
-
1docs/Readme.md
-
4docs/Training-Curriculum-Learning.md
-
6docs/Training-Environment-Parameter-Randomization.md
-
38docs/Training-ML-Agents.md
-
98docs/Training-Self-Play.md
-
9docs/Using-Docker.md
-
7docs/Using-Tensorboard.md
-
2gym-unity/README.md
-
34gym-unity/gym_unity/envs/__init__.py
-
48gym-unity/gym_unity/tests/test_gym.py
-
2ml-agents-envs/mlagents_envs/communicator.py
-
117ml-agents-envs/mlagents_envs/environment.py
-
3ml-agents-envs/mlagents_envs/mock_communicator.py
-
3ml-agents-envs/mlagents_envs/rpc_communicator.py
-
4ml-agents-envs/mlagents_envs/side_channel/outgoing_message.py
-
4ml-agents-envs/mlagents_envs/side_channel/side_channel.py
-
23ml-agents-envs/mlagents_envs/tests/test_envs.py
-
5ml-agents/mlagents/model_serialization.py
-
52ml-agents/mlagents/trainers/agent_processor.py
-
52ml-agents/mlagents/trainers/behavior_id_utils.py
-
5ml-agents/mlagents/trainers/components/reward_signals/__init__.py
-
4ml-agents/mlagents/trainers/curriculum.py
-
38ml-agents/mlagents/trainers/distributions.py
-
15ml-agents/mlagents/trainers/env_manager.py
-
439ml-agents/mlagents/trainers/ghost/trainer.py
-
145ml-agents/mlagents/trainers/learn.py
-
4ml-agents/mlagents/trainers/meta_curriculum.py
-
1ml-agents/mlagents/trainers/policy/nn_policy.py
-
34ml-agents/mlagents/trainers/policy/tf_policy.py
-
11ml-agents/mlagents/trainers/ppo/trainer.py
-
5ml-agents/mlagents/trainers/sac/optimizer.py
-
11ml-agents/mlagents/trainers/sac/trainer.py
-
6ml-agents/mlagents/trainers/simple_env_manager.py
-
47ml-agents/mlagents/trainers/stats.py
-
124ml-agents/mlagents/trainers/subprocess_env_manager.py
-
80ml-agents/mlagents/trainers/tests/simple_test_envs.py
-
43ml-agents/mlagents/trainers/tests/test_agent_processor.py
-
10ml-agents/mlagents/trainers/tests/test_distributions.py
-
36ml-agents/mlagents/trainers/tests/test_ghost.py
-
48ml-agents/mlagents/trainers/tests/test_learn.py
-
4ml-agents/mlagents/trainers/tests/test_meta_curriculum.py
-
129ml-agents/mlagents/trainers/tests/test_simple_rl.py
-
30ml-agents/mlagents/trainers/tests/test_stats.py
-
55ml-agents/mlagents/trainers/tests/test_subprocess_env_manager.py
-
22ml-agents/mlagents/trainers/tests/test_trainer_util.py
-
10ml-agents/mlagents/trainers/trainer/trainer.py
-
25ml-agents/mlagents/trainers/trainer_controller.py
-
41ml-agents/mlagents/trainers/trainer_util.py
-
2ml-agents/setup.py
-
67ml-agents/tests/yamato/training_int_tests.py
-
69ml-agents/tests/yamato/yamato_utils.py
-
1setup.cfg
-
32.yamato/gym-interface-test.yml
-
32.yamato/python-ll-api-test.yml
-
234com.unity.ml-agents/Runtime/SideChannels/SideChannelUtils.cs
-
11com.unity.ml-agents/Runtime/SideChannels/SideChannelUtils.cs.meta
|
|||
from typing import Dict, NamedTuple |
|||
from typing import NamedTuple |
|||
from urllib.parse import urlparse, parse_qs |
|||
name_behavior_id: str |
|||
""" |
|||
BehaviorIdentifiers is a named tuple of the identifiers that uniquely distinguish |
|||
an agent encountered in the trainer_controller. The named tuple consists of the |
|||
fully qualified behavior name, the name of the brain name (corresponds to trainer |
|||
in the trainer controller) and the team id. In the future, this can be extended |
|||
to support further identifiers. |
|||
""" |
|||
|
|||
behavior_id: str |
|||
behavior_ids: Dict[str, int] |
|||
team_id: int |
|||
Parses a name_behavior_id of the form name?team=0¶m1=i&... |
|||
Parses a name_behavior_id of the form name?team=0 |
|||
This allows you to access the brain name and distinguishing identifiers |
|||
without parsing more than once. |
|||
This allows you to access the brain name and team id of an agent |
|||
ids: Dict[str, int] = {} |
|||
if "?" in name_behavior_id: |
|||
name, identifiers = name_behavior_id.rsplit("?", 1) |
|||
if "&" in identifiers: |
|||
list_of_identifiers = identifiers.split("&") |
|||
else: |
|||
list_of_identifiers = [identifiers] |
|||
|
|||
for identifier in list_of_identifiers: |
|||
key, value = identifier.split("=") |
|||
ids[key] = int(value) |
|||
else: |
|||
name = name_behavior_id |
|||
|
|||
parsed = urlparse(name_behavior_id) |
|||
name = parsed.path |
|||
ids = parse_qs(parsed.query) |
|||
team_id: int = 0 |
|||
if "team" in ids: |
|||
team_id = int(ids["team"][0]) |
|||
name_behavior_id=name_behavior_id, brain_name=name, behavior_ids=ids |
|||
behavior_id=name_behavior_id, brain_name=name, team_id=team_id |
|||
|
|||
|
|||
def create_name_behavior_id(name: str, team_id: int) -> str: |
|||
""" |
|||
Reconstructs fully qualified behavior name from name and team_id |
|||
:param name: brain name |
|||
:param team_id: team ID |
|||
:return: name_behavior_id |
|||
""" |
|||
return name + "?team=" + str(team_id) |
|
|||
test_editors: |
|||
- version: 2019.3 |
|||
--- |
|||
{% for editor in test_editors %} |
|||
test_gym_interface_{{ editor.version }}: |
|||
name: Test Mac Gym Interface {{ editor.version }} |
|||
agent: |
|||
type: Unity::VM::osx |
|||
image: ml-agents/ml-agents-bokken-mac:0.1.4-492264 |
|||
flavor: b1.small |
|||
variables: |
|||
UNITY_VERSION: {{ editor.version }} |
|||
commands: |
|||
- pip install pyyaml |
|||
- python -u -m ml-agents.tests.yamato.setup_venv |
|||
- ./venv/bin/python ml-agents/tests/yamato/scripts/run_gym.py |
|||
dependencies: |
|||
- .yamato/standalone-build-test.yml#test_mac_standalone_{{ editor.version }} |
|||
triggers: |
|||
cancel_old_ci: true |
|||
changes: |
|||
only: |
|||
- "com.unity.ml-agents/**" |
|||
- "Project/**" |
|||
- "ml-agents/**" |
|||
- "ml-agents-envs/**" |
|||
- ".yamato/gym-interface-test.yml" |
|||
except: |
|||
- "*.md" |
|||
- "com.unity.ml-agents/*.md" |
|||
- "com.unity.ml-agents/**/*.md" |
|||
{% endfor %} |
|
|||
test_editors: |
|||
- version: 2019.3 |
|||
--- |
|||
{% for editor in test_editors %} |
|||
test_mac_ll_api_{{ editor.version }}: |
|||
name: Test Mac LL-API {{ editor.version }} |
|||
agent: |
|||
type: Unity::VM::osx |
|||
image: ml-agents/ml-agents-bokken-mac:0.1.4-492264 |
|||
flavor: b1.small |
|||
variables: |
|||
UNITY_VERSION: {{ editor.version }} |
|||
commands: |
|||
- pip install pyyaml |
|||
- python -u -m ml-agents.tests.yamato.setup_venv |
|||
- ./venv/bin/python ml-agents/tests/yamato/scripts/run_llapi.py |
|||
dependencies: |
|||
- .yamato/standalone-build-test.yml#test_mac_standalone_{{ editor.version }} |
|||
triggers: |
|||
cancel_old_ci: true |
|||
changes: |
|||
only: |
|||
- "com.unity.ml-agents/**" |
|||
- "Project/**" |
|||
- "ml-agents/**" |
|||
- "ml-agents-envs/**" |
|||
- ".yamato/python-ll-api-test.yml" |
|||
except: |
|||
- "*.md" |
|||
- "com.unity.ml-agents/*.md" |
|||
- "com.unity.ml-agents/**/*.md" |
|||
{% endfor %} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System.IO; |
|||
|
|||
namespace MLAgents.SideChannels |
|||
{ |
|||
public static class SideChannelUtils |
|||
{ |
|||
|
|||
private static Dictionary<Guid, SideChannel> RegisteredChannels = new Dictionary<Guid, SideChannel>(); |
|||
|
|||
private struct CachedSideChannelMessage |
|||
{ |
|||
public Guid ChannelId; |
|||
public byte[] Message; |
|||
} |
|||
|
|||
private static Queue<CachedSideChannelMessage> m_CachedMessages = new Queue<CachedSideChannelMessage>(); |
|||
|
|||
/// <summary>
|
|||
/// Registers a side channel to the communicator. The side channel will exchange
|
|||
/// messages with its Python equivalent.
|
|||
/// </summary>
|
|||
/// <param name="sideChannel"> The side channel to be registered.</param>
|
|||
public static void RegisterSideChannel(SideChannel sideChannel) |
|||
{ |
|||
var channelId = sideChannel.ChannelId; |
|||
if (RegisteredChannels.ContainsKey(channelId)) |
|||
{ |
|||
throw new UnityAgentsException(string.Format( |
|||
"A side channel with type index {0} is already registered. You cannot register multiple " + |
|||
"side channels of the same id.", channelId)); |
|||
} |
|||
|
|||
// Process any messages that we've already received for this channel ID.
|
|||
var numMessages = m_CachedMessages.Count; |
|||
for (int i = 0; i < numMessages; i++) |
|||
{ |
|||
var cachedMessage = m_CachedMessages.Dequeue(); |
|||
if (channelId == cachedMessage.ChannelId) |
|||
{ |
|||
using (var incomingMsg = new IncomingMessage(cachedMessage.Message)) |
|||
{ |
|||
sideChannel.OnMessageReceived(incomingMsg); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
m_CachedMessages.Enqueue(cachedMessage); |
|||
} |
|||
} |
|||
RegisteredChannels.Add(channelId, sideChannel); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Unregisters a side channel from the communicator.
|
|||
/// </summary>
|
|||
/// <param name="sideChannel"> The side channel to be unregistered.</param>
|
|||
public static void UnregisterSideChannel(SideChannel sideChannel) |
|||
{ |
|||
if (RegisteredChannels.ContainsKey(sideChannel.ChannelId)) |
|||
{ |
|||
RegisteredChannels.Remove(sideChannel.ChannelId); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Unregisters all the side channels from the communicator.
|
|||
/// </summary>
|
|||
public static void UnregisterAllSideChannels() |
|||
{ |
|||
RegisteredChannels = new Dictionary<Guid, SideChannel>(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns the SideChannel of Type T if there is one registered, or null if it doesn't.
|
|||
/// If there are multiple SideChannels of the same type registered, the returned instance is arbitrary.
|
|||
/// </summary>
|
|||
/// <typeparam name="T"></typeparam>
|
|||
/// <returns></returns>
|
|||
public static T GetSideChannel<T>() where T: SideChannel |
|||
{ |
|||
foreach (var sc in RegisteredChannels.Values) |
|||
{ |
|||
if (sc.GetType() == typeof(T)) |
|||
{ |
|||
return (T) sc; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Returns all SideChannels of Type T that are registered. Use <see cref="GetSideChannel{T}()"/> if possible,
|
|||
/// as that does not make any memory allocations.
|
|||
/// </summary>
|
|||
/// <typeparam name="T"></typeparam>
|
|||
/// <returns></returns>
|
|||
public static List<T> GetSideChannels<T>() where T: SideChannel |
|||
{ |
|||
var output = new List<T>(); |
|||
|
|||
foreach (var sc in RegisteredChannels.Values) |
|||
{ |
|||
if (sc.GetType() == typeof(T)) |
|||
{ |
|||
output.Add((T) sc); |
|||
} |
|||
} |
|||
return output; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Grabs the messages that the registered side channels will send to Python at the current step
|
|||
/// into a singe byte array.
|
|||
/// </summary>
|
|||
/// <returns></returns>
|
|||
internal static byte[] GetSideChannelMessage() |
|||
{ |
|||
return GetSideChannelMessage(RegisteredChannels); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Grabs the messages that the registered side channels will send to Python at the current step
|
|||
/// into a singe byte array.
|
|||
/// </summary>
|
|||
/// <param name="sideChannels"> A dictionary of channel type to channel.</param>
|
|||
/// <returns></returns>
|
|||
internal static byte[] GetSideChannelMessage(Dictionary<Guid, SideChannel> sideChannels) |
|||
{ |
|||
using (var memStream = new MemoryStream()) |
|||
{ |
|||
using (var binaryWriter = new BinaryWriter(memStream)) |
|||
{ |
|||
foreach (var sideChannel in sideChannels.Values) |
|||
{ |
|||
var messageList = sideChannel.MessageQueue; |
|||
foreach (var message in messageList) |
|||
{ |
|||
binaryWriter.Write(sideChannel.ChannelId.ToByteArray()); |
|||
binaryWriter.Write(message.Length); |
|||
binaryWriter.Write(message); |
|||
} |
|||
sideChannel.MessageQueue.Clear(); |
|||
} |
|||
return memStream.ToArray(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Separates the data received from Python into individual messages for each registered side channel.
|
|||
/// </summary>
|
|||
/// <param name="dataReceived">The byte array of data received from Python.</param>
|
|||
internal static void ProcessSideChannelData(byte[] dataReceived) |
|||
{ |
|||
ProcessSideChannelData(RegisteredChannels, dataReceived); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Separates the data received from Python into individual messages for each registered side channel.
|
|||
/// </summary>
|
|||
/// <param name="sideChannels">A dictionary of channel type to channel.</param>
|
|||
/// <param name="dataReceived">The byte array of data received from Python.</param>
|
|||
internal static void ProcessSideChannelData(Dictionary<Guid, SideChannel> sideChannels, byte[] dataReceived) |
|||
{ |
|||
while (m_CachedMessages.Count != 0) |
|||
{ |
|||
var cachedMessage = m_CachedMessages.Dequeue(); |
|||
if (sideChannels.ContainsKey(cachedMessage.ChannelId)) |
|||
{ |
|||
using (var incomingMsg = new IncomingMessage(cachedMessage.Message)) |
|||
{ |
|||
sideChannels[cachedMessage.ChannelId].OnMessageReceived(incomingMsg); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
Debug.Log(string.Format( |
|||
"Unknown side channel data received. Channel Id is " |
|||
+ ": {0}", cachedMessage.ChannelId)); |
|||
} |
|||
} |
|||
|
|||
if (dataReceived.Length == 0) |
|||
{ |
|||
return; |
|||
} |
|||
using (var memStream = new MemoryStream(dataReceived)) |
|||
{ |
|||
using (var binaryReader = new BinaryReader(memStream)) |
|||
{ |
|||
while (memStream.Position < memStream.Length) |
|||
{ |
|||
Guid channelId = Guid.Empty; |
|||
byte[] message = null; |
|||
try |
|||
{ |
|||
channelId = new Guid(binaryReader.ReadBytes(16)); |
|||
var messageLength = binaryReader.ReadInt32(); |
|||
message = binaryReader.ReadBytes(messageLength); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
throw new UnityAgentsException( |
|||
"There was a problem reading a message in a SideChannel. Please make sure the " + |
|||
"version of MLAgents in Unity is compatible with the Python version. Original error : " |
|||
+ ex.Message); |
|||
} |
|||
if (sideChannels.ContainsKey(channelId)) |
|||
{ |
|||
using (var incomingMsg = new IncomingMessage(message)) |
|||
{ |
|||
sideChannels[channelId].OnMessageReceived(incomingMsg); |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
// Don't recognize this ID, but cache it in case the SideChannel that can handle
|
|||
// it is registered before the next call to ProcessSideChannelData.
|
|||
m_CachedMessages.Enqueue(new CachedSideChannelMessage |
|||
{ |
|||
ChannelId = channelId, |
|||
Message = message |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2506dff31271f49298fbff21e13fa8b6 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
部分文件因为文件数量过多而无法显示
撰写
预览
正在加载...
取消
保存
Reference in new issue