Python gym.core.Wrapper.__init__() Examples
The following are 30
code examples of gym.core.Wrapper.__init__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gym.core.Wrapper
, or try the search function
.
Example #1
Source File: monitor.py From baselines with MIT License | 6 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename: self.results_writer = ResultsWriter(filename, header={"t_start": time.time(), 'env_id' : env.spec and env.spec.id}, extra_keys=reset_keywords + info_keywords ) else: self.results_writer = None self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #2
Source File: monitor.py From learning2run with MIT License | 6 votes |
def __init__(self, env, filename, allow_early_resets=False): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.logger = JSONLogger(self.f) self.logger.writekvs({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'}) self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_metadata = {} # extra info that gets injected into each log entry # Useful for metalearning where we're modifying the environment externally # But want our logs to know about these modifications
Example #3
Source File: monitor.py From deeprl-baselines with MIT License | 6 votes |
def __init__(self, env): """Adds two qunatities to info returned by every step: num_steps: int Number of steps takes so far rewards: [float] All the cumulative rewards for the episodes completed so far. """ super().__init__(env) # current episode state self._current_reward = None self._num_steps = None # temporary monitor state that we do not save self._time_offset = None self._total_steps = None # monitor state self._episode_rewards = [] self._episode_lengths = [] self._episode_end_times = []
Example #4
Source File: monitor.py From multiagent-gail with MIT License | 6 votes |
def __init__(self, env, filename, allow_early_resets=False): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.logger = JSONLogger(self.f) self.logger.writekvs({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'}) self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_metadata = {} # extra info that gets injected into each log entry # Useful for metalearning where we're modifying the environment externally # But want our logs to know about these modifications
Example #5
Source File: monitor.py From ICML2019-TREX with MIT License | 6 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() self.results_writer = ResultsWriter( filename, header={"t_start": time.time(), 'env_id' : env.spec and env.spec.id}, extra_keys=reset_keywords + info_keywords ) self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #6
Source File: monitor.py From ICML2019-TREX with MIT License | 6 votes |
def __init__(self, filename=None, header='', extra_keys=()): self.extra_keys = extra_keys if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") if isinstance(header, dict): header = '# {} \n'.format(json.dumps(header)) self.f.write(header) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+tuple(extra_keys)) self.logger.writeheader() self.f.flush()
Example #7
Source File: monitor.py From ICML2019-TREX with MIT License | 6 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() self.results_writer = ResultsWriter( filename, header={"t_start": time.time(), 'env_id' : env.spec and env.spec.id}, extra_keys=reset_keywords + info_keywords ) self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #8
Source File: monitor.py From ICML2019-TREX with MIT License | 6 votes |
def __init__(self, filename=None, header='', extra_keys=()): self.extra_keys = extra_keys if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") if isinstance(header, dict): header = '# {} \n'.format(json.dumps(header)) self.f.write(header) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+tuple(extra_keys)) self.logger.writeheader() self.f.flush()
Example #9
Source File: monitor.py From gail-tf with MIT License | 6 votes |
def __init__(self, env, filename, allow_early_resets=False): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.logger = JSONLogger(self.f) self.logger.writekvs({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'}) self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_metadata = {} # extra info that gets injected into each log entry # Useful for metalearning where we're modifying the environment externally # But want our logs to know about these modifications
Example #10
Source File: monitor.py From rl-teacher with MIT License | 6 votes |
def __init__(self, env, filename, allow_early_resets=False): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.logger = JSONLogger(self.f) self.logger.writekvs({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'}) self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_metadata = {} # extra info that gets injected into each log entry # Useful for metalearning where we're modifying the environment externally # But want our logs to know about these modifications
Example #11
Source File: monitor.py From rl-attack with MIT License | 6 votes |
def __init__(self, env, filename, allow_early_resets=False): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.logger = JSONLogger(self.f) self.logger.writekvs({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'}) self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_metadata = {} # extra info that gets injected into each log entry # Useful for metalearning where we're modifying the environment externally # But want our logs to know about these modifications
Example #12
Source File: monitor.py From treeqn with MIT License | 5 votes |
def __init__(self, file, override=False, filename=None): self.file = file self.override = override self.filename = filename
Example #13
Source File: monitor.py From BackpropThroughTheVoidRL with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords) self.logger.writeheader() self.reset_keywords = reset_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #14
Source File: monitor.py From baselines with MIT License | 5 votes |
def __init__(self, filename, header='', extra_keys=()): self.extra_keys = extra_keys assert filename is not None if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") if isinstance(header, dict): header = '# {} \n'.format(json.dumps(header)) self.f.write(header) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+tuple(extra_keys)) self.logger.writeheader() self.f.flush()
Example #15
Source File: bench_monitor.py From rl-generalization with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, 'env_id' : env.spec and env.spec.id})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords+info_keywords) self.logger.writeheader() self.f.flush() self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #16
Source File: env_wrapper.py From reinforce_py with MIT License | 5 votes |
def __init__(self, env_fns): self.envs = [fn() for fn in env_fns] env = self.envs[0] self.action_space = env.action_space self.observation_space = env.observation_space self.ts = np.zeros(len(self.envs), dtype='int')
Example #17
Source File: env_wrapper.py From reinforce_py with MIT License | 5 votes |
def __init__(self, venv, ob=True, ret=True, clipob=10., cliprew=10., gamma=0.99, epsilon=1e-8): self.venv = venv self._ob_space = venv.observation_space self._ac_space = venv.action_space self.ob_rms = RunningMeanStd(shape=self._ob_space.shape) if ob else None self.ret_rms = RunningMeanStd(shape=()) if ret else None self.clipob = clipob self.cliprew = cliprew self.ret = np.zeros(self.num_envs) self.gamma = gamma self.epsilon = epsilon
Example #18
Source File: env_wrapper.py From reinforce_py with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords) self.logger.writeheader() self.reset_keywords = reset_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #19
Source File: monitor.py From midlevel-reps with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords) self.logger.writeheader() self.reset_keywords = reset_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset() ## Cambria specific self.sensor_space = env.sensor_space
Example #20
Source File: monitor.py From rl-testbed-for-energyplus with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() print('Monitor: filename={}'.format(filename)) if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, 'env_id' : env.spec and env.spec.id})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords) self.logger.writeheader() self.f.flush() self.reset_keywords = reset_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #21
Source File: monitor.py From deeprl-baselines with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords) self.logger.writeheader() self.reset_keywords = reset_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #22
Source File: monitor.py From vel with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, 'env_id' : env.spec and env.spec.id})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords+info_keywords) self.logger.writeheader() self.f.flush() self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #23
Source File: monitor.py From lirpg with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, 'env_id' : env.spec and env.spec.id})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords+info_keywords) self.logger.writeheader() self.f.flush() self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #24
Source File: monitor.py From treeqn with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, cpu=None): Wrapper.__init__(self, env=env) self.tstart = time.time() self.filename = filename if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): filename_local = filename + "." + Monitor.EXT_LOCAL filename = filename + "." + Monitor.EXT else: filename_local = filename[:-13] + "." + Monitor.EXT_LOCAL self.f = open(filename, "wt") self.f_local = open(filename_local, "wt") self.logger = JSONLogger(self.f, filename=filename) self.logger_local = JSONLogger(self.f_local, override=True) self.logger.writekvs({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'}) self.logger_local.writekvs({"t_start": self.tstart, "gym_version": gym.__version__, "env_id": env.spec.id if env.spec else 'Unknown'}) self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.total_steps = 0 self.current_metadata = {} # extra info that gets injected into each log entry # Useful for metalearning where we're modifying the environment externally # But want our logs to know about these modifications self.cpu = cpu
Example #25
Source File: monitor.py From multiagent-gail with MIT License | 5 votes |
def __init__(self, file): self.file = file
Example #26
Source File: monitor.py From rl-teacher with MIT License | 5 votes |
def __init__(self, file): self.file = file
Example #27
Source File: monitor.py From self-imitation-learning with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, 'env_id' : env.spec and env.spec.id})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords+info_keywords) self.logger.writeheader() self.f.flush() self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #28
Source File: monitor.py From rl-attack with MIT License | 5 votes |
def __init__(self, file): self.file = file
Example #29
Source File: monitor.py From sonic_contest with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, 'env_id' : env.spec and env.spec.id})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords+info_keywords) self.logger.writeheader() self.f.flush() self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()
Example #30
Source File: monitor.py From pytorch-pommerman-rl with MIT License | 5 votes |
def __init__(self, env, filename, allow_early_resets=False, reset_keywords=(), info_keywords=()): Wrapper.__init__(self, env=env) self.tstart = time.time() if filename is None: self.f = None self.logger = None else: if not filename.endswith(Monitor.EXT): if osp.isdir(filename): filename = osp.join(filename, Monitor.EXT) else: filename = filename + "." + Monitor.EXT self.f = open(filename, "wt") self.f.write('#%s\n'%json.dumps({"t_start": self.tstart, 'env_id' : env.spec and env.spec.id})) self.logger = csv.DictWriter(self.f, fieldnames=('r', 'l', 't')+reset_keywords+info_keywords) self.logger.writeheader() self.f.flush() self.reset_keywords = reset_keywords self.info_keywords = info_keywords self.allow_early_resets = allow_early_resets self.rewards = None self.needs_reset = True self.episode_rewards = [] self.episode_lengths = [] self.episode_times = [] self.total_steps = 0 self.current_reset_info = {} # extra info about the current episode, that was passed in during reset()