Skip to content

Commit 39ab731

Browse files
committed
changed logs
1 parent 345ad7e commit 39ab731

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

Algorithms/ddpg/ddpg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def update(self, experiences):
151151

152152
# MSE loss
153153
loss_q = ((Q_values-Qprime)**2).mean()
154-
loss_info = dict(Qvals=Q_values.detach().cpu().numpy())
154+
loss_info = dict(Qvals=Q_values.detach().cpu().numpy().tolist())
155155

156156
loss_q.backward()
157157
self.q_optimizer.step()

Algorithms/td3/td3.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ def update(self, experiences, update_policy=False):
171171

172172
# MSE loss
173173
loss_q = ((q1-Qprime)**2).mean() + ((q2-Qprime)**2).mean()
174-
loss_info = dict(Q1vals=q1.detach().cpu().numpy(),
175-
Q2Vals=q2.detach().cpu().numpy())
174+
loss_info = dict(Q1vals=q1.detach().cpu().numpy().tolist(),
175+
Q2Vals=q2.detach().cpu().numpy().tolist())
176176

177177
loss_q.backward()
178178
self.q_optimizer.step()

Logger/logger.py

+5-14
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,18 @@ def dump(self):
5050
Write all of the diagnostics from the current iteration.
5151
Writes to the output file.
5252
"""
53-
# print(self.logger_dict)
54-
# with open(self.output_filepath, 'wb') as f:
55-
# pickle.dump(self.logger_dict, f)
56-
57-
if self.init:
58-
assert len(self.logger_dict) > 0, "no variables stored inside dictionary to dump!"
59-
self.logger_list.append(self.logger_dict)
60-
self.init = False
61-
else:
62-
self.logger_list[-1] = self.logger_dict
63-
53+
assert len(self.logger_dict) > 0, "no variables stored inside dictionary to dump!"
54+
6455
with open(self.output_filepath, 'w') as f:
65-
f.write(json.dumps(self.logger_list, indent=4))
56+
f.write(json.dumps(self.logger_list + [self.logger_dict], indent=4))
6657

6758
def reset(self):
6859
'''
6960
Reset the log dict for a new experiment. Used for training the same algorithm multiple times
7061
'''
71-
self.logger_dict = {}
7262
self.logger_list.append(self.logger_dict)
73-
63+
self.logger_dict = {}
64+
7465
with open(self.output_filepath, 'w') as f:
7566
f.write(json.dumps(self.logger_list, indent=4))
7667

0 commit comments

Comments
 (0)