visualization/rollout.py
def rollout(self, horizon=50, save_path=None):
        """ Rollout several timesteps of an episode of the environment.

        Args:
            horizon: The number of timesteps to roll out.
            save_path: If provided, will save each frame to disk at this
                location.
        """
        rewards = []
        observations = []
        shape = self.env.world_map.shape
        full_obs = [np.zeros((shape[0], shape[1], 3), dtype=np.uint8) for i in range(horizon)]

        for i in range(horizon):
            agents = list(self.env.agents.values())
            action_dim = self.env.action_space.n
            agent_action_dict = dict()
            for agent in agents:
                rand_action = np.random.randint(action_dim)
                agent_action_dict[agent.agent_id] = rand_action
            obs, rew, dones, info, = self.env.step(agent_action_dict)

            sys.stdout.flush()

            if save_path is not None:
                self.env.render(filename=save_path + "frame" + str(i).zfill(6) + ".png")
                if i % 10 == 0:
                    print("Saved frame " + str(i) + "/" + str(horizon))

            rgb_arr = self.env.full_map_to_colors()
            full_obs[i] = rgb_arr.astype(np.uint8)
            observations.append(obs["agent-0"])
            rewards.append(rew["agent-0"])

            if dones["__all__"]:
                print("Environment ended early because all agents were done.")
                break

        return rewards, observations, full_obs
 Rollout several timesteps of an episode of the environment.

        Args:
            horizon: The number of timesteps to roll out.
            save_path: If provided, will save each frame to disk at this
                location.
        
Rollout several timesteps of an episode of the environment.
Rollout several timesteps of an episode of the environment .
def rollout(self, horizon=50, save_path=None):
        rewards = []
        observations = []
        shape = self.env.world_map.shape
        full_obs = [np.zeros((shape[0], shape[1], 3), dtype=np.uint8) for i in range(horizon)]
        for i in range(horizon):
            agents = list(self.env.agents.values())
            action_dim = self.env.action_space.n
            agent_action_dict = dict()
            for agent in agents:
                rand_action = np.random.randint(action_dim)
                agent_action_dict[agent.agent_id] = rand_action
            obs, rew, dones, info, = self.env.step(agent_action_dict)
            sys.stdout.flush()
            if save_path is not None:
                self.env.render(filename=save_path + "frame" + str(i).zfill(6) + ".png")
                if i % 10 == 0:
                    print("Saved frame " + str(i) + "/" + str(horizon))
            rgb_arr = self.env.full_map_to_colors()
            full_obs[i] = rgb_arr.astype(np.uint8)
            observations.append(obs["agent-0"])
            rewards.append(rew["agent-0"])
            if dones["__all__"]:
                print("Environment ended early because all agents were done.")
                break
        return rewards, observations, full_obs
def rollout ( self , horizon = 50 , save_path = None ) : rewards = [ ] observations = [ ] shape = self . env . world_map . shape full_obs = [ np . zeros ( ( shape [ 0 ] , shape [ 1 ] , 3 ) , dtype = np . uint8 ) for i in range ( horizon ) ] for i in range ( horizon ) : agents = list ( self . env . agents . values ( ) ) action_dim = self . env . action_space . n agent_action_dict = dict ( ) for agent in agents : rand_action = np . random . randint ( action_dim ) agent_action_dict [ agent . agent_id ] = rand_action obs , rew , dones , info , = self . env . step ( agent_action_dict ) sys . stdout . flush ( ) if save_path is not None : self . env . render ( filename = save_path + "frame" + str ( i ) . zfill ( 6 ) + ".png" ) if i % 10 == 0 : print ( "Saved frame " + str ( i ) + "/" + str ( horizon ) ) rgb_arr = self . env . full_map_to_colors ( ) full_obs [ i ] = rgb_arr . astype ( np . uint8 ) observations . append ( obs [ "agent-0" ] ) rewards . append ( rew [ "agent-0" ] ) if dones [ "__all__" ] : print ( "Environment ended early because all agents were done." ) break return rewards , observations , full_obs
Rollout several timesteps of an episode of the environment.
Rollout several timesteps of an episode of the environment .
""" Rollout several timesteps of an episode of the environment.

        Args:
            horizon: The number of timesteps to roll out.
            save_path: If provided, will save each frame to disk at this
                location.
        """
self
horizon
The number of timesteps to roll out.
The number of timesteps to roll out .
save_path
If provided, will save each frame to disk at this
location.
If provided will save each frame to disk at this location .