forked from igilitschenski/multi_car_racing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain_ppo_test.py
49 lines (42 loc) · 1.42 KB
/
train_ppo_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import ray
import gymnasium as gym
# import gym_multi_car_racing
import numpy as np
from gym import spaces
from ray.rllib.algorithms import ppo
class DummyEnv(gym.Env):
def __init__(self, env_config):
# pick actual env based on worker and env indexes
self.env = gym.make("CartPole-v1")
self.action_space = self.env.action_space
self.observation_space = self.env.observation_space
def reset(self, seed, options):
return self.env.reset(seed, options)
def step(self, action):
return self.env.step(action)
# class DummyEnv(gym.Env):
# def __init__(self, env_config):
# super(DummyEnv, self).__init__()
# # Define a simple observation space and action space
# self.observation_space = spaces.Box(low=0, high=1, shape=(4,), dtype=np.float32)
# self.action_space = spaces.Discrete(2)
# def reset(self):
# # Return an initial random observation
# return np.random.rand(4)
# def step(self, action):
# # Return a random observation, zero reward, not done, and empty info
# obs = np.random.rand(4)
# reward = 0
# done = False
# info = {}
# return obs, reward, done, info
print(type(DummyEnv))
ray.init()
algo = ppo.PPO(env=DummyEnv, config={
"env_config": {}, # config to pass to env class
})
for i in range(len(2)):
algo.train()
print("hi")
print("finished")
ray.shutdown()