Skip to content

Commit

Permalink
Merge branch 'release/v2.0.0-alpha.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohojoe committed Mar 9, 2020
2 parents 3598f6d + c285c6a commit 1d80fd2
Show file tree
Hide file tree
Showing 892 changed files with 53,644 additions and 25,519 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ ml-agents-protobuf/Grpc*
# Ignore PyPi build files.
dist/
build/
old_summaries/
mono_crash.*
File renamed without changes.
274 changes: 274 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@


-----
### ‎⁨ml-agents/⁨mlagents⁩/trainers⁩/learn.py
line 90 add (last param for `create_environment_factory()`)
``` python
list([str(x) for t in run_options.items() for x in t]), # NOTE passes all arguments to Unity
```
line 210 add (last param for `create_environment_factory()`)
``` python
unity_args={},
```
line 246 add (last param for `UnityEnvironment()`)
``` python
args=unity_args,
```
line 298 add (two new options for `_USAGE`)
```
--spawn-env=<name> Inform environment which SpawnableEnv to use (if supported) [default: None].
--num-spawn-envs=<n> Inform environment how many SpawnableEnv to create (if supported) [default: None].
```

-----
## Editor - Add Files
### ‎UnitySDK/Assets/ML-Agents/Editor/EnvSpawnerDrawer.cs
-----
## Scripts - Add Files
### UnitySDK/Assets/ML-Agents/Scripts/EnvSpawner.cs
### UnitySDK/Assets/ML-Agents/Scripts/SpawnableEnv.cs
### UnitySDK/Assets/ML-Agents/Scripts/SelectEnvToSpawn.cs
-----
## Scripts - Edits
### UnitySDK/Assets/ML-Agents/Scripts/Academy.cs
line 240, replace
```csharp
void Awake()
{
InitializeEnvironment();
}
```
with
```csharp
void Awake()
{
if (ShouldInitalizeOnAwake())
InitializeEnvironment();
else
enabled = false;
```
then add
```csharp
void OnEnable()
{
if (!ShouldInitalizeOnAwake())
InitializeEnvironment();
}
public bool ShouldInitalizeOnAwake()
{
if (agentSpawner != null && IsTrainingMode())
return true;
if (GetComponent<SelectEnvToSpawn>() == null)
return true;
return false;
}
```
line 291, replace
```csharp
var exposedBrains = broadcastHub.broadcastingBrains.Where(x => x != null).ToList();;
var controlledBrains = broadcastHub.broadcastingBrains.Where(
x => x != null && x is LearningBrain && broadcastHub.IsControlled(x));
foreach (LearningBrain brain in controlledBrains)
{
brain.SetToControlledExternally();
}
```
with
```csharp
var spawnPrefab = agentSpawner.GetPrefabFor(GetAgentId());
var spawnAgentPrefabs = spawnPrefab.GetComponentsInChildren<Agent>();
var spawnAgentPrefabBrains = spawnAgentPrefabs
.Where(x=>x.brain as LearningBrain != null)
.Select(x=>x.brain)
.ToList();
var spawnerEnabled = spawnAgentPrefabBrains.Count > 0;
var hubBrains = broadcastHub.broadcastingBrains.Where(x => x != null).ToList();;
var hubControlledBrains = broadcastHub.broadcastingBrains.Where(
x => x != null && x is LearningBrain && broadcastHub.IsControlled(x));

IEnumerable<Brain> exposedBrains =
spawnerEnabled ? spawnAgentPrefabBrains : hubBrains;
IEnumerable<Brain> controlledBrains = hubControlledBrains;
if (spawnerEnabled)
controlledBrains = IsTrainingMode()
? spawnAgentPrefabBrains
: new List<Brain>();
```
line 336, add
```csharp
foreach (LearningBrain brain in controlledBrains)
{
brain.SetToControlledExternally();
}
```
line 398, add
```python
if (spawnerEnabled)
agentSpawner.SpawnSpawnableEnv(this.gameObject, GetNumAgents() ,spawnPrefab);
```
line 441, add
```python
/// <summary>
/// Return the number of agents to spawn.
/// </summary>
public int GetNumAgents()
{
// try get from command line
List<string> commandLineArgs = new List<string>(System.Environment.GetCommandLineArgs());
int index = commandLineArgs.IndexOf("--num-spawn-envs");
if(index != -1) {
int numEnvs;
if (int.TryParse(commandLineArgs[index + 1], out numEnvs))
return numEnvs;
}
return isInference ? agentSpawner.inferenceNumEnvsDefault : agentSpawner.trainingNumEnvsDefault;
}

/// <summary>
/// Return the agentId to spawn.
/// </summary>
public string GetAgentId()
{
// try get from command line
List<string> commandLineArgs = new List<string>(System.Environment.GetCommandLineArgs());
int index = commandLineArgs.IndexOf("--spawn-env");
if(index != -1) {
return commandLineArgs[index + 1];
}
return agentSpawner.envIdDefault;
}

/// <summary>
/// Return if training mode.
/// </summary>
bool IsTrainingMode()
{
if (agentSpawner != null && agentSpawner.trainingMode)
return true;
List<string> commandLineArgs = new List<string>(System.Environment.GetCommandLineArgs());
int index = commandLineArgs.IndexOf("--train");
bool trainingMode = index != -1;
return trainingMode;
}
```
line 688, add to `FixedUpdate()`
```python
SpawnableEnv.TriggerPhysicsStep();
```
line 699, add tp `OnDestroy()`
```python
broadcastHub.Clear();
broadcastHub = null;
agentSpawner = null;
```
-----
### UnitySDK/Assets/ML-Agents/Scripts/Agent.cs
line 181, add
```csharp

/// <summary>
/// If numberOfActionsBetweenDecisions > 1, setting this to true will
/// only send Actions on decisions steps. This is useful when running
/// physics at high frequencies on continious control agents. (used
/// when On Demand Decisions is turned off).
/// </summary>
public bool skipActionsWithDecisions;
```
line 902, add
```csharp
protected AgentInfo GetInfo()
{
return info;
}
```
line 1026, replace
```csharp
void MakeRequests(int academyStepCounter)
{
agentParameters.numberOfActionsBetweenDecisions =
Mathf.Max(agentParameters.numberOfActionsBetweenDecisions, 1);
if (!agentParameters.onDemandDecision)
{
RequestAction();
if (academyStepCounter %
agentParameters.numberOfActionsBetweenDecisions == 0)
{
RequestDecision();
}
}
}
```
with
```csharp
void MakeRequests(int academyStepCounter)
{
agentParameters.numberOfActionsBetweenDecisions =
Mathf.Max(agentParameters.numberOfActionsBetweenDecisions, 1);
if (!agentParameters.onDemandDecision)
{
bool skipDecision = false;
bool skipAction = false;
if (academyStepCounter %
agentParameters.numberOfActionsBetweenDecisions != 0)
{
skipDecision = true;
skipAction = agentParameters.skipActionsWithDecisions;
}
if (!skipAction)
RequestAction();
if (!skipDecision)
RequestDecision();
}
}
```
line 1101, add
```csharp
/// <summary>
/// Cleanup function
/// </summary>
protected virtual void OnDestroy()
{
brain?.Clear();
Monitor.RemoveAllValues(transform);
}
}
```
-----
### UnitySDK/Assets/ML-Agents/Scripts/Brain.cs
line 92, add
```csharp
public void Clear()
{
var academy = FindObjectOfType<Academy>();
if (academy != null)
academy.BrainDecideAction -= BrainDecideAction;
agentInfos.Clear();
_isInitialized = false;
}
```
-----
### UnitySDK/Assets/ML-Agents/Scripts/Monitor.cs
line 33 repace
``` csharp
static bool isInstantiated;
```
with
``` csharp
static bool isInstantiated{ get {return canvas!=null;} }
```
line 89, within `if (!isInstantiated)` remove
``` csharp
isInstantiated = true;
```
line 159, within `if (!isInstantiated)` remove
``` csharp
isInstantiated = true;
```
line 221, within `if (!isInstantiated)` remove
``` csharp
isInstantiated = true;
```
line 335, within `if (!isInstantiated)` remove
``` csharp
isInstantiated = true;
```
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ RUN apt-get update && apt-get -y upgrade
# xvfb is used to do CPU based rendering of Unity
RUN apt-get install -y xvfb

# Install ml-agents-envs package locally
COPY ml-agents-envs /ml-agents-envs
WORKDIR /ml-agents-envs
RUN pip install -e .

# Install ml-agents package next
COPY ml-agents /ml-agents
WORKDIR /ml-agents
RUN pip install .
RUN pip install -e .

# port 5005 is the port used in in Editor training.
EXPOSE 5005
Expand Down
4 changes: 2 additions & 2 deletions LICENSE
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@
APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2017 Unity Technologies

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 1d80fd2

Please sign in to comment.