class local_env(object): def __init__(self, env_id): remote_base = 'http://127.0.0.1:5000' self.client = Client(remote_base) self.instance_id = self.client.env_create(env_id) def reset(self): obs = self.client.env_reset(self.instance_id) return obs def step(self, action): #print("---sssss---------",type(action),action.item()) [observation, reward, done, info] = self.client.env_step(self.instance_id, action.item(), True) return observation, reward, done, info def action_space_sample(self): action = self.client.env_action_space_sample(self.instance_id) return action def action_space_info(self): info = self.client.env_action_space_info(self.instance_id) return info def observation_space_info(self): info = self.client.env_observation_space_info(self.instance_id) return info
# Run experiment, with monitor outdir = '/tmp/random-agent-results' client.env_monitor_start(instance_id, outdir, force=True) episode_count = 100 max_steps = 200 reward = 0 done = False for i in range(episode_count): ob = client.env_reset(instance_id) for j in range(max_steps): action = agent.act(ob, reward, done) ob, reward, done, _ = client.env_step(instance_id, action, True) if done: break # Dump result info to disk client.env_monitor_close(instance_id) # Upload to the scoreboard. This expects the 'OPENAI_GYM_API_KEY' # environment variable to be set on the client side. logger.info("""Successfully ran example agent using gym_http_client. Now trying to upload results to the scoreboard. If this fails, you likely need to set os.environ['OPENAI_GYM_API_KEY']=<your_api_key>""") client.upload(outdir)
resume=False, video_callable=False) episode_count = 100 max_steps = 200 reward = 0 done = False for i in range(episode_count): ob = client.env_reset(instance_id) for j in range(max_steps): # action = agent.act(ob, reward, done) action = client.env_action_space_sample(instance_id) ob, reward, done, _ = client.env_step(instance_id, action, render=False) if done: break # Dump result info to disk client.env_monitor_close(instance_id) # Upload to the scoreboard. This expects the 'OPENAI_GYM_API_KEY' # environment variable to be set on the client side. logger.info("""Successfully ran example agent using gym_http_client. Now trying to upload results to the scoreboard. If this fails, you likely need to set os.environ['OPENAI_GYM_API_KEY']=<your_api_key>""") client.upload(outdir)