|
|
|
|
|
|
class EnvironmentCommand(enum.Enum): |
|
|
|
STEP = 1 |
|
|
|
EXTERNAL_BRAINS = 2 |
|
|
|
GET_PROPERTIES = 3 |
|
|
|
ENVIRONMENT_PARAMETERS = 3 |
|
|
|
RESET = 4 |
|
|
|
CLOSE = 5 |
|
|
|
ENV_EXITED = 6 |
|
|
|
|
|
|
reset_timers() |
|
|
|
elif req.cmd == EnvironmentCommand.EXTERNAL_BRAINS: |
|
|
|
_send_response(EnvironmentCommand.EXTERNAL_BRAINS, external_brains()) |
|
|
|
elif req.cmd == EnvironmentCommand.RESET: |
|
|
|
elif req.cmd == EnvironmentCommand.ENVIRONMENT_PARAMETERS: |
|
|
|
elif req.cmd == EnvironmentCommand.RESET: |
|
|
|
env.reset() |
|
|
|
all_step_result = _generate_all_results() |
|
|
|
_send_response(EnvironmentCommand.RESET, all_step_result) |
|
|
|
|
|
|
if not self.step_queue.empty(): |
|
|
|
step = self.step_queue.get_nowait() |
|
|
|
self.env_workers[step.worker_id].waiting = False |
|
|
|
# Send config to environment |
|
|
|
self.set_env_parameters(config) |
|
|
|
# First enqueue reset commands for all workers so that they reset in parallel |
|
|
|
for ew in self.env_workers: |
|
|
|
ew.send(EnvironmentCommand.RESET, config) |
|
|
|
|
|
|
return list(map(lambda ew: ew.previous_step, self.env_workers)) |
|
|
|
|
|
|
|
def set_env_parameters(self, config: Dict = None) -> None: |
|
|
|
""" |
|
|
|
Sends environment parameter settings to C# via the |
|
|
|
EnvironmentParametersSidehannel for each worker. |
|
|
|
:param config: Dict of environment parameter keys and values |
|
|
|
""" |
|
|
|
for ew in self.env_workers: |
|
|
|
ew.send(EnvironmentCommand.ENVIRONMENT_PARAMETERS, config) |
|
|
|
|
|
|
|
@property |
|
|
|
def external_brains(self) -> Dict[BehaviorName, BrainParameters]: |
|
|
|