浏览代码

Move gRPC code to its own special place (#2621)

- exclude .meta files from mixed line ending checks.
- update CommunicatorObjects directory in CI scripts and Proto generation scripts.
/develop-gpu-test
GitHub 5 年前
当前提交
24250c90
共有 38 个文件被更改,包括 151 次插入138 次删除
  1. 5
      .circleci/config.yml
  2. 3
      .pre-commit-config.yaml
  3. 2
      UnitySDK/Assets/ML-Agents/Editor/DemonstrationImporter.cs
  4. 38
      UnitySDK/Assets/ML-Agents/Scripts/Agent.cs
  5. 34
      UnitySDK/Assets/ML-Agents/Scripts/BrainParameters.cs
  6. 38
      UnitySDK/Assets/ML-Agents/Scripts/Demonstration.cs
  7. 2
      protobuf-definitions/make.sh
  8. 2
      protobuf-definitions/make_for_win.bat
  9. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/AgentActionProto.cs.meta
  10. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/AgentInfoProto.cs.meta
  11. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/BrainParametersProto.cs.meta
  12. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/CommandProto.cs.meta
  13. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/CustomAction.cs.meta
  14. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/CustomObservation.cs.meta
  15. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/CustomResetParameters.cs.meta
  16. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/DemonstrationMetaProto.cs.meta
  17. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/EngineConfigurationProto.cs.meta
  18. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/EnvironmentParametersProto.cs.meta
  19. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/Header.cs.meta
  20. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/ResolutionProto.cs.meta
  21. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/SpaceTypeProto.cs.meta
  22. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityInput.cs.meta
  23. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityMessage.cs.meta
  24. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityOutput.cs.meta
  25. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityRlInitializationInput.cs.meta
  26. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityRlInitializationOutput.cs.meta
  27. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityRlInput.cs.meta
  28. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityRlOutput.cs.meta
  29. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityToExternal.cs.meta
  30. 2
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityToExternalGrpc.cs.meta
  31. 3
      UnitySDK/Assets/ML-Agents/Scripts/Grpc.meta
  32. 115
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/GrpcExtensions.cs
  33. 3
      UnitySDK/Assets/ML-Agents/Scripts/Grpc/GrpcExtensions.cs.meta
  34. 0
      /UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects.meta
  35. 0
      /UnitySDK/Assets/ML-Agents/Scripts/Grpc/RpcCommunicator.cs.meta
  36. 0
      /UnitySDK/Assets/ML-Agents/Scripts/Grpc/RpcCommunicator.cs
  37. 0
      /UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects

5
.circleci/config.yml


chmod +x Grpc.Tools.1.14.1/tools/linux_x64/protoc
chmod +x Grpc.Tools.1.14.1/tools/linux_x64/grpc_csharp_plugin
COMPILER=Grpc.Tools.1.14.1/tools/linux_x64 ./make.sh
git diff --exit-code --quiet -- :/ ':(exclude,top)UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/*.meta' \
CS_PROTO_PATH=UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects
git diff --exit-code --quiet -- :/ ":(exclude,top)$CS_PROTO_PATH/*.meta" \
git diff -- :/ ':(exclude,top)UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/*.meta' > /tmp/proto.patch; \
git diff -- :/ ":(exclude,top)$CS_PROTO_PATH/*.meta" > /tmp/proto.patch; \
exit $GIT_ERR; }
- store_artifacts:
path: /tmp/proto.patch

3
.pre-commit-config.yaml


exclude: >
(?x)^(
.*cs.meta|
.*.css
.*.css|
.*.meta
)$
args: [--fix=lf]
- id: flake8

2
UnitySDK/Assets/ML-Agents/Editor/DemonstrationImporter.cs


Stream reader = File.OpenRead(ctx.assetPath);
var metaDataProto = DemonstrationMetaProto.Parser.ParseDelimitedFrom(reader);
var metaData = new DemonstrationMetaData(metaDataProto);
var metaData = metaDataProto.ToDemonstrationMetaData();
reader.Seek(DemonstrationStore.MetaDataBytes + 1, 0);
var brainParamsProto = BrainParametersProto.Parser.ParseDelimitedFrom(reader);

38
UnitySDK/Assets/ML-Agents/Scripts/Agent.cs


using System.Collections.Generic;
using Google.Protobuf;
using MLAgents.CommunicatorObjects;
using UnityEngine;

/// to an action in addition to a scalar reward.
/// </summary>
public CustomObservation customObservation;
/// <summary>
/// Converts a AgentInfo to a protobuffer generated AgentInfoProto
/// </summary>
/// <returns>The protobuf version of the AgentInfo.</returns>
public AgentInfoProto ToProto()
{
var agentInfoProto = new AgentInfoProto
{
StackedVectorObservation = { stackedVectorObservation },
StoredVectorActions = { storedVectorActions },
StoredTextActions = storedTextActions,
TextObservation = textObservation,
Reward = reward,
MaxStepReached = maxStepReached,
Done = done,
Id = id,
CustomObservation = customObservation
};
if (memories != null)
{
agentInfoProto.Memories.Add(memories);
}
if (actionMasks != null)
{
agentInfoProto.ActionMask.AddRange(actionMasks);
}
foreach (var obs in visualObservations)
{
agentInfoProto.VisualObservations.Add(
ByteString.CopyFrom(obs.EncodeToPNG())
);
}
return agentInfoProto;
}
/// <summary>
/// Remove the visual observations from memory. Call at each timestep

34
UnitySDK/Assets/ML-Agents/Scripts/BrainParameters.cs


/// <summary>Defines if the action is discrete or continuous</summary>
public SpaceType vectorActionSpaceType = SpaceType.Discrete;
/// <summary>
/// Converts a Brain into to a Protobuff BrainInfoProto so it can be sent
/// </summary>
/// <returns>The BrainInfoProto generated.</returns>
/// <param name="name">The name of the brain.</param>
/// <param name="isTraining">Whether or not the Brain is training.</param>
public CommunicatorObjects.BrainParametersProto
ToProto(string name, bool isTraining)
{
var brainParametersProto = new CommunicatorObjects.BrainParametersProto
{
VectorObservationSize = vectorObservationSize,
NumStackedVectorObservations = numStackedVectorObservations,
VectorActionSize = {vectorActionSize},
VectorActionSpaceType =
(CommunicatorObjects.SpaceTypeProto)vectorActionSpaceType,
BrainName = name,
IsTraining = isTraining
};
brainParametersProto.VectorActionDescriptions.AddRange(vectorActionDescriptions);
foreach (var res in cameraResolutions)
{
brainParametersProto.CameraResolutions.Add(
new CommunicatorObjects.ResolutionProto
{
Width = res.width,
Height = res.height,
GrayScale = res.blackAndWhite
});
}
return brainParametersProto;
}
public BrainParameters()
{
}

38
UnitySDK/Assets/ML-Agents/Scripts/Demonstration.cs


using System;
using MLAgents.CommunicatorObjects;
using UnityEngine;
namespace MLAgents

public string demonstrationName;
public const int ApiVersion = 1;
/// <summary>
/// Constructor for initializing metadata to default values.
/// </summary>
public DemonstrationMetaData()
{
}
/// <summary>
/// Initialize metadata values based on proto object.
/// </summary>
public DemonstrationMetaData(DemonstrationMetaProto demoProto)
{
numberEpisodes = demoProto.NumberEpisodes;
numberExperiences = demoProto.NumberSteps;
meanReward = demoProto.MeanReward;
demonstrationName = demoProto.DemonstrationName;
if (demoProto.ApiVersion != ApiVersion)
{
throw new Exception("API versions of demonstration are incompatible.");
}
}
/// <summary>
/// Convert metadata object to proto object.
/// </summary>
public DemonstrationMetaProto ToProto()
{
var demoProto = new DemonstrationMetaProto
{
ApiVersion = ApiVersion,
MeanReward = meanReward,
NumberSteps = numberExperiences,
NumberEpisodes = numberEpisodes,
DemonstrationName = demonstrationName
};
return demoProto;
}
}
}

2
protobuf-definitions/make.sh


# COMPILER=[DIRECTORY]
SRC_DIR=proto/mlagents/envs/communicator_objects
DST_DIR_C=../UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects
DST_DIR_C=../UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects
DST_DIR_P=../ml-agents-envs
PROTO_PATH=proto
PYTHON_PACKAGE=mlagents/envs/communicator_objects

2
protobuf-definitions/make_for_win.bat


rem set COMPILER=[DIRECTORY]
set SRC_DIR=proto\mlagents\envs\communicator_objects
set DST_DIR_C=..\UnitySDK\Assets\ML-Agents\Scripts\CommunicatorObjects
set DST_DIR_C=..\UnitySDK\Assets\ML-Agents\Scripts\Grpc\CommunicatorObjects
set DST_DIR_P=..\ml-agents-envs
set PROTO_PATH=proto

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/AgentActionProto.cs.meta


fileFormatVersion: 2
guid: 4482f127d4a874cf8a11da2b2cc27dc9
guid: 7397bbc10357b4972af34293e72d96d3
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/AgentInfoProto.cs.meta


fileFormatVersion: 2
guid: 791522439b8324bff85f84309db90ecc
guid: 0d095cb8e4b854e73acd0c1504492564
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/BrainParametersProto.cs.meta


fileFormatVersion: 2
guid: 7b41acc4d406e4a3c94df3399b2a6471
guid: 970de4bdd0ae24d31aaafa1990526d83
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/CommandProto.cs.meta


fileFormatVersion: 2
guid: 6b2ff9fe2c38b4e79aba78908cc5492c
guid: 79178b095ad724b21b91f187adb4a3e6
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/CustomAction.cs.meta


fileFormatVersion: 2
guid: a8d11b50ed9ce45f7827f5117b65db06
guid: cc39771cc6e944eaaafb44e2da960a65
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/CustomObservation.cs.meta


fileFormatVersion: 2
guid: 896847c1364a7475d9094058ff93b7f0
guid: 186aa820efd71454db6e4cb7b883dce5
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/CustomResetParameters.cs.meta


fileFormatVersion: 2
guid: a071e48ae56b2424e8b59aad01646f59
guid: 62f03717ee98042bf8990733358f2dbd
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/DemonstrationMetaProto.cs.meta


fileFormatVersion: 2
guid: f7abfeda342414e059423ef90ede4c30
guid: 7cba96ab3b11045e8a874900b69a0660
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/EngineConfigurationProto.cs.meta


fileFormatVersion: 2
guid: 2cebeb1263d7846b4b3c7c6e5d5e193f
guid: 90f4d8da1dacf4844a9fdf36c368e2b7
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/EnvironmentParametersProto.cs.meta


fileFormatVersion: 2
guid: be8c5f75bdcff41488a8e85748541100
guid: 45cb126d422a348f1af0a80b9a3b591f
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/Header.cs.meta


fileFormatVersion: 2
guid: 8bb8aabfab48b408381733bccccd5af9
guid: 870996bd75a1a4fbcbb120b1e1e66c37
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/ResolutionProto.cs.meta


fileFormatVersion: 2
guid: eae234f817240444a9d18b3d7366f260
guid: f19fefeaaa2594e70b23e74adfaf0d5a
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/SpaceTypeProto.cs.meta


fileFormatVersion: 2
guid: 3e61637749b07412284363ff304da763
guid: c586cad5c95d54841a36c0f74ea95071
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityInput.cs.meta


fileFormatVersion: 2
guid: 25e46cd9eca204e19a08fa938802ef9d
guid: 13de5026cc0834f558fe971eb93c850e
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityMessage.cs.meta


fileFormatVersion: 2
guid: d270bf9ce3d564bb48b2095802c15ff9
guid: e2189c32296994576b0ef0aaa2b78142
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityOutput.cs.meta


fileFormatVersion: 2
guid: 5b7166f97831f45ef86df5eed0042240
guid: e1c19e75c7657497fbc05cfa40dd6783
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityRlInitializationInput.cs.meta


fileFormatVersion: 2
guid: 6c81750abd5a9432babe1834534122c0
guid: e1542ad34ffb34317b74b239135d0477
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityRlInitializationOutput.cs.meta


fileFormatVersion: 2
guid: f7ac9dd525a2246688054b2442eda28a
guid: e0bcb88495d5d48229140a2080dfd297
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityRlInput.cs.meta


fileFormatVersion: 2
guid: 24680ffa432734c09b4660d82303cbd2
guid: c9d247f0bc49d468da0f9f0cc6484d34
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityRlOutput.cs.meta


fileFormatVersion: 2
guid: af13b8fefefa74a948934dd273f94c4a
guid: 7b039d6d52b5142a78431d1758f5bf53
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityToExternal.cs.meta


fileFormatVersion: 2
guid: 199e76fc828bc4561abad51402438e07
guid: c03819ddc4c30416ab6ecc83c9cee562
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects/UnityToExternalGrpc.cs.meta


fileFormatVersion: 2
guid: 0378b2871a6c649f69c2f32d5c0fb045
guid: 6c0f560328e7343499ad203c75c11741
MonoImporter:
externalObjects: {}
serializedVersion: 2

3
UnitySDK/Assets/ML-Agents/Scripts/Grpc.meta


fileFormatVersion: 2
guid: 418327e202c7464bb6649d025df1b539
timeCreated: 1569444731

115
UnitySDK/Assets/ML-Agents/Scripts/Grpc/GrpcExtensions.cs


using System;
using Google.Protobuf;
using MLAgents.CommunicatorObjects;
using UnityEngine;
namespace MLAgents
{
public static class GrpcExtensions
{
/// <summary>
/// Converts a AgentInfo to a protobuf generated AgentInfoProto
/// </summary>
/// <returns>The protobuf version of the AgentInfo.</returns>
public static AgentInfoProto ToProto(this AgentInfo ai)
{
var agentInfoProto = new AgentInfoProto
{
StackedVectorObservation = { ai.stackedVectorObservation },
StoredVectorActions = { ai.storedVectorActions },
StoredTextActions = ai.storedTextActions,
TextObservation = ai.textObservation,
Reward = ai.reward,
MaxStepReached = ai.maxStepReached,
Done = ai.done,
Id = ai.id,
CustomObservation = ai.customObservation
};
if (ai.memories != null)
{
agentInfoProto.Memories.Add(ai.memories);
}
if (ai.actionMasks != null)
{
agentInfoProto.ActionMask.AddRange(ai.actionMasks);
}
foreach (var obs in ai.visualObservations)
{
agentInfoProto.VisualObservations.Add(
ByteString.CopyFrom(obs.EncodeToPNG())
);
}
return agentInfoProto;
}
/// <summary>
/// Converts a Brain into to a Protobuff BrainInfoProto so it can be sent
/// </summary>
/// <returns>The BrainInfoProto generated.</returns>
/// <param name="name">The name of the brain.</param>
/// <param name="isTraining">Whether or not the Brain is training.</param>
public static BrainParametersProto ToProto(this BrainParameters bp, string name, bool isTraining)
{
var brainParametersProto = new BrainParametersProto
{
VectorObservationSize = bp.vectorObservationSize,
NumStackedVectorObservations = bp.numStackedVectorObservations,
VectorActionSize = {bp.vectorActionSize},
VectorActionSpaceType =
(SpaceTypeProto)bp.vectorActionSpaceType,
BrainName = name,
IsTraining = isTraining
};
brainParametersProto.VectorActionDescriptions.AddRange(bp.vectorActionDescriptions);
foreach (var res in bp.cameraResolutions)
{
brainParametersProto.CameraResolutions.Add(
new ResolutionProto
{
Width = res.width,
Height = res.height,
GrayScale = res.blackAndWhite
});
}
return brainParametersProto;
}
/// <summary>
/// Convert metadata object to proto object.
/// </summary>
public static DemonstrationMetaProto ToProto(this DemonstrationMetaData dm)
{
var demoProto = new DemonstrationMetaProto
{
ApiVersion = DemonstrationMetaData.ApiVersion,
MeanReward = dm.meanReward,
NumberSteps = dm.numberExperiences,
NumberEpisodes = dm.numberEpisodes,
DemonstrationName = dm.demonstrationName
};
return demoProto;
}
/// <summary>
/// Initialize metadata values based on proto object.
/// </summary>
public static DemonstrationMetaData ToDemonstrationMetaData(this DemonstrationMetaProto demoProto)
{
var dm = new DemonstrationMetaData
{
numberEpisodes = demoProto.NumberEpisodes,
numberExperiences = demoProto.NumberSteps,
meanReward = demoProto.MeanReward,
demonstrationName = demoProto.DemonstrationName
};
if (demoProto.ApiVersion != DemonstrationMetaData.ApiVersion)
{
throw new Exception("API versions of demonstration are incompatible.");
}
return dm;
}
}
}

3
UnitySDK/Assets/ML-Agents/Scripts/Grpc/GrpcExtensions.cs.meta


fileFormatVersion: 2
guid: 02e8742d8a124607bef3b5ff8b9dd3d0
timeCreated: 1569444771

/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects.meta → /UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects.meta

/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs.meta → /UnitySDK/Assets/ML-Agents/Scripts/Grpc/RpcCommunicator.cs.meta

/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs → /UnitySDK/Assets/ML-Agents/Scripts/Grpc/RpcCommunicator.cs

/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects → /UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects

正在加载...
取消
保存