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
from gym_http_client import Client class RandomDiscreteAgent(object): def __init__(self, n): self.n = n def act(self, observation, reward, done): return np.random.randint(self.n) if __name__ == '__main__': logger = logging.getLogger() logger.setLevel(logging.INFO) # Set up client remote_base = 'http://127.0.0.1:5000' client = Client(remote_base) # Set up environment env_id = 'CartPole-v0' instance_id = client.env_create(env_id) # Set up agent action_space_info = client.env_action_space_info(instance_id) agent = RandomDiscreteAgent(action_space_info['n']) # Run experiment, with monitor outdir = '/tmp/random-agent-results' client.env_monitor_start(instance_id, outdir, force=True) episode_count = 100 max_steps = 200
class RandomDiscreteAgent(object): def __init__(self, n): self.n = n def act(self, observation, reward, done): return np.random.randint(self.n) if __name__ == '__main__': logger = logging.getLogger() logger.setLevel(logging.INFO) # Set up client remote_base = 'http://127.0.0.1:5000' client = Client(remote_base) # Set up environment env_id = 'CartPole-v0' instance_id = client.env_create(env_id) # Set up agent action_space_info = client.env_action_space_info(instance_id) agent = RandomDiscreteAgent(action_space_info['n']) # Run experiment, with monitor outdir = '/tmp/random-agent-results' client.env_monitor_start(instance_id, outdir, force=True, resume=False,
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)
import logging from gym_http_client import Client class RandomDiscreteAgent(object): def __init__(self, n): self.n = n if __name__ == '__main__': logger = logging.getLogger() logger.setLevel(logging.INFO) # Set up client remote_base = 'http://127.0.0.1:5000' client = Client(remote_base) # Set up environment env_id = 'CartPole-v0' instance_id = client.env_create(env_id) # Set up agent action_space_info = client.env_action_space_info(instance_id) agent = RandomDiscreteAgent(action_space_info['n']) # Run experiment, with monitor outdir = '/tmp/random-agent-results' client.env_monitor_start(instance_id, outdir, force=True, resume=False, video_callable=False) episode_count = 100 max_steps = 200 reward = 0
class RandomDiscreteAgent(object): def __init__(self, n): self.n = n def act(self, observation, reward, done): return np.random.randint(self.n) if __name__ == '__main__': logger = logging.getLogger() logger.setLevel(logging.INFO) # Set up client remote_base = 'http://127.0.0.1:5000' client = Client(remote_base) # Set up environment env_id = 'CartPole-v0' instance_id = client.env_create(env_id) # Set up agent action_space_info = client.env_action_space_info(instance_id) agent = RandomDiscreteAgent(action_space_info['n']) # Run experiment, with monitor outdir = '/tmp/random-agent-results' client.env_monitor_start(instance_id, outdir, force=True) episode_count = 100 max_steps = 200