MCPcopy Create free account
hub / github.com/BIT-MCS/DRL-eFresh / train

Function train

train_agent.py:13–314  ·  view source on GitHub ↗
(worker_id, traffic_light, counter, shared_model, shared_grad_buffers, local_time, son_process_counter,
          device)

Source from the content-addressed store, hash-verified

11
12
13def train(worker_id, traffic_light, counter, shared_model, shared_grad_buffers, local_time, son_process_counter,
14 device):
15 os.environ['CUDA_VISIBLE_DEVICES'] = str(params.cuda_device)
16
17 util = Util(device)
18 torch.manual_seed(params.seed + worker_id)
19 torch.set_num_threads(4)
20 # ----------------make environment----------------------
21 env = Make_Env(device, params.max_time_steps, local_time, worker_id)
22 # -----------------load parameters----------------------
23 obs_shape = env.observ_shape
24 uav_num = params.uav_num
25 clip = params.clip
26 use_gae = params.use_gae
27 ent_coeff = params.ent_coeff
28 value_coeff = params.value_coeff
29 clip_coeff = params.clip_coeff
30 gamma = params.gamma
31 gae_lambda = params.gae_lambda
32 use_adv_norm = params.use_adv_norm
33 # --------------create name---------------------------
34 method_name = 'FixTauPpo'
35 if use_adv_norm:
36 method_name += 'AdvNorm'
37 # if worker_id == 0:
38 # # visdom cannot work in ssh!!!
39 # vis = visdom.Visdom(env=method_name)
40
41 # -----------------create storage---------------------
42 rollout = RolloutStorage(params.max_time_steps, params.mini_batch_num, obs_shape, uav_num)
43 rollout.to(device)
44
45 # ---------------create local model---------------------
46 local_ppo_model = Model(obs_shape, uav_num, device)
47 local_ppo_model.to(device)
48
49 episode_length = 0
50 interact_time = 0
51 # --------------define file writer-----------------------
52 root_path = os.path.join(params.root_path, str(local_time))
53
54 if worker_id ==0:
55 file_root_path = os.path.join(params.root_path, str(local_time) + '/' + str(worker_id) + '/file')
56 os.makedirs(file_root_path)
57
58 # loss_file = open(os.path.join(file_root_path, 'loss.csv'), 'w', newline='')
59 # loss_writer = csv.writer(loss_file)
60 # reward_file = open(os.path.join(file_root_path, 'reward.csv'), 'w', newline='')
61 # reward_writer = csv.writer(reward_file)
62 # action_file = open(os.path.join(file_root_path, 'action.csv'), 'w', newline='')
63 # action_writer = csv.writer(action_file)
64
65 av_reward_list = []
66 av_value_loss_list = []
67 av_policy_loss_list = []
68 av_ent_loss_list = []
69
70 # load local model parameters

Callers

nothing calls this directly

Calls 15

toMethod · 0.95
resetMethod · 0.95
after_updateMethod · 0.95
actMethod · 0.95
stepMethod · 0.95
to_numpyMethod · 0.95
insertMethod · 0.95
get_valueMethod · 0.95
compute_returnsMethod · 0.95

Tested by

no test coverage detected