예제 #1
0
    def __init__(
            self,
            envs_dir,
            experimental_read_from_local_dir=False,
            _add_to_name="",  # internal, for test only, do not use !
            _compat_glop_version=None,  # internal, for test only, do not use !
            _test=False,
            **kwargs):
        GridObjects.__init__(self)
        RandomObject.__init__(self)
        self.current_env = None
        self.env_index = None
        self.mix_envs = []
        self._env_dir = os.path.abspath(envs_dir)

        # Special case handling for backend
        # TODO: with backend.copy() instead !
        backendClass = None
        if "backend" in kwargs:
            backendClass = type(kwargs["backend"])
            del kwargs["backend"]

        # Inline import to prevent cyclical import
        from grid2op.MakeEnv.Make import make

        # TODO reuse same observation_space and action_space in all the envs maybe ?
        try:
            for env_dir in sorted(os.listdir(envs_dir)):
                env_path = os.path.join(envs_dir, env_dir)
                if not os.path.isdir(env_path):
                    continue
                # Special case for backend
                if backendClass is not None:
                    env = make(env_path,
                               backend=backendClass(),
                               _add_to_name=_add_to_name,
                               _compat_glop_version=_compat_glop_version,
                               test=_test,
                               experimental_read_from_local_dir=
                               experimental_read_from_local_dir,
                               **kwargs)
                else:
                    env = make(env_path,
                               _add_to_name=_add_to_name,
                               _compat_glop_version=_compat_glop_version,
                               test=_test,
                               experimental_read_from_local_dir=
                               experimental_read_from_local_dir,
                               **kwargs)
                self.mix_envs.append(env)
        except Exception as exc_:
            err_msg = "MultiMix environment creation failed: {}".format(exc_)
            raise EnvError(err_msg)

        if len(self.mix_envs) == 0:
            err_msg = "MultiMix envs_dir did not contain any valid env"
            raise EnvError(err_msg)

        self.env_index = 0
        self.current_env = self.mix_envs[self.env_index]
        # Make sure GridObject class attributes are set from first env
        # Should be fine since the grid is the same for all envs
        multi_env_name = os.path.basename(
            os.path.abspath(envs_dir)) + _add_to_name
        save_env_name = self.current_env.env_name
        self.current_env.env_name = multi_env_name
        self.__class__ = self.init_grid(self.current_env)
        self.current_env.env_name = save_env_name
예제 #2
0
 def __init__(self, action_space):
     RandomObject.__init__(self)
     self.action_space = action_space
     self._do_nothing = self.action_space()
예제 #3
0
 def __init__(self, action_space):
     RandomObject.__init__(self)
     self.action_space = copy.deepcopy(action_space)