浏览代码

Merge pull request #2138 from rsfutch77/protobuf_update

Fix Protobuf Install Instructions
/develop-generalizationTraining-TrainerController
GitHub 6 年前
当前提交
9a68742f
共有 4 个文件被更改,包括 39 次插入17 次删除
  1. 4
      .gitignore
  2. 2
      docs/Creating-Custom-Protobuf-Messages.md
  3. 41
      protobuf-definitions/README.md
  4. 9
      protobuf-definitions/make_for_win.bat

4
.gitignore


*.pytest_cache/
# Ignore compiled protobuf files.
ml-agents-protobuf/cs
ml-agents-protobuf/python
ml-agents-protobuf/Grpc*
*Grpc.Tools*
# Ignore PyPi build files.
dist/

2
docs/Creating-Custom-Protobuf-Messages.md


## Implementing a Custom Message
Assume the ml-agents repository is checked out to a folder named $MLAGENTS_ROOT. Whenever you change the fields of a custom message, you must run `$MLAGENTS_ROOT/protobuf-definitions/make.bat` to create C# and Python files corresponding to the new message. Follow the directions in [this file](../protobuf-definitions/README.md) for guidance. After running `$MLAGENTS_ROOT/protobuf-definitions/make.bat`, reinstall the Python package by running `pip install $MLAGENTS_ROOT/ml-agents` and make sure your Unity project is using the newly-generated version of `$MLAGENTS_ROOT/UnitySDK`.
Whenever you change the fields of a custom message, you must follow the directions in [this file](../protobuf-definitions/README.md) to create C# and Python files corresponding to the new message and re-install the mlagents Python package.
## Custom Message Types

41
protobuf-definitions/README.md


## Requirements
* grpc 1.14.1
* grpcio-tools 1.11.1
* Grpc.Tools 1.14.1
First we will follow these steps once install protobuf and grpcio-tools via your terminal.
Assume the ml-agents repository is checked out to a folder named $MLAGENTS_ROOT.
**Note:** If you're using Anaconda, don't forget to activate the ml-agents environment first.
`pip install grpcio-tools`
`pip install grpcio-tools==1.11.1`
`nuget install Grpc.Tools` into known directory.
If you don't have it already, download the latest version of [nuget](https://www.nuget.org/downloads).
Navigate to your installation of nuget and run the following:
`nuget install Grpc.Tools -Version 1.14.1 -OutputDirectory $MLAGENTS_ROOT\protobuf-definitions`
On Windows & Linux: [See here](https://github.com/google/protobuf/blob/master/src/README.md).
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 `UnitySDK/Assets/ML-Agents/Scripts/CommunicatorObjects` folder, you will need to add the following to the beginning of the file
Whenever you change the fields of a custom message, you must follow the steps below to create C# and Python files corresponding to the new message.
1. Open a terminal. **Note:** If you're using Anaconda, don't forget to activate the ml-agents environment first.
2. Un-comment line 7 in `make.bat` (for Windows, use `make_for_win.bat`), and set to correct Grpc.Tools sub-directory.
3. Run the `.bat` from the terminal by navigating to `$MLAGENTS_ROOT\protobuf-definitions` and entering `make.bat` (for Windows, use `make_for_win.bat`)
4. Note any errors generated that may result from setting the wrong directory in step 2.
5. In the generated `UnityToExternalGrpc.cs` file in the `$MLAGENTS_ROOT/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

```
This is to make sure the generated code does not try to access the Grpc library
on platforms that are not supported by Grpc.
Finally, re-install the mlagents packages by running the following commands from the same `$MLAGENTS_ROOT\protobuf-definitions` directory.
```
cd ..
cd ml-agents-envs
pip install -e .
cd ..
cd ml-agents
pip install -e .
mlagents-learn
```
The final line will test if everything was generated and installed correctly. If it worked, you should see the Unity logo.

9
protobuf-definitions/make_for_win.bat


rem GRPC-TOOLS required. Install with `nuget install Grpc.Tools`.
rem Then un-comment and replace [DIRECTORY] with location of files.
rem For example, on Windows, you might have something like:
rem set COMPILER=Grpc.Tools.1.14.1/tools/windows_x64
rem set COMPILER=Grpc.Tools.1.14.1\tools\windows_x64
rem set COMPILER=[DIRECTORY]
set SRC_DIR=proto\mlagents\envs\communicator_objects
set DST_DIR_C=..\UnitySDK\Assets\ML-Agents\Scripts\CommunicatorObjects

rem generate proto objects in python and C#
for %%i in (%SRC_DIR%\*.proto) do (
protoc --proto_path=proto --csharp_out=%DST_DIR_C% %%i
protoc --proto_path=proto --python_out=%DST_DIR_P% %%i
%COMPILER%\protoc --proto_path=proto --csharp_out=%DST_DIR_C% %%i
%COMPILER%\protoc --proto_path=proto --python_out=%DST_DIR_P% %%i
)
rem grpc

%COMPILER%\protoc --proto_path=proto --csharp_out %DST_DIR_C% --grpc_out %DST_DIR_C% %SRC_DIR%\%GRPC% --plugin=protoc-gen-grpc=%COMPILER%\grpc_csharp_plugin.exe
python3 -m grpc_tools.protoc --proto_path=proto --python_out=%DST_DIR_P% --grpc_python_out=%DST_DIR_P% %SRC_DIR%\%GRPC%
python -m grpc_tools.protoc --proto_path=proto --python_out=%DST_DIR_P% --grpc_python_out=%DST_DIR_P% %SRC_DIR%\%GRPC%
rem Generate the init file for the python module
rem rm -f $DST_DIR_P/$PYTHON_PACKAGE/__init__.py

正在加载...
取消
保存