Skip to content

Commit 61788c0

Browse files
author
Marwan Mattar
committed
Merge branch 'development-0.3' into docs/random-fixes
# Conflicts: # docs/Learning-Environment-Create-New.md
2 parents 7e86f0c + 8e0014c commit 61788c0

File tree

11 files changed

+120
-108
lines changed

11 files changed

+120
-108
lines changed

docs/Getting-Started-with-Balance-Ball.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ the `Internal` Brain mode will only be available once completing these steps.
325325

326326
1. Make sure the TensorFlowSharp plugin is in your `Assets` folder. A Plugins
327327
folder which includes TF# can be downloaded
328-
[here](https://s3.amazonaws.com/unity-agents/0.2/TFSharpPlugin.unitypackage).
328+
[here](https://s3.amazonaws.com/unity-agents/0.3/TFSharpPlugin.unitypackage).
329329
Double click and import it once downloaded. You can see if this was
330330
successfully installed by checking the TensorFlow files in the Project tab
331331
under `Assets` -> `ML-Agents` -> `Plugins` -> `Computer`

docs/Learning-Environment-Best-Practices.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ complexity over time. This can either be done manually, or via Curriculum Learni
1515

1616
## Vector Observations
1717
* Vector Observations should include all variables relevant to allowing the agent to take the optimally informed decision.
18+
* In cases where Vector Observations need to be remembered or compared over time, increase the `Stacked Vectors` value to allow the agent to keep track of multiple observations into the past.
1819
* Categorical variables such as type of object (Sword, Shield, Bow) should be encoded in one-hot fashion (i.e. `3` -> `0, 0, 1`).
1920
* Besides encoding non-numeric values, all inputs should be normalized to be in the range 0 to +1 (or -1 to 1). For example, the `x` position information of an agent where the maximum possible value is `maxValue` should be recorded as `AddVectorObs(transform.position.x / maxValue);` rather than `AddVectorObs(transform.position.x);`. See the equation below for one approach of normalization.
2021
* Positional information of relevant GameObjects should be encoded in relative coordinates wherever possible. This is often relative to the agent position.

docs/Learning-Environment-Create-New.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Next, we will create a very simple scene to act as our ML-Agents environment. Th
5757
2. Name the GameObject "Target"
5858
3. Select Target to view its properties in the Inspector window.
5959
4. Set Transform to Position = (3,0.5,3), Rotation = (0,0,0), Scale = (1,1,1).
60-
5. On the Cube's Mesh Renderer, expand the Materials property and change the default-material to *block*.
60+
5. On the Cube's Mesh Renderer, expand the Materials property and change the default-material to *Block*.
6161

6262
![The Target Cube in the Inspector window](images/mlagents-NewTutBlock.png)
6363

@@ -116,15 +116,13 @@ The default settings for the Academy properties are also fine for this environme
116116

117117
## Add a Brain
118118

119-
The Brain object encapsulates the decision making process. An Agent sends its observations to its Brain and expects a decision in return. The Brain Type setting determines how the Brain makes decisions. Unlike the Academy and Agent classes, you don't make your own Brain subclasses. (You can extend CoreBrain to make your own *types* of Brain, but the four built-in brain types should cover almost all scenarios.)
119+
The Brain object encapsulates the decision making process. An Agent sends its observations to its Brain and expects a decision in return. The Brain Type setting determines how the Brain makes decisions. Unlike the Academy and Agent classes, you don't make your own Brain subclasses.
120120

121121
To create the Brain:
122122

123-
1. Right-click the Academy GameObject in the Hierarchy window and choose *Create Empty* to add a child GameObject.
124-
2. Name the new GameObject, "Brain".
125-
3. Select the Brain GameObject to show its properties in the Inspector window.
126-
4. Click **Add Component**.
127-
5. Select the **Scripts/Brain** component to add it to the GameObject.
123+
1. Select the Brain GameObject created earlier to show its properties in the Inspector window.
124+
2. Click **Add Component**.
125+
3. Select the **Scripts/Brain** component to add it to the GameObject.
128126

129127
We will come back to the Brain properties later, but leave the Brain Type as **Player** for now.
130128

@@ -258,9 +256,9 @@ The final part of the Agent code is the Agent.AgentAction() function, which rece
258256

259257
**Actions**
260258

261-
The decision of the Brain comes in the form of an action array passed to the `AgentAction()` function. The number of elements in this array is determined by the `Vector Action Space Type` and `Vector Action Space Size` settings of the agent's Brain. The RollerAgent uses the continuous vector action space and needs two continuous control signals from the brain. Thus, we will set the Brain `Vector Action Size` to 2. The first element,`action[0]` determines the force applied along the x axis; `action[1]` determines the force applied along the z axis. (If we allowed the agent to move in three dimensions, then we would need to set `Vector Action Size` to 3. Note the Brain really has no idea what the values in the action array mean. The training process adjust the action values in response to the observation input and then sees what kind of rewards it gets as a result.
259+
The decision of the Brain comes in the form of an action array passed to the `AgentAction()` function. The number of elements in this array is determined by the `Vector Action Space Type` and `Vector Action Space Size` settings of the agent's Brain. The RollerAgent uses the continuous vector action space and needs two continuous control signals from the brain. Thus, we will set the Brain `Vector Action Size` to 2. The first element,`action[0]` determines the force applied along the x axis; `action[1]` determines the force applied along the z axis. (If we allowed the agent to move in three dimensions, then we would need to set `Vector Action Size` to 3. Note the Brain really has no idea what the values in the action array mean. The training process just adjusts the action values in response to the observation input and then sees what kind of rewards it gets as a result.
262260

263-
Before we can add a force to the agent, we need a reference to its Rigidbody component. A [Rigidbody](https://docs.unity3d.com/ScriptReference/Rigidbody.html) is Unity's primary element for physics simulation. (See [Physics](https://docs.unity3d.com/Manual/PhysicsSection.html) for full documentation of Unity physics.) A good place to set references to other components of the same GameObject is in the standard Unity `Start()` method:
261+
The RollerAgent applies the values from the action[] array to its Rigidbody component, `rBody`, using the `Rigidbody.AddForce` function:
264262

265263

266264
With the reference to the Rigidbody, the agent can apply the values from the action[] array using the `Rigidbody.AddForce` function:
@@ -383,10 +381,10 @@ Also, drag the Target GameObject from the Hierarchy window to the RollerAgent Ta
383381

384382
Finally, select the Brain GameObject so that you can see its properties in the Inspector window. Set the following properties:
385383

384+
* `Vector Observation Space Type` = **Continuous**
386385
* `Vector Observation Space Size` = 8
387-
* `Vector Action Space Size` = 2
388386
* `Vector Action Space Type` = **Continuous**
389-
* `Vector Observation Space Type` = **Continuous**
387+
* `Vector Action Space Size` = 2
390388
* `Brain Type` = **Player**
391389

392390
Now you are ready to test the environment before training.

docs/Learning-Environment-Design-Brains.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The Brain Inspector window in the Unity Editor displays the properties assigned
2323
* `Vector Observation`
2424
* `Space Type` - Corresponds to whether the observation vector contains a single integer (Discrete) or a series of real-valued floats (Continuous).
2525
* `Space Size` - Length of vector observation for brain (In _Continuous_ space type). Or number of possible values (in _Discrete_ space type).
26-
* `Stacked Vectors` - The number of previous vector observations that will be stacked before being sent to the brain.
26+
* `Stacked Vectors` - The number of previous vector observations that will be stacked and used collectively for decision making. This results in the effective size of the vector observation being passed to the brain being: _Space Size_ x _Stacked Vectors_.
2727
* `Visual Observations` - Describes height, width, and whether to grayscale visual observations for the Brain.
2828
* `Vector Action`
2929
* `Space Type` - Corresponds to whether action vector contains a single integer (Discrete) or a series of real-valued floats (Continuous).
Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,68 @@
11
# Training on Amazon Web Service
22

3-
This page contains instructions for setting up an EC2 instance on Amazon Web Service for use in training ML-Agents environments. Current limitations of the Unity Engine require that a screen be available to render to. In order to make this possible when training on a remote server, a virtual screen is required. We can do this by installing Xorg and creating a virtual screen. Once installed and created, we can display the Unity environment in the virtual environment, and train as we would on a local machine.
3+
This page contains instructions for setting up an EC2 instance on Amazon Web Service for training ML-Agents environments. You can run "headless" training if none of the agents in the environment use visual observations.
44

55
## Pre-Configured AMI
66
A public pre-configured AMI is available with the ID: `ami-30ec184a` in the `us-east-1` region. It was created as a modification of the Amazon Deep Learning [AMI](https://aws.amazon.com/marketplace/pp/B01M0AXXQB).
77

88
## Configuring your own Instance
9-
Instructions here are adapted from this [Medium post](https://medium.com/towards-data-science/how-to-run-unity-on-amazon-cloud-or-without-monitor-3c10ce022639) on running general Unity applications in the cloud.
109

1110
1. To begin with, you will need an EC2 instance which contains the latest Nvidia drivers, CUDA8, and cuDNN. There are a number of external tutorials which describe this, such as:
1211
* [Getting CUDA 8 to Work With openAI Gym on AWS and Compiling TensorFlow for CUDA 8 Compatibility](https://davidsanwald.github.io/2016/11/13/building-tensorflow-with-gpu-support.html)
1312
* [Installing TensorFlow on an AWS EC2 P2 GPU Instance](http://expressionflow.com/2016/10/09/installing-tensorflow-on-an-aws-ec2-p2-gpu-instance/)
1413
* [Updating Nvidia CUDA to 8.0.x in Ubuntu 16.04 – EC2 Gx instance](https://aichamp.wordpress.com/2016/11/09/updating-nvidia-cuda-to-8-0-x-in-ubuntu-16-04-ec2-gx-instance/)
15-
2. Move `python` to remote instance.
14+
15+
## Installing ML-Agents
16+
17+
2. Move `python` sub-folder of this ml-agents repo to the remote ECS instance, and set it as the working directory.
1618
2. Install the required packages with `pip3 install .`.
17-
3. Run the following commands to install Xorg:
19+
20+
## Testing
21+
22+
To verify that all steps worked correctly:
23+
24+
1. In the Unity Editor, load a project containing an ML-Agents environment (you can use one of the example environments if you have not created your own).
25+
2. Open the Build Settings window (menu: File > Build Settings).
26+
3. Select Linux as the Target Platform, and x64_86 as the target architecture.
27+
4. Check Headless Mode (unless you have enabled a virtual screen following the instructions below).
28+
5. Click Build to build the Unity environment executable.
29+
6. Upload the executable to your EC2 instance.
30+
7. Test the instance setup from Python using:
31+
32+
```python
33+
from unityagents import UnityEnvironment
34+
35+
env = UnityEnvironment(<your_env>)
36+
```
37+
Where `<your_env>` corresponds to the path to your environment executable.
38+
39+
You should receive a message confirming that the environment was loaded successfully.
40+
41+
## (Optional) Enabling a virtual screen
42+
43+
_Instructions here are adapted from this [Medium post](https://medium.com/towards-data-science/how-to-run-unity-on-amazon-cloud-or-without-monitor-3c10ce022639) on running general Unity applications in the cloud._
44+
45+
Current limitations of the Unity Engine require that a screen be available to render to when using visual observations. In order to make this possible when training on a remote server, a virtual screen is required. We can do this by installing Xorg and creating a virtual screen. Once installed and created, we can display the Unity environment in the virtual environment, and train as we would on a local machine. Ensure that `headless` mode is disabled when building linux executables which use visual observations.
46+
47+
1. Run the following commands to install Xorg:
48+
1849
```
1950
sudo apt-get update
2051
sudo apt-get install -y xserver-xorg mesa-utils
2152
sudo nvidia-xconfig -a --use-display-device=None --virtual=1280x1024
2253
```
23-
4. Restart the EC2 instance.
2454
25-
## Launching your instance
55+
2. Restart the EC2 instance.
2656
27-
1. Make sure there are no Xorg processes running. To kill the Xorg processes, run `sudo killall Xorg`.
57+
3. Make sure there are no Xorg processes running. To kill the Xorg processes, run `sudo killall Xorg`.
2858
Note that you might have to run this command multiple times depending on how Xorg is configured.
2959
If you run `nvidia-smi`, you will have a list of processes running on the GPU, Xorg should not be in the list.
3060
31-
2. Run:
61+
4. Run:
62+
3263
```
3364
sudo /usr/bin/X :0 &
3465
export DISPLAY=:0
3566
```
36-
3. To ensure the installation was successful, run `glxgears`. If there are no errors, then Xorg is correctly configured.
37-
4. There is a bug in _Unity 2017.1_ which requires the uninstallation of `libxrandr2`, which can be removed with :
38-
```
39-
sudo apt-get remove --purge libwxgtk3.0-0v5
40-
sudo apt-get remove --purge libxrandr2
41-
```
42-
This is scheduled to be fixed in 2017.3.
43-
44-
## Testing
45-
46-
If all steps worked correctly, upload an example binary built for Linux to the instance, and test it from Python with:
47-
```python
48-
from unityagents import UnityEnvironment
49-
50-
env = UnityEnvironment(your_env)
51-
```
52-
53-
You should receive a message confirming that the environment was loaded successfully.
67+
68+
5. To ensure the installation was successful, run `glxgears`. If there are no errors, then Xorg is correctly configured.

python/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
required = f.read().splitlines()
88

99
setup(name='unityagents',
10-
version='0.2.0',
10+
version='0.3.0',
1111
description='Unity Machine Learning Agents',
1212
license='Apache License 2.0',
1313
author='Unity Technologies',
1414
author_email='[email protected]',
1515
url='https://github.com/Unity-Technologies/ml-agents',
16-
packages=find_packages(exclude = ['ppo']),
16+
packages=find_packages(),
1717
install_requires = required,
1818
long_description= ("Unity Machine Learning Agents allows researchers and developers "
1919
"to transform games and simulations created using the Unity Editor into environments "

0 commit comments

Comments
 (0)