Skip to content

Commit fce3521

Browse files
author
Chris Elion
authoredSep 9, 2020
allow ending the episode for MaxStepsReached (#4453)
* allow ending the episode for MaxStepsReached * changelog * rename and update docs
1 parent 9968f18 commit fce3521

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed
 

‎com.unity.ml-agents/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ and this project adheres to
1919
- Enabled C# formatting using `dotnet-format`. (#4362)
2020
- GridSensor was added to the com.unity.ml-agents.extensions package. Thank you
2121
to Jaden Travnik from Eidos Montreal for the contribution! (#4399)
22+
- Added `Agent.EpisodeInterrupted()`, which can be used to reset the agent when
23+
it has reached a user-determined maximum number of steps. This behaves similarly
24+
to `Agent.EndEpsiode()` but has a slightly different effect on training (#4453).
2225
#### ml-agents / ml-agents-envs / gym-unity (Python)
2326
- Experimental PyTorch support has been added. Use `--torch` when running `mlagents-learn`, or add
2427
`framework: pytorch` to your trainer configuration (under the behavior name) to enable it.

‎com.unity.ml-agents/Runtime/Agent.cs

+33-2
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ public void LazyInitialize()
445445
enum DoneReason
446446
{
447447
/// <summary>
448-
/// The <see cref="EndEpisode"/> method was called.
448+
/// The episode was ended manually by calling <see cref="EndEpisode"/>.
449449
/// </summary>
450450
DoneCalled,
451451

@@ -691,10 +691,41 @@ void UpdateRewardStats()
691691
/// <summary>
692692
/// Sets the done flag to true and resets the agent.
693693
/// </summary>
694+
/// <remarks>
695+
/// This should be used when the episode can no longer continue, such as when the Agent
696+
/// reaches the goal or fails at the task.
697+
/// </remarks>
694698
/// <seealso cref="OnEpisodeBegin"/>
699+
/// <seealso cref="EpisodeInterrupted"/>
695700
public void EndEpisode()
696701
{
697-
NotifyAgentDone(DoneReason.DoneCalled);
702+
EndEpisodeAndReset(DoneReason.DoneCalled);
703+
}
704+
705+
/// <summary>
706+
/// Indicate that the episode is over but not due to the "fault" of the Agent.
707+
/// This has the same end result as calling <see cref="EndEpisode"/>, but has a
708+
/// slightly different effect on training.
709+
/// </summary>
710+
/// <remarks>
711+
/// This should be used when the episode could continue, but has gone on for
712+
/// a sufficient number of steps.
713+
/// </remarks>
714+
/// <seealso cref="OnEpisodeBegin"/>
715+
/// <seealso cref="EndEpisode"/>
716+
public void EpisodeInterrupted()
717+
{
718+
EndEpisodeAndReset(DoneReason.MaxStepReached);
719+
}
720+
721+
722+
/// <summary>
723+
/// Internal method to end the episode and reset the Agent.
724+
/// </summary>
725+
/// <param name="reason"></param>
726+
void EndEpisodeAndReset(DoneReason reason)
727+
{
728+
NotifyAgentDone(reason);
698729
_AgentReset();
699730
}
700731

0 commit comments

Comments
 (0)
Please sign in to comment.