-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain.py
More file actions
51 lines (34 loc) · 1.24 KB
/
Copy pathtrain.py
File metadata and controls
51 lines (34 loc) · 1.24 KB
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
50
import warnings
warnings.filterwarnings("ignore",catefgory=UserWarning)
warnings.filterwarnings("ignore",category=UserWarning,module="stable_baselines")
import wandb
from stable_baselines import PPO2, ACKTR
from stable_baselines.common.vec_env import DummyVecEnv
from stable_baselines.common.callbacks import EvalCallback
from env imoprt mEnv
nQueues = 3
boost=0
agent = "PPO2"
#agent="ACKTR"
wandb.init(project='process-scheduling1', config={"nQueues": nQueues, "boost": boost, "agent": agent})
wandb.run.name = agent_name
wandb.config.update({"nQueues": nQueues, "boost": boost, "agent": agent})
env= mEnv(boost,nQueues,False)
env=DummyVecEnv([lambda: env])
hyperparams={'gamma':0.99,'n_steps':128,'learning_rate':0.00025}
model = PPO2('MlpPolicy',env,verbose=1,**hyperparams)
callback =EvalCallback(env,best_model_save_path='./logs/',
log_path='./logs/',
eval_freq=5000,
deterministic=True,
render=False)
obs = env.reset()
r=0
for _ in range(20000):
action,_state=model.predict(obs,deterministic=True)
obs,reward,done,info=env.step(action)
r+=reward
if _ % 100==0:
wandb.log({"reward":r})
model.save(f"{agent}_{_}")
wandb.finish()