37
37
from cylc .flow .task_proxy import TaskProxy
38
38
39
39
40
- # Exotic: Recursive Type hint.
41
- NestedDict = Dict [str , Union ['NestedDict' , Any ]]
40
+ SIMULATION_CONFIGS = ['simulation' , 'execution time limit' ]
42
41
43
42
44
43
def configure_sim_modes (taskdefs , sim_mode ):
@@ -55,7 +54,6 @@ def configure_rtc_sim_mode(rtc, dummy_mode):
55
54
"""Change a task proxy's runtime config to simulation mode settings.
56
55
"""
57
56
sleep_sec = get_simulated_run_len (rtc )
58
-
59
57
rtc ['execution time limit' ] = (
60
58
sleep_sec + DurationParser ().parse (str (
61
59
rtc ['simulation' ]['time limit buffer' ])).get_seconds ()
@@ -70,10 +68,9 @@ def configure_rtc_sim_mode(rtc, dummy_mode):
70
68
rtc ['env-script' ] = ""
71
69
rtc ['pre-script' ] = ""
72
70
rtc ['post-script' ] = ""
71
+ rtc ['err-script' ] = ""
73
72
rtc ['script' ] = build_dummy_script (
74
- rtc , sleep_sec ) if dummy_mode else ""
75
- else :
76
- rtc ['script' ] = ""
73
+ rtc , sleep_sec )
77
74
78
75
disable_platforms (rtc )
79
76
@@ -111,7 +108,9 @@ def get_simulated_run_len(rtc: Dict[str, Any]) -> int:
111
108
else :
112
109
sleep_sec = rtc ['simulation' ]['default run length' ]
113
110
else :
114
- if limit and speedup :
111
+ if limit and speedup and isinstance (limit , float ):
112
+ sleep_sec = limit / speedup
113
+ elif limit and speedup :
115
114
sleep_sec = (DurationParser ().parse (
116
115
str (limit )).get_seconds () / speedup )
117
116
else :
@@ -183,60 +182,6 @@ def parse_fail_cycle_points(
183
182
return f_pts
184
183
185
184
186
- def unpack_dict (dict_ : NestedDict , parent_key : str = '' ) -> Dict [str , Any ]:
187
- """Unpack a nested dict into a single layer.
188
-
189
- Examples:
190
- >>> unpack_dict({'foo': 1, 'bar': {'baz': 2, 'qux':3}})
191
- {'foo': 1, 'bar.baz': 2, 'bar.qux': 3}
192
- >>> unpack_dict({'foo': {'example': 42}, 'bar': {"1":2, "3":4}})
193
- {'foo.example': 42, 'bar.1': 2, 'bar.3': 4}
194
-
195
- """
196
- output = {}
197
- for key , value in dict_ .items ():
198
- new_key = parent_key + '.' + key if parent_key else key
199
- if isinstance (value , dict ):
200
- output .update (unpack_dict (value , new_key ))
201
- else :
202
- output [new_key ] = value
203
-
204
- return output
205
-
206
-
207
- def nested_dict_path_update (
208
- dict_ : NestedDict , path : List [Any ], value : Any
209
- ) -> NestedDict :
210
- """Set a value in a nested dict.
211
-
212
- Examples:
213
- >>> nested_dict_path_update({'foo': {'bar': 1}}, ['foo', 'bar'], 42)
214
- {'foo': {'bar': 42}}
215
- """
216
- this = dict_
217
- for i in range (len (path )):
218
- if isinstance (this [path [i ]], dict ):
219
- this = this [path [i ]]
220
- else :
221
- this [path [i ]] = value
222
- return dict_
223
-
224
-
225
- def update_nested_dict (rtc : NestedDict , dict_ : NestedDict ) -> None :
226
- """Update one config nested dictionary with the contents of another.
227
-
228
- Examples:
229
- >>> x = {'foo': {'bar': 12}, 'qux': 77}
230
- >>> y = {'foo': {'bar': 42}}
231
- >>> update_nested_dict(x, y)
232
- >>> print(x)
233
- {'foo': {'bar': 42}, 'qux': 77}
234
- """
235
- for keylist , value in unpack_dict (dict_ ).items ():
236
- keys = keylist .split ('.' )
237
- rtc = nested_dict_path_update (rtc , keys , value )
238
-
239
-
240
185
def sim_time_check (
241
186
message_queue : 'Queue[TaskMsg]' ,
242
187
itasks : 'List[TaskProxy]' ,
@@ -250,16 +195,22 @@ def sim_time_check(
250
195
251
196
Returns:
252
197
True if _any_ simulated task state has changed.
253
- """
254
198
199
+ """
255
200
sim_task_state_changed = False
256
201
now = time ()
257
202
for itask in itasks :
258
203
if broadcast_mgr :
259
204
broadcast = broadcast_mgr .get_broadcast (itask .tokens )
260
205
if broadcast :
261
- update_nested_dict (
262
- itask .tdef .rtconfig , broadcast )
206
+ for config in SIMULATION_CONFIGS :
207
+ if (
208
+ config in broadcast
209
+ and isinstance (broadcast [config ], dict )
210
+ ):
211
+ itask .tdef .rtconfig [config ].update (broadcast [config ])
212
+ elif config in broadcast :
213
+ itask .tdef .rtconfig [config ] = broadcast [config ]
263
214
configure_rtc_sim_mode (itask .tdef .rtconfig , False )
264
215
if itask .state .status != TASK_STATUS_RUNNING :
265
216
continue
0 commit comments