@@ -28,6 +28,7 @@ public class ModelOverrider : MonoBehaviour
28
28
const string k_CommandLineModelOverrideDirectoryFlag = "--mlagents-override-model-directory" ;
29
29
const string k_CommandLineModelOverrideExtensionFlag = "--mlagents-override-model-extension" ;
30
30
const string k_CommandLineQuitAfterEpisodesFlag = "--mlagents-quit-after-episodes" ;
31
+ const string k_CommandLineQuitAfterSeconds = "--mlagents-quit-after-seconds" ;
31
32
const string k_CommandLineQuitOnLoadFailure = "--mlagents-quit-on-load-failure" ;
32
33
33
34
// The attached Agent
@@ -45,6 +46,9 @@ public class ModelOverrider : MonoBehaviour
45
46
// Will default to 1 if override models are specified, otherwise 0.
46
47
int m_MaxEpisodes ;
47
48
49
+ // Deadline - exit if the time exceeds this
50
+ DateTime m_Deadline = DateTime . MaxValue ;
51
+
48
52
int m_NumSteps ;
49
53
int m_PreviousNumSteps ;
50
54
int m_PreviousAgentCompletedEpisodes ;
@@ -89,6 +93,8 @@ public static string GetOverrideBehaviorName(string originalBehaviorName)
89
93
void GetAssetPathFromCommandLine ( )
90
94
{
91
95
var maxEpisodes = 0 ;
96
+ var timeoutSeconds = 0 ;
97
+
92
98
string [ ] commandLineArgsOverride = null ;
93
99
if ( ! string . IsNullOrEmpty ( debugCommandLineOverride ) && Application . isEditor )
94
100
{
@@ -120,6 +126,10 @@ void GetAssetPathFromCommandLine()
120
126
{
121
127
Int32 . TryParse ( args [ i + 1 ] , out maxEpisodes ) ;
122
128
}
129
+ else if ( args [ i ] == k_CommandLineQuitAfterSeconds && i < args . Length - 1 )
130
+ {
131
+ Int32 . TryParse ( args [ i + 1 ] , out timeoutSeconds ) ;
132
+ }
123
133
else if ( args [ i ] == k_CommandLineQuitOnLoadFailure )
124
134
{
125
135
m_QuitOnLoadFailure = true ;
@@ -132,6 +142,13 @@ void GetAssetPathFromCommandLine()
132
142
m_MaxEpisodes = maxEpisodes > 0 ? maxEpisodes : 1 ;
133
143
Debug . Log ( $ "setting m_MaxEpisodes to { maxEpisodes } ") ;
134
144
}
145
+
146
+ if ( timeoutSeconds > 0 )
147
+ {
148
+ m_Deadline = DateTime . Now + TimeSpan . FromSeconds ( timeoutSeconds ) ;
149
+ Debug . Log ( $ "setting deadline to { timeoutSeconds } from now.") ;
150
+
151
+ }
135
152
}
136
153
137
154
void OnEnable ( )
@@ -172,9 +189,21 @@ void FixedUpdate()
172
189
Application . Quit ( 0 ) ;
173
190
#if UNITY_EDITOR
174
191
EditorApplication . isPlaying = false ;
192
+ #endif
193
+ }
194
+ else if ( DateTime . Now >= m_Deadline )
195
+ {
196
+ Debug . Log (
197
+ $ "Deadline exceeded. " +
198
+ $ "{ TotalCompletedEpisodes } /{ m_MaxEpisodes } episodes and " +
199
+ $ "{ TotalNumSteps } /{ m_MaxEpisodes * m_Agent . MaxStep } steps completed. Exiting.") ;
200
+ Application . Quit ( 0 ) ;
201
+ #if UNITY_EDITOR
202
+ EditorApplication . isPlaying = false ;
175
203
#endif
176
204
}
177
205
}
206
+
178
207
m_NumSteps ++ ;
179
208
}
180
209
0 commit comments