Skip to content
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

[WIP] [Fix] Fixing collect observation called on done #5375

Merged
merged 4 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions com.unity.ml-agents/Runtime/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,11 @@ void NotifyAgentDone(DoneReason doneReason)
m_Info.done = true;
m_Info.maxStepReached = doneReason == DoneReason.MaxStepReached;
m_Info.groupId = m_GroupId;
if (collectObservationsSensor != null)
UpdateSensors();
// Make sure the latest observations are being passed to training.
using (m_CollectObservationsChecker.Start())
{
// Make sure the latest observations are being passed to training.
collectObservationsSensor.Reset();
using (m_CollectObservationsChecker.Start())
{
CollectObservations(collectObservationsSensor);
}
CollectObservations(collectObservationsSensor);
}
// Request the last decision with no callbacks
// We request a decision so Python knows the Agent is done immediately
Expand Down
11 changes: 9 additions & 2 deletions com.unity.ml-agents/Tests/Runtime/Sensor/StackingSensorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@ public void AssertStackingReset()
agent1.RequestDecision();
aca.EnvironmentStep();
}

policy.OnRequestDecision = () => SensorTestHelper.CompareObservation(sensor, new[] { 18f, 19f, 21f });
SensorTestHelper.CompareObservation(sensor, new[] { 18f, 19f, 20f });
policy.OnRequestDecision = () => SensorTestHelper.CompareObservation(sensor, new[] { 19f, 20f, 21f });
agent1.EndEpisode();
policy.OnRequestDecision = () => { };
SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f });
for (int i = 0; i < 20; i++)
{
agent1.RequestDecision();
aca.EnvironmentStep();
SensorTestHelper.CompareObservation(sensor, new[] { Math.Max(0, i - 1f), i, i + 1 });
}
}

[Test]
Expand Down
6 changes: 4 additions & 2 deletions docs/Learning-Environment-Design-Agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,8 @@ The `BufferSensorComponent` Editor inspector has two arguments:
the `BufferSensor` will be able to collect.

To add an entity's observations to a `BufferSensorComponent`, you need
to call `BufferSensorComponent.AppendObservation()`
to call `BufferSensorComponent.AppendObservation()` in the
Agent.CollectObservations() method
with a float array of size `Observation Size` as argument.

__Note__: Currently, the observations put into the `BufferSensor` are
Expand All @@ -621,7 +622,8 @@ between -1 and 1.

#### Variable Length Observation Summary & Best Practices
- Attach `BufferSensorComponent` to use.
- Call `BufferSensorComponent.AppendObservation()` to add the observations
- Call `BufferSensorComponent.AppendObservation()` in the
Agent.CollectObservations() methodto add the observations
of an entity to the `BufferSensor`.
- Normalize the entities observations before feeding them into the `BufferSensor`.

Expand Down