From 67bc04a504da4b42a3d05fba1cd878164fa52aef Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 21 Feb 2019 11:43:10 -0800 Subject: [PATCH 1/7] Fix for GRPC, need documentation --- .../Plugins/ProtoBuffer/Grpc.Core.dll.meta | 80 ++++++++++++++++++- .../UnityToExternalGrpc.cs | 6 ++ .../ML-Agents/Scripts/RpcCommunicator.cs | 7 ++ .../ML-Agents/Scripts/SocketCommunicator.cs | 1 - 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta b/UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta index 2a461c7267..3163a0cdcb 100644 --- a/UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta +++ b/UnitySDK/Assets/ML-Agents/Plugins/ProtoBuffer/Grpc.Core.dll.meta @@ -8,23 +8,99 @@ PluginImporter: isPreloaded: 0 isOverridable: 0 platformData: + - first: + '': Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude Linux: 0 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXUniversal: 0 + Exclude Win: 0 + Exclude Win64: 0 + Exclude iOS: 1 + - first: + Android: Android + second: + enabled: 0 + settings: + CPU: ARMv7 - first: Any: second: - enabled: 1 + enabled: 0 settings: {} - first: Editor: Editor second: - enabled: 0 + enabled: 1 settings: + CPU: AnyCPU DefaultValueInitialized: true + OS: AnyOS + - first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Linux + second: + enabled: 1 + settings: + CPU: x86 + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: x86_64 + - first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: {} + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU - first: Windows Store Apps: WindowsStoreApps second: enabled: 0 settings: CPU: AnyCPU + - first: + iPhone: iOS + second: + enabled: 0 + settings: + CompileFlags: + FrameworkDependencies: userData: assetBundleName: assetBundleVariant: diff --git a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs index e266ac4935..e9472e45db 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs @@ -2,6 +2,9 @@ // Generated by the protocol buffer compiler. DO NOT EDIT! // source: mlagents/envs/communicator_objects/unity_to_external.proto // + +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWSWINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX + #pragma warning disable 1591 #region Designer generated code @@ -128,3 +131,6 @@ protected override UnityToExternalClient NewInstance(ClientBaseConfiguration con } } #endregion + +#endif + diff --git a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs index 4a1b2fde10..b2259f9a4e 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs @@ -1,4 +1,6 @@ +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWSWINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX using Grpc.Core; +#endif using System.IO; using System.Threading; using System.Threading.Tasks; @@ -41,6 +43,7 @@ public RPCCommunicator(CommunicatorParameters communicatorParameters) public UnityInput Initialize(UnityOutput unityOutput, out UnityInput unityInput) { +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX m_isOpen = true; var channel = new Channel( "localhost:"+m_communicatorParameters.port, @@ -57,6 +60,10 @@ public UnityInput Initialize(UnityOutput unityOutput, #endif #endif return result.UnityInput; +#else + throw new UnityAgentsException( + "You cannot perform training on this platform."); +#endif } /// diff --git a/UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs b/UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs index bd13e1751a..a2e6ca6f0e 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/SocketCommunicator.cs @@ -1,5 +1,4 @@ using Google.Protobuf; -using Grpc.Core; using System.Net.Sockets; using UnityEngine; using MLAgents.CommunicatorObjects; From d7394f8d9d1e694dc77e94bba4a5d9a45567ff91 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 21 Feb 2019 11:53:08 -0800 Subject: [PATCH 2/7] Edits --- .../CommunicatorObjects/UnityToExternalGrpc.cs | 2 +- .../Assets/ML-Agents/Scripts/RpcCommunicator.cs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs index e9472e45db..5008f0cd9d 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs @@ -3,7 +3,7 @@ // source: mlagents/envs/communicator_objects/unity_to_external.proto // -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWSWINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWSWINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX #pragma warning disable 1591 #region Designer generated code diff --git a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs index b2259f9a4e..213941c67e 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs @@ -1,4 +1,4 @@ -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWSWINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX using Grpc.Core; #endif using System.IO; @@ -18,9 +18,10 @@ public class RPCCommunicator : Communicator /// If true, the communication is active. bool m_isOpen; +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX /// The Unity to External client. UnityToExternal.UnityToExternalClient m_client; - +#endif /// The communicator parameters sent at construction CommunicatorParameters m_communicatorParameters; @@ -43,7 +44,7 @@ public RPCCommunicator(CommunicatorParameters communicatorParameters) public UnityInput Initialize(UnityOutput unityOutput, out UnityInput unityInput) { -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX m_isOpen = true; var channel = new Channel( "localhost:"+m_communicatorParameters.port, @@ -71,6 +72,7 @@ public UnityInput Initialize(UnityOutput unityOutput, /// public void Close() { +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX if (!m_isOpen) { return; @@ -85,6 +87,10 @@ public void Close() { return; } +#else + throw new UnityAgentsException( + "You cannot perform training on this platform."); +#endif } /// @@ -94,6 +100,7 @@ public void Close() /// The UnityOutput to be sent. public UnityInput Exchange(UnityOutput unityOutput) { +# if UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX if (!m_isOpen) { return null; @@ -116,6 +123,10 @@ public UnityInput Exchange(UnityOutput unityOutput) m_isOpen = false; return null; } +#else + throw new UnityAgentsException( + "You cannot perform training on this platform."); +#endif } /// From db9d496d650b8490c3ff9f0160320bec99886e16 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 21 Feb 2019 12:20:11 -0800 Subject: [PATCH 3/7] typo --- .../Scripts/CommunicatorObjects/UnityToExternalGrpc.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs index 5008f0cd9d..e303750865 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs @@ -3,7 +3,7 @@ // source: mlagents/envs/communicator_objects/unity_to_external.proto // -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWSWINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX #pragma warning disable 1591 #region Designer generated code From 5c6a400fc95a773669c5999950ae737a396fc840 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 21 Feb 2019 12:32:48 -0800 Subject: [PATCH 4/7] Fixes --- .../Scripts/CommunicatorObjects/UnityToExternalGrpc.cs | 2 +- UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs index e303750865..bf738cbd7a 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects/UnityToExternalGrpc.cs @@ -3,7 +3,7 @@ // source: mlagents/envs/communicator_objects/unity_to_external.proto // -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX #pragma warning disable 1591 #region Designer generated code diff --git a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs index 213941c67e..7363af2c7f 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs @@ -1,4 +1,4 @@ -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX using Grpc.Core; #endif using System.IO; @@ -18,7 +18,7 @@ public class RPCCommunicator : Communicator /// If true, the communication is active. bool m_isOpen; -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX /// The Unity to External client. UnityToExternal.UnityToExternalClient m_client; #endif @@ -72,7 +72,7 @@ public UnityInput Initialize(UnityOutput unityOutput, /// public void Close() { -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX if (!m_isOpen) { return; @@ -100,7 +100,7 @@ public void Close() /// The UnityOutput to be sent. public UnityInput Exchange(UnityOutput unityOutput) { -# if UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX if (!m_isOpen) { return null; From c23ccf79213dc25231d8e300e441b58c5ca47583 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 21 Feb 2019 12:37:47 -0800 Subject: [PATCH 5/7] Missing typo --- UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs index 7363af2c7f..f35cb8c60e 100644 --- a/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs +++ b/UnitySDK/Assets/ML-Agents/Scripts/RpcCommunicator.cs @@ -44,7 +44,7 @@ public RPCCommunicator(CommunicatorParameters communicatorParameters) public UnityInput Initialize(UnityOutput unityOutput, out UnityInput unityInput) { -# if UNITY_EDITOR || UNITY_STANDALONE_WINDOWS || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX m_isOpen = true; var channel = new Channel( "localhost:"+m_communicatorParameters.port, From d52a22918de075911294a6908cf53d4786b23909 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 21 Feb 2019 13:33:02 -0800 Subject: [PATCH 6/7] Modified the documentation --- protobuf-definitions/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/protobuf-definitions/README.md b/protobuf-definitions/README.md index 5141828f42..8ae6e7d5fc 100644 --- a/protobuf-definitions/README.md +++ b/protobuf-definitions/README.md @@ -26,3 +26,14 @@ On Windows & Linux: [See here](https://github.com/google/protobuf/blob/master/sr 1. Install pre-requisites. 2. Un-comment line 4 in `make.bat`, and set to correct Grpc.Tools sub-directory. 3. Run `make.bat` +4. In the generated `UnityToExternalGrpc.cs` file in the `CommunicatorObjects` folder, you will need to add on top of the file the line + +```csharp +# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX +``` + and at the bottom of the file the line + + ```csharp + #endif + ``` +This is to make sure the Grpc library is not used on platforms that do not support training. From cbe5e611aad4eb5bfef292d1a1953e9400ff7b21 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 21 Feb 2019 15:11:31 -0800 Subject: [PATCH 7/7] Updated the documentation --- protobuf-definitions/README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/protobuf-definitions/README.md b/protobuf-definitions/README.md index 8ae6e7d5fc..bc4ca01e92 100644 --- a/protobuf-definitions/README.md +++ b/protobuf-definitions/README.md @@ -26,14 +26,15 @@ On Windows & Linux: [See here](https://github.com/google/protobuf/blob/master/sr 1. Install pre-requisites. 2. Un-comment line 4 in `make.bat`, and set to correct Grpc.Tools sub-directory. 3. Run `make.bat` -4. In the generated `UnityToExternalGrpc.cs` file in the `CommunicatorObjects` folder, you will need to add on top of the file the line +4. In the generated `UnityToExternalGrpc.cs` file in the `UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects` folder, you will need to add the following to the beginning of the file ```csharp # if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX ``` - and at the bottom of the file the line + and the following line to the end ```csharp #endif ``` -This is to make sure the Grpc library is not used on platforms that do not support training. +This is to make sure the generated code does not try to access the Grpc library +on platforms that are not supported by Grpc.