'Args:
name (str): the gym environment name.
dumpdir (str): the directory to dump recordings to.
viz (bool): whether to start visualization.
auto_restart (bool): whether to restart after episode ends.'

def __init__(self, name, dumpdir=None, viz=False, auto_restart=True):

    with _ENV_LOCK:
        self.gymenv = gym.make(name)
    if dumpdir:
        mkdir_p(dumpdir)
        self.gymenv = gym.wrappers.Monitor(self.gymenv, dumpdir)
    self.use_dir = dumpdir
    self.reset_stat()
    self.rwd_counter = StatCounter()
    self.restart_episode()
    self.auto_restart = auto_restart
    self.viz = viz
