forked from rohan-sawhney/multi-agent-rl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonitor.py
28 lines (21 loc) · 840 Bytes
/
monitor.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
import gym
class MyMonitor(gym.wrappers.Monitor):
def _after_step(self, observation, reward, done, info):
if not self.enabled:
return done
if done and self.env_semantics_autoreset:
# For envs with BlockingReset wrapping VNCEnv, this observation
# will be the first one of the new episode
self._reset_video_recorder()
self.episode_id += 1
self._flush()
# Semisupervised envs modify the rewards, but we want the original when
# scoring
if info.get('true_reward', None):
reward = info['true_reward']
# Record stats
self.stats_recorder.after_step(
observation, np.sum(reward), any(done), info)
# Record video
self.video_recorder.capture_frame()
return done