46
46
class EnvironmentCommand (enum .Enum ):
47
47
STEP = 1
48
48
EXTERNAL_BRAINS = 2
49
- GET_PROPERTIES = 3
49
+ ENVIRONMENT_PARAMETERS = 3
50
50
RESET = 4
51
51
CLOSE = 5
52
52
ENV_EXITED = 6
@@ -174,12 +174,13 @@ def external_brains():
174
174
reset_timers ()
175
175
elif req .cmd == EnvironmentCommand .EXTERNAL_BRAINS :
176
176
_send_response (EnvironmentCommand .EXTERNAL_BRAINS , external_brains ())
177
- elif req .cmd == EnvironmentCommand .RESET :
177
+ elif req .cmd == EnvironmentCommand .ENVIRONMENT_PARAMETERS :
178
178
for k , v in req .payload .items ():
179
179
if isinstance (v , float ):
180
180
env_parameters .set_float_parameter (k , v )
181
181
elif isinstance (v , ParameterRandomizationSettings ):
182
182
v .apply (k , env_parameters )
183
+ elif req .cmd == EnvironmentCommand .RESET :
183
184
env .reset ()
184
185
all_step_result = _generate_all_results ()
185
186
_send_response (EnvironmentCommand .RESET , all_step_result )
@@ -291,6 +292,8 @@ def _reset_env(self, config: Optional[Dict] = None) -> List[EnvironmentStep]:
291
292
if not self .step_queue .empty ():
292
293
step = self .step_queue .get_nowait ()
293
294
self .env_workers [step .worker_id ].waiting = False
295
+ # Send config to environment
296
+ self .set_env_parameters (config )
294
297
# First enqueue reset commands for all workers so that they reset in parallel
295
298
for ew in self .env_workers :
296
299
ew .send (EnvironmentCommand .RESET , config )
@@ -299,6 +302,15 @@ def _reset_env(self, config: Optional[Dict] = None) -> List[EnvironmentStep]:
299
302
ew .previous_step = EnvironmentStep (ew .recv ().payload , ew .worker_id , {}, {})
300
303
return list (map (lambda ew : ew .previous_step , self .env_workers ))
301
304
305
+ def set_env_parameters (self , config : Dict = None ) -> None :
306
+ """
307
+ Sends environment parameter settings to C# via the
308
+ EnvironmentParametersSidehannel for each worker.
309
+ :param config: Dict of environment parameter keys and values
310
+ """
311
+ for ew in self .env_workers :
312
+ ew .send (EnvironmentCommand .ENVIRONMENT_PARAMETERS , config )
313
+
302
314
@property
303
315
def external_brains (self ) -> Dict [BehaviorName , BrainParameters ]:
304
316
self .env_workers [0 ].send (EnvironmentCommand .EXTERNAL_BRAINS )
0 commit comments