コード例 #1
0
    def __init__(self, exec_path, env_path):

        self.handle = "environment"
        self.mem = _GodotEnv.SharedMemoryTensor(self.handle)
        self.sem_act = _GodotEnv.SharedMemorySemaphore("sem_action", 0)
        self.sem_obs = _GodotEnv.SharedMemorySemaphore("sem_observation", 0)

        #Important: if this process is called with subprocess.PIPE, the semaphores will be stuck in impossible combination
        with open("stdout.txt", "wb") as out, open("stderr.txt", "wb") as err:
            self.process = subprocess.Popen([
                exec_path, "--path",
                os.path.abspath(env_path), "--handle", self.handle
            ],
                                            stdout=out,
                                            stderr=err)

        #Array to manipulate the state of the simulator
        self.env_action = torch.zeros(2, dtype=torch.int, device='cpu')
        self.env_action[0] = 0  #1 = reset
        self.env_action[1] = 0  #1 = exit

        #Example of agent action
        self.agent_action = torch.zeros(2, dtype=torch.float, device='cpu')

        high = np.array([1., 1., 1., 1., 1., 1., 1., 1.])
        self.action_space = spaces.Box(low=-1.0,
                                       high=1.0,
                                       shape=(2, ),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(low=-high,
                                            high=high,
                                            dtype=np.float32)

        atexit.register(self.close)
コード例 #2
0
ファイル: InvPendulum.py プロジェクト: lupoglaz/GodotAIGym
    def __init__(self,
                 exec_path,
                 env_path,
                 num_actions=1,
                 num_observations=3,
                 render=True):
        self.handle = "environment"
        self.mem = _GodotEnv.SharedMemoryTensor(self.handle)
        self.sem_act = _GodotEnv.SharedMemorySemaphore("sem_action", 0)
        self.sem_obs = _GodotEnv.SharedMemorySemaphore("sem_observation", 0)

        self.agent_action_tensor = self.mem.newFloatTensor(
            "agent_action", num_actions)
        self.env_action_tensor = self.mem.newIntTensor("env_action", 2)
        self.observation_tensor = self.mem.newFloatTensor(
            "observation", num_observations)
        self.reward_tensor = self.mem.newFloatTensor("reward", 1)
        self.done_tensor = self.mem.newIntTensor("done", 1)

        #Important: if this process is called with subprocess.PIPE, the semaphores will be stuck in impossible combination
        with open("stdout.txt", "wb") as out, open("stderr.txt", "wb") as err:
            if render:
                self.process = subprocess.Popen([
                    exec_path, "--path",
                    os.path.abspath(env_path), "--handle", self.handle
                ],
                                                stdout=out,
                                                stderr=err)
            else:
                self.process = subprocess.Popen([
                    exec_path, "--path",
                    os.path.abspath(env_path), "--disable-render-loop",
                    "--handle", self.handle
                ],
                                                stdout=out,
                                                stderr=err)

        #Array to manipulate the state of the simulator
        self.env_action = torch.zeros(2, dtype=torch.int, device='cpu')
        self.env_action[0] = 0  #1 = reset
        self.env_action[1] = 0  #1 = exit

        #Example of agent action
        self.agent_action = torch.zeros(1, dtype=torch.float, device='cpu')

        self.max_torque = 8.0
        self.max_speed = 8

        self.action_space = spaces.Box(low=-self.max_torque,
                                       high=self.max_torque,
                                       shape=(num_actions, ),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(low=-1.0,
                                            high=1.0,
                                            shape=(num_observations, ),
                                            dtype=np.float32)

        atexit.register(self.close)
コード例 #3
0
    def __init__(self, exec_path, env_path):

        self.steps = 0
        self.max_steps = 200

        self.min_position = 150
        self.max_position = 400
        self.max_speed = 450
        self.rotation = 2 * np.pi
        self.low = np.array(
            [self.min_position, -self.max_speed, -self.rotation],
            dtype=np.float32)
        self.high = np.array(
            [self.max_position, self.max_speed, -self.rotation],
            dtype=np.float32)

        self.handle = "Environment"
        self.mem = _GodotEnv.SharedMemoryTensor(self.handle)
        self.sem_act = _GodotEnv.SharedMemorySemaphore("sem_action", 0)
        self.sem_obs = _GodotEnv.SharedMemorySemaphore("sem_observation", 0)

        #Important: if this process is called with subprocess.PIPE, the semaphores will be stuck in impossible combination
        with open("stdout.txt", "wb") as out, open("stderr.txt", "wb") as err:
            self.process = subprocess.Popen([
                exec_path, "--path",
                os.path.abspath(env_path), "--handle", self.handle
            ],
                                            stdout=out,
                                            stderr=err)

        #Array to manipulate the state of the simulator
        self.env_action = torch.zeros(2, dtype=torch.int, device='cpu')
        self.env_action[0] = 0  #1 = reset
        self.env_action[1] = 0  #1 = exit

        #Example of agent action
        self.agent_action = torch.zeros(1, dtype=torch.float, device='cpu')

        self.action_space = spaces.Discrete(2)
        self.observation_space = spaces.Box(self.low,
                                            self.high,
                                            dtype=np.float32)

        atexit.register(self.close)
コード例 #4
0
    def __init__(self, exec_path, env_path):
        self.handle = "environment"
        self.mem = _GodotEnv.SharedMemoryTensor(self.handle)
        self.sem_act = _GodotEnv.SharedMemorySemaphore("sem_action", 0)
        self.sem_obs = _GodotEnv.SharedMemorySemaphore("sem_observation", 0)

        #Important: if this process is called with subprocess.PIPE, the semaphores will be stuck in impossible combination
        with open("stdout.txt", "wb") as out, open("stderr.txt", "wb") as err:
            self.process = subprocess.Popen([
                exec_path, "--path",
                os.path.abspath(env_path), "--disable-render-loop", "--handle",
                self.handle
            ],
                                            stdout=out,
                                            stderr=err)
        time.sleep(0.01)
        #Array to manipulate the state of the simulator
        # self.env_action = torch.zeros(1, dtype=torch.int, device='cpu')
        # self.env_action[0] = 0	#1 = exit

        atexit.register(self.close)
コード例 #5
0
    def __init__(self,
                 exec_path,
                 pck_path=None,
                 render=False,
                 num_actions=2,
                 num_observations=21):
        self.handle = 'environment'
        self.mem = _GodotEnv.SharedMemoryTensor(self.handle)
        self.sem_act = _GodotEnv.SharedMemorySemaphore("sem_action", 0)
        self.sem_obs = _GodotEnv.SharedMemorySemaphore("sem_observation", 0)

        self.agent_action_tensor = self.mem.newFloatTensor(
            "agent_action", num_actions)
        self.env_action_tensor = self.mem.newIntTensor("env_action", 2)
        self.observation_tensor = self.mem.newFloatTensor(
            "observation", num_observations)
        self.reward_tensor = self.mem.newFloatTensor("reward", 1)
        self.done_tensor = self.mem.newIntTensor("done", 1)

        self.out = open("stdout.txt", 'wb')
        self.err = open("stderr.txt", 'wb')

        cmd = [exec_path]
        if not (pck_path is None):
            cmd += ['--path', os.path.abspath(pck_path)]
        if not render:
            cmd += ['--disable-render-loop']
        cmd += ['--handle', self.handle]
        self.process = subprocess.Popen(cmd, stdout=self.out, stderr=self.err)

        self.action_space = spaces.Box(low=-1,
                                       high=1.0,
                                       shape=(num_actions, ),
                                       dtype=np.float32)
        self.observation_space = spaces.Box(low=-1,
                                            high=1.0,
                                            shape=(num_observations, ),
                                            dtype=np.float32)

        atexit.register(self.close)
コード例 #6
0
 def setUp(self):
     self.mem = _GodotEnv.SharedMemoryTensor("environment")
     self.sem_act = _GodotEnv.SharedMemorySemaphore("sem_action", 0)
     self.sem_obs = _GodotEnv.SharedMemorySemaphore("sem_observation", 0)
コード例 #7
0
 def setUp(self):
     output = launch_process(["g++", "tensors.cpp", "-lpthread", "-lrt"])
     print(output)
     self.mem = _GodotEnv.SharedMemoryTensor("test_segment")