Skip to content

Commit

Permalink
we can run lagrangian without risk experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
manila95 committed Oct 20, 2023
1 parent 9df7c5b commit 94b173e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cleanrl/ppo_lagrangian_continuous_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def train_risk(args, model, data, criterion, opt, device):
next_done = torch.zeros(args.num_envs).to(device)
num_updates = args.total_timesteps // args.batch_size
ep_cost = np.zeros(args.num_envs)
total_cost = ep_cost
for update in range(1, num_updates + 1):
# Annealing the rate if instructed to do so.
if args.anneal_lr:
Expand Down Expand Up @@ -561,12 +562,13 @@ def train_risk(args, model, data, criterion, opt, device):
#if "episode" in item.keys():
count += 1
print(f"global_step={global_step}, episodic_return={info['episode']['r']}, episodic_cost={ep_cost}")

total_cost += ep_cost
reward_pool.append(info['episode']['r'])
writer.add_scalar("costs/episodic_cost", ep_cost, global_step)
ep_cost = 0
if count == 30:
writer.add_scalar("charts/episodic_return", np.mean(reward_pool), global_step)
writer.add_scalar("costs/Cummulative Cost", total_cost, global_step)
count = 0
# writer.add_scalar("charts/episodic_length", item["episode"]["l"], global_step)
f_ep_len.append(f_ep_len[-1] + int(info["episode"]["l"]))
Expand Down

0 comments on commit 94b173e

Please sign in to comment.