def generate_rollouts(self):
self.reset_all_rollouts()<EOL>o = np.empty((self.rollout_batch_size, self.dims['<STR_LIT:o>']), np.float32)  <EOL>ag = np.empty((self.rollout_batch_size, self.dims['<STR_LIT:g>']), np.float32)  <EOL>o[:] = self.initial_o<EOL>ag[:] = self.initial_ag<EOL>obs, achieved_goals, acts, goals, successes = [], [], [], [], []<EOL>dones = []<EOL>info_values = [np.empty((self.T - <NUM_LIT:1>, self.rollout_batch_size, self.dims['<STR_LIT>' + key]), np.float32) for key in self.info_keys]<EOL>Qs = []<EOL>for t in range(self.T):<EOL><INDENT>policy_output = self.policy.get_actions(<EOL>o, ag, self.g,<EOL>compute_Q=self.compute_Q,<EOL>noise_eps=self.noise_eps if not self.exploit else <NUM_LIT:0.>,<EOL>random_eps=self.random_eps if not self.exploit else <NUM_LIT:0.>,<EOL>use_target_net=self.use_target_net)<EOL>if self.compute_Q:<EOL><INDENT>u, Q = policy_output<EOL>Qs.append(Q)<EOL><DEDENT>else:<EOL><INDENT>u = policy_output<EOL><DEDENT>if u.ndim == <NUM_LIT:1>:<EOL><INDENT>u = u.reshape(<NUM_LIT:1>, -<NUM_LIT:1>)<EOL><DEDENT>o_new = np.empty((self.rollout_batch_size, self.dims['<STR_LIT:o>']))<EOL>ag_new = np.empty((self.rollout_batch_size, self.dims['<STR_LIT:g>']))<EOL>success = np.zeros(self.rollout_batch_size)<EOL>obs_dict_new, _, done, info = self.venv.step(u)<EOL>o_new = obs_dict_new['<STR_LIT>']<EOL>ag_new = obs_dict_new['<STR_LIT>']<EOL>success = np.array([i.get('<STR_LIT>', <NUM_LIT:0.0>) for i in info])<EOL>if any(done):<EOL><INDENT>break<EOL><DEDENT>for i, info_dict in enumerate(info):<EOL><INDENT>for idx, key in enumerate(self.info_keys):<EOL><INDENT>info_values[idx][t, i] = info[i][key]<EOL><DEDENT><DEDENT>if np.isnan(o_new).any():<EOL><INDENT>self.logger.warn('<STR_LIT>')<EOL>self.reset_all_rollouts()<EOL>return self.generate_rollouts()<EOL><DEDENT>dones.append(done)<EOL>obs.append(o.copy())<EOL>achieved_goals.append(ag.copy())<EOL>successes.append(success.copy())<EOL>acts.append(u.copy())<EOL>goals.append(self.g.copy())<EOL>o[...] = o_new<EOL>ag[...] = ag_new<EOL><DEDENT>obs.append(o.copy())<EOL>achieved_goals.append(ag.copy())<EOL>episode = dict(o=obs,<EOL>u=acts,<EOL>g=goals,<EOL>ag=achieved_goals)<EOL>for key, value in zip(self.info_keys, info_values):<EOL><INDENT>episode['<STR_LIT>'.format(key)] = value<EOL><DEDENT>successful = np.array(successes)[-<NUM_LIT:1>, :]<EOL>assert successful.shape == (self.rollout_batch_size,)<EOL>success_rate = np.mean(successful)<EOL>self.success_history.append(success_rate)<EOL>if self.compute_Q:<EOL><INDENT>self.Q_history.append(np.mean(Qs))<EOL><DEDENT>self.n_episodes += self.rollout_batch_size<EOL>return convert_episode_to_batch_major(episode)<EOL>
Performs `rollout_batch_size` rollouts in parallel for time horizon `T` with the current
        policy acting on it accordingly.