Beispiel #1
0
    def __init__(self, envs):
        # export observation space & action space
        self.observation_space = [e.observation_space for e in envs]
        self.action_space = [e.action_space for e in envs]

        self._envs = envs
        self._par = RunParallel()
Beispiel #2
0
class VecEnv(gym.Env):
    """Vectorize a list of environments as a single environment."""
    def __init__(self, envs):
        self.observation_space = Tuple([e.observation_space for e in envs])
        self.action_space = Tuple([e.action_space for e in envs])

        self._envs = envs
        self._par = RunParallel()

    def reset(self):
        # self.close()
        # os.system('pkill -9 vizdoom')
        observations = self._par.run((e.reset) for e in self._envs)
        return observations

    def step(self, actions):
        ret = self._par.run(
            (e.step, act) for e, act in zip(self._envs, actions))
        observations, rewards, dones, infos = [item for item in zip(*ret)]
        # print('VecEnv/infos')
        # print(infos)
        # return observations, rewards, dones, infos
        return observations, rewards, dones, {}

    def close(self):
        self._par.run((e.close) for e in self._envs)

    def render(self, *args):
        obs = self._par.run((e.render) for e in self._envs)
        return obs

    @property
    def envs(self):
        return self._envs
Beispiel #3
0
class VecEnv(gym.Env):
    # TODO(pengsun): delete/trim this class
    def __init__(self, envs):
        # export observation space & action space
        self.observation_space = [e.observation_space for e in envs]
        self.action_space = [e.action_space for e in envs]

        self._envs = envs
        self._par = RunParallel()

    def reset(self):
        observations = self._par.run((e.reset) for e in self._envs)
        return observations

    def step(self, actions):
        ret = self._par.run(
            (e.step, act) for e, act in zip(self._envs, actions))
        observations, rewards, dones, infos = [item for item in zip(*ret)]
        return observations, rewards, dones, infos

    def close(self):
        self._par.run((e.close) for e in self._envs)

    def render(self, *args):
        obs = self._par.run((e.render) for e in self._envs)
        return obs

    @property
    def envs(self):
        return self._envs
Beispiel #4
0
    def __init__(self, envs):
        self.observation_space = Tuple([e.observation_space for e in envs])
        self.action_space = Tuple([e.action_space for e in envs])

        self._envs = envs
        self._par = RunParallel()