Skip to content

Commit 22afeef

Browse files
1 to 1 Brain to Agent (#2729)
* 1 to 1 Brain to Agent This is a work in progess In this PR : - Deleted all Brain Objects - Moved the BrainParameters into the Agent - Gave the Agent a Heuristic method (see Balance Ball for example) - Modified the Communicator and ModelRunner : Put can only take one agent at a time - Made the IBrain Interface with RequestDecision and DecideAction method No changes made to Python [Design Doc](https://docs.google.com/document/d/1hBhBxZ9lepGF4H6fc6Hu6AW7UwOmnyX3trmgI3HpOmo/edit#) * Removing editorconfig * Updating BallanceBall scene * grammar mistake * Clearing the Agents of the Model runner * Added Documentation on IBrain * Modified comments on GiveModel * Introduced a factory * Split Learning Brain in two * Changes to walljump * Fixing the Unit tests * Renaming the Brain to Policy * Heuristic now has priority over training * Edited code comments * Fixing bugs * Develop one to one scene edits (#2744) * Delting all brains, setting Behavior Parameters * Removing learning from all the configs * Forgot one agent * Removing leftover brains * Dead meta file * Adding Heuristics * Moving the policies in a separate folder * Missing meta file * Develop one to one with component (#2753) * Made Policy Factory a component * Broke the Heuristic * fix bug * BugFix * Reimplemented Heuristic * Changing all of the prefabs * forgotten file * Fixing under which conditions the Heuristic policy is used * Dispose of brain * Removing references to Brain in the Academy comments; * Develop one to one documentation (#2742) * initial changes to the documentation * More documentation changes, not done. * More documentation changes * More docs * Changed the images * addressing comments * Adding one line to the migrating doc * Removing warning in the Agent Inspector when Vis Obs is used * Fixing C# unit tests
1 parent 607af33 commit 22afeef

File tree

246 files changed

+3022
-16958
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+3022
-16958
lines changed
-4.85 KB
Binary file not shown.

UnitySDK/Assets/Gizmos/HeuristicBrain Icon.png.meta

Lines changed: 0 additions & 76 deletions
This file was deleted.
-4.81 KB
Binary file not shown.

UnitySDK/Assets/Gizmos/LearningBrain Icon.png.meta

Lines changed: 0 additions & 76 deletions
This file was deleted.
-5.1 KB
Binary file not shown.

UnitySDK/Assets/Gizmos/PlayerBrain Icon.png.meta

Lines changed: 0 additions & 76 deletions
This file was deleted.

UnitySDK/Assets/ML-Agents/Editor/AgentEditor.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using UnityEngine;
22
using UnityEditor;
3+
using Barracuda;
34

45
namespace MLAgents
56
{
6-
/*
7-
This code is meant to modify the behavior of the inspector on Brain Components.
8-
Depending on the type of brain that is used, the available fields will be modified in the inspector accordingly.
9-
*/
7+
/*
8+
This code is meant to modify the behavior of the inspector on Agent Components.
9+
*/
1010
[CustomEditor(typeof(Agent), true)]
1111
[CanEditMultipleObjects]
1212
public class AgentEditor : Editor
@@ -16,7 +16,6 @@ public override void OnInspectorGUI()
1616
var serializedAgent = serializedObject;
1717
serializedAgent.Update();
1818

19-
var brain = serializedAgent.FindProperty("brain");
2019
var actionsPerDecision = serializedAgent.FindProperty(
2120
"agentParameters.numberOfActionsBetweenDecisions");
2221
var maxSteps = serializedAgent.FindProperty(
@@ -26,7 +25,6 @@ public override void OnInspectorGUI()
2625
var isOdd = serializedAgent.FindProperty(
2726
"agentParameters.onDemandDecision");
2827

29-
EditorGUILayout.PropertyField(brain);
3028

3129

3230
EditorGUILayout.PropertyField(
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using Barracuda;
4+
5+
namespace MLAgents
6+
{
7+
/*
8+
This code is meant to modify the behavior of the inspector on Agent Components.
9+
*/
10+
[CustomEditor(typeof(BehaviorParameters))]
11+
[CanEditMultipleObjects]
12+
public class BehaviorParametersEditor : Editor
13+
{
14+
private const float k_TimeBetweenModelReloads = 2f;
15+
// Time since the last reload of the model
16+
private float m_TimeSinceModelReload;
17+
// Whether or not the model needs to be reloaded
18+
private bool m_RequireReload;
19+
20+
public override void OnInspectorGUI()
21+
{
22+
var serializedObject = base.serializedObject;
23+
serializedObject.Update();
24+
25+
// Drawing the Behavior Parameters
26+
EditorGUI.BeginChangeCheck();
27+
EditorGUI.indentLevel++;
28+
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BehaviorName"));
29+
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_BrainParameters"), true);
30+
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Model"), true);
31+
EditorGUI.indentLevel++;
32+
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_InferenceDevice"), true);
33+
EditorGUI.indentLevel--;
34+
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_UseHeuristic"));
35+
// EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Heuristic"), true);
36+
EditorGUI.indentLevel--;
37+
if (EditorGUI.EndChangeCheck())
38+
{
39+
m_RequireReload = true;
40+
}
41+
DisplayFailedModelChecks();
42+
serializedObject.ApplyModifiedProperties();
43+
}
44+
45+
/// <summary>
46+
/// Must be called within OnEditorGUI()
47+
/// </summary>
48+
private void DisplayFailedModelChecks()
49+
{
50+
if (m_RequireReload && m_TimeSinceModelReload > k_TimeBetweenModelReloads)
51+
{
52+
m_RequireReload = false;
53+
m_TimeSinceModelReload = 0;
54+
}
55+
// Display all failed checks
56+
D.logEnabled = false;
57+
Model barracudaModel = null;
58+
var model = (NNModel)serializedObject.FindProperty("m_Model").objectReferenceValue;
59+
var brainParameters = ((BehaviorParameters)target).brainParameters;
60+
if (model != null)
61+
{
62+
barracudaModel = ModelLoader.Load(model.Value);
63+
}
64+
if (brainParameters != null)
65+
{
66+
var failedChecks = InferenceBrain.BarracudaModelParamLoader.CheckModel(
67+
barracudaModel, brainParameters);
68+
foreach (var check in failedChecks)
69+
{
70+
if (check != null)
71+
{
72+
EditorGUILayout.HelpBox(check, MessageType.Warning);
73+
}
74+
}
75+
}
76+
}
77+
}
78+
}

UnitySDK/Assets/ML-Agents/Scripts/LearningBrain.cs.meta renamed to UnitySDK/Assets/ML-Agents/Editor/BehaviorParametersEditor.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnitySDK/Assets/ML-Agents/Editor/BrainEditor.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

UnitySDK/Assets/ML-Agents/Editor/BrainEditor.cs.meta

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)