-
Notifications
You must be signed in to change notification settings - Fork 4.3k
ObservableAttribute #3925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObservableAttribute #3925
Conversation
@@ -39,15 +44,13 @@ public override void Initialize() | |||
SetResetParameters(); | |||
} | |||
|
|||
public override void CollectObservations(VectorSensor sensor) | |||
[Observable] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to either revert this scene change, or retrain the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted. Separate jira to retrain.
com.unity.ml-agents/Runtime/Agent.cs
Outdated
/// <summary> | ||
/// Options for controlling how the Agent class is searched for <see cref="ObservableAttribute"/>s. | ||
/// </summary> | ||
public enum ObservableAttributeHandling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like any of the names here :/ Suggestions welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObservableAttributeOptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if SensorAttribute
makes it more consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed to ObservableAttributeOptions
m_NumStackedObservations = numStackedObservations; | ||
} | ||
|
||
internal static IEnumerable<(FieldInfo, ObservableAttribute)> GetObservableFields(object o, bool declaredOnly) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if these would be cleaner as a single IEnumerable<(MemberInfo, ObservableAttribute)>
that returned both FieldInfos and PropertyInfos. Downside is that we'd have to try to cast before using in the constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to do this for caching, but it's OK for now.
@@ -0,0 +1,11 @@ | |||
fileFormatVersion: 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this in a previous PR.
@@ -98,6 +101,19 @@ void DisplayFailedModelChecks() | |||
{ | |||
sensorComponents = behaviorParameters.GetComponents<SensorComponent>(); | |||
} | |||
|
|||
int observableSensorSizes = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Observable seems to be the name for the members marked with the Observable attribute. Maybe in this code it should have a mode descriptive name. ReflexionObservable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean specifically in this part of the code, or in general? We already have "Reflection" in the namespace for the attribute; I don't think we need it in the attribute name as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the name of this variable specifically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to observableAttributeSensorTotalSize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(and added a few comments)
com.unity.ml-agents/Runtime/Sensors/Reflection/IntReflectionSensor.cs
Outdated
Show resolved
Hide resolved
com.unity.ml-agents/Runtime/Sensors/Reflection/ObservableAttribute.cs
Outdated
Show resolved
Hide resolved
@@ -22,6 +22,9 @@ public override void OnInspectorGUI() | |||
new GUIContent("Max Step", "The per-agent maximum number of steps.") | |||
); | |||
|
|||
var observableAttributeBehavior = serializedAgent.FindProperty("m_observableAttributeHandling"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the m_observableAttributeHandling
belongs on the behavior parameters, not on the Agent inspector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I like that better.
Proposed change(s)
Adds a new attribute, ObservableAttribute, which allows users to mark up Agent fields and properties to be turned into observations. Currently, the following data types are supported: int, float, bool, Vector2/3/4, Quaternion.
There is a non-zero (and possibly non-trivial) overhead for using these; they're recommended for getting started, but for production, users should use CollectObservations or a custom ISensor implementation.
Future work (not in this PR, links to jiras):
Benchmark
Caching
Support for Enums (?)
Convert some examples and retrain
Useful links (Github issues, JIRA tickets, ML-Agents forum threads etc.)
https://mattwarren.org/2016/12/14/Why-is-Reflection-slow/
https://jira.unity3d.com/browse/MLA-11
Types of change(s)
Checklist
Other comments