예제 #1
0
    def create_remote_workers(self, cls, num_actors, agent_config, worker_spec,
                              *args):
        """
        Creates Ray actors for remote execution.

        Args:
            cls (Union[RayValueWorker, RayPolicyWorker]): RayActor class.
            num_actors (int): Num RayActor to create.
            agent_config (dict): Agent config.
            worker_spec (dict): Worker spec.
            *args (any): Arguments for RayActor class.

        Returns:
            list: Remote Ray actors.
        """
        workers = []
        cls_as_remote = cls.as_remote(num_cpus=self.num_cpus_per_worker,
                                      num_gpus=self.num_gpus_per_worker).remote

        # Create remote objects and schedule init tasks.
        ray_constant_exploration = worker_spec.get("ray_constant_exploration",
                                                   False)
        for i in range_(num_actors):
            if ray_constant_exploration is True:
                exploration_val = worker_exploration(i, num_actors)
                worker_spec["ray_exploration"] = exploration_val
            worker = cls_as_remote(deepcopy(agent_config), worker_spec, *args)
            self.worker_ids[worker] = "worker_{}".format(i)
            workers.append(worker)
            self.logger.info("Successfully built agent num {}.".format(i))

        return workers
예제 #2
0
    def create_remote_workers(self, cls, num_actors, agent_config, worker_spec,
                              *args):
        """
        Creates Ray actors for remote execution.

        Args:
            cls (RayWorker): Actor class, must be an instance of RayWorker.
            num_actors (int): Num
            agent_config (dict): Agent config.
            worker_spec (dict): Worker spec.
            *args (any): Arguments for RayWorker class.

        Returns:
            list: Remote Ray actors.
        """
        workers = []
        init_tasks = []

        cls_as_remote = cls.as_remote(num_cpus=self.num_cpus_per_worker,
                                      num_gpus=self.num_gpus_per_worker).remote

        # Create remote objects and schedule init tasks.
        ray_constant_exploration = worker_spec.get("ray_constant_exploration",
                                                   False)
        for i in range_(num_actors):
            if ray_constant_exploration is True:
                exploration_val = worker_exploration(i, num_actors)
                worker_spec["ray_exploration"] = exploration_val
            worker = cls_as_remote(deepcopy(agent_config), worker_spec, *args)
            self.worker_ids[worker] = "worker_{}".format(i)
            workers.append(worker)
            build_result = worker.init_agent.remote()
            init_tasks.append(build_result)

        ready, not_ready = ray.wait(init_tasks, num_returns=len(init_tasks))

        for i, res in enumerate(ready):
            result = ray.get(res)
            if result:
                self.logger.info("Successfully built agent num {}.".format(i))

        return workers