(env, action_function)
return path
Builds a path by running through an environment using a provided function to select actions.
Builds a path by running through an environment using a provided function to select actions.
Builds a path by running through an environment using a provided function to select actions .
def do_rollout(env, action_function):
    """ Builds a path by running through an environment using a provided function to select actions. """
    obs, rewards, actions, human_obs = [], [], [], []
    max_timesteps_per_episode = get_timesteps_per_episode(env)
    ob = env.reset()
    # Primary environment loop
    for i in range(max_timesteps_per_episode):
        action = action_function(env, ob)
        obs.append(ob)
        actions.append(action)
        ob, rew, done, info = env.step(action)
        rewards.append(rew)
        human_obs.append(info.get("human_obs"))
        if done:
            break
    # Build path dictionary
    path = {
        "obs": np.array(obs),
        "original_rewards": np.array(rewards),
        "actions": np.array(actions),
        "human_obs": np.array(human_obs)}
    return path
def do_rollout ( env , action_function ) : obs , rewards , actions , human_obs = [ ] , [ ] , [ ] , [ ] max_timesteps_per_episode = get_timesteps_per_episode ( env ) ob = env . reset ( ) # Primary environment loop for i in range ( max_timesteps_per_episode ) : action = action_function ( env , ob ) obs . append ( ob ) actions . append ( action ) ob , rew , done , info = env . step ( action ) rewards . append ( rew ) human_obs . append ( info . get ( "human_obs" ) ) if done : break # Build path dictionary path = { "obs" : np . array ( obs ) , "original_rewards" : np . array ( rewards ) , "actions" : np . array ( actions ) , "human_obs" : np . array ( human_obs ) } return path