env-ssl-wrapper 0.4.3__tar.gz → 0.4.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/PKG-INFO +3 -1
  2. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/README.md +2 -0
  3. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/action_chunk.py +6 -4
  4. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/auto_batched_wrapper.py +8 -12
  5. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/helpers.py +3 -0
  6. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/pyproject.toml +1 -1
  7. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/.gitignore +0 -0
  8. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/LICENSE +0 -0
  9. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/__init__.py +0 -0
  10. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/memory_trace.py +0 -0
  11. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/__init__.py +0 -0
  12. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/action_transform_wrapper.py +0 -0
  13. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/adapters.py +0 -0
  14. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/done_tracker_wrapper.py +0 -0
  15. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/episode_padding_wrapper.py +0 -0
  16. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/flatten_obs_wrapper.py +0 -0
  17. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/image_wrapper.py +0 -0
  18. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/mocks.py +0 -0
  19. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/spaces.py +0 -0
  20. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/standardize_env_wrapper.py +0 -0
  21. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/standardize_wrapper.py +0 -0
  22. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/tensor_wrapper.py +0 -0
  23. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/time_limit_wrapper.py +0 -0
  24. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/utils.py +0 -0
  25. {env_ssl_wrapper-0.4.3 → env_ssl_wrapper-0.4.5}/env_ssl_wrapper/standardize/vector.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: env-ssl-wrapper
3
- Version: 0.4.3
3
+ Version: 0.4.5
4
4
  Summary: One torch-native interface for any MDP environment
5
5
  Project-URL: Homepage, https://pypi.org/project/env-ssl-wrapper/
6
6
  Project-URL: Repository, https://codeberg.org/lucidrains/env-ssl-wrapper
@@ -167,6 +167,8 @@ Execution stops early the moment any env terminates or truncates mid-chunk — t
167
167
 
168
168
  Pass `gamma` (default `1.`) to discount intra-chunk rewards $r = \sum_{i=0}^{L-1} \gamma^i r_i$. The macro-transition discount factor to the next state is provided as `info['discount'] = gamma ** chunk_length`. `reward_mode` can also be `'mean'` or `'last'`.
169
169
 
170
+ Set `reward_mode = 'chunk'` to get the raw per-step rewards back as a reward chunk of shape `(num_envs, chunk_length)` (`(chunk_length,)` for a single env) instead of a reduced scalar — useful when a learner wants to do per-step credit assignment within the chunk. The chunk is truncated to the number of substeps actually executed (`info['chunk_length']`) and is undiscounted, so `gamma` only affects the aggregated modes.
171
+
170
172
  Can also be passed directly to `StandardizeEnvWrapper` or `compose_env`:
171
173
 
172
174
  ```python
@@ -104,6 +104,8 @@ Execution stops early the moment any env terminates or truncates mid-chunk — t
104
104
 
105
105
  Pass `gamma` (default `1.`) to discount intra-chunk rewards $r = \sum_{i=0}^{L-1} \gamma^i r_i$. The macro-transition discount factor to the next state is provided as `info['discount'] = gamma ** chunk_length`. `reward_mode` can also be `'mean'` or `'last'`.
106
106
 
107
+ Set `reward_mode = 'chunk'` to get the raw per-step rewards back as a reward chunk of shape `(num_envs, chunk_length)` (`(chunk_length,)` for a single env) instead of a reduced scalar — useful when a learner wants to do per-step credit assignment within the chunk. The chunk is truncated to the number of substeps actually executed (`info['chunk_length']`) and is undiscounted, so `gamma` only affects the aggregated modes.
108
+
107
109
  Can also be passed directly to `StandardizeEnvWrapper` or `compose_env`:
108
110
 
109
111
  ```python
@@ -7,7 +7,7 @@ from torch import is_tensor
7
7
 
8
8
  from .standardize.helpers import (
9
9
  EnvWrapper,
10
- exists,
10
+ copy_leaf,
11
11
  default,
12
12
  any_true,
13
13
  dones_of,
@@ -45,7 +45,7 @@ class ActionChunkWrapper(EnvWrapper):
45
45
  gamma = default(discount, gamma)
46
46
  assert chunk_len >= 1, f'chunk_len must be at least 1, got {chunk_len}'
47
47
  assert 0. <= gamma <= 1., f'gamma must be between 0 and 1, got {gamma}'
48
- assert reward_mode in ('sum', 'mean', 'last'), f'unknown reward_mode {reward_mode!r}'
48
+ assert reward_mode in ('sum', 'mean', 'last', 'chunk'), f'unknown reward_mode {reward_mode!r}'
49
49
 
50
50
  self.chunk_len = chunk_len
51
51
  self.gamma = float(gamma)
@@ -83,7 +83,7 @@ class ActionChunkWrapper(EnvWrapper):
83
83
 
84
84
  for action in chunk_steps(actions, chunk_axis):
85
85
  out = self.env.step(action)
86
- rewards.append(out[1])
86
+ rewards.append(copy_leaf(out[1]))
87
87
 
88
88
  if any_true(dones_of(out[2], out[3])):
89
89
  break
@@ -93,7 +93,9 @@ class ActionChunkWrapper(EnvWrapper):
93
93
  rewards = stack_steps(rewards)
94
94
  executed_len = rewards.shape[-1]
95
95
 
96
- if self.reward_mode == 'last':
96
+ if self.reward_mode == 'chunk':
97
+ reward = rewards
98
+ elif self.reward_mode == 'last':
97
99
  reward = rewards[..., -1]
98
100
  elif self.reward_mode == 'mean':
99
101
  reward = reduce(rewards, '... k -> ...', 'mean')
@@ -153,18 +153,14 @@ def is_numeric_container(x):
153
153
  def maybe_squeeze_dim(x, shape_tree = None, is_vector = False, prepend_batch = False):
154
154
  # reshape actions to match the env's space, falling back to heuristics
155
155
 
156
- if isinstance(shape_tree, (list, dict)):
157
- keyed = isinstance(shape_tree, dict)
158
-
159
- ok = x.keys() == shape_tree.keys() if keyed else isinstance(x, (list, tuple)) and len(x) == len(shape_tree)
160
- assert ok, f'action structure does not match its {"dict" if keyed else "tuple"} action space'
161
-
162
- children = list(x.values()) if keyed else list(x)
163
- subtrees = list(shape_tree.values()) if keyed else shape_tree
164
-
165
- leaves = [maybe_squeeze_dim(child, subtree, is_vector, prepend_batch) for child, subtree in zip(children, subtrees)]
166
-
167
- return dict(zip(x.keys(), leaves)) if keyed else rebuild_container(x, leaves)
156
+ if isinstance(shape_tree, dict):
157
+ assert isinstance(x, dict) and x.keys() == shape_tree.keys(), 'action structure does not match its dict action space'
158
+ return {key: maybe_squeeze_dim(child, shape_tree[key], is_vector, prepend_batch) for key, child in x.items()}
159
+
160
+ if isinstance(shape_tree, list):
161
+ assert isinstance(x, (list, tuple)) and len(x) == len(shape_tree), 'action structure does not match its tuple action space'
162
+ leaves = [maybe_squeeze_dim(child, subtree, is_vector, prepend_batch) for child, subtree in zip(x, shape_tree)]
163
+ return rebuild_container(x, leaves)
168
164
 
169
165
  # leaf-shaped tree — claims the whole input
170
166
 
@@ -84,6 +84,9 @@ def copy_leaf(x):
84
84
 
85
85
  return x
86
86
 
87
+ def copy_tree(tree):
88
+ return tree_map(copy_leaf, tree)
89
+
87
90
  def dones_of(terminated, truncated):
88
91
  if not isinstance(terminated, (dict, list, tuple)):
89
92
  return terminated | truncated
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "env-ssl-wrapper"
3
- version = "0.4.3"
3
+ version = "0.4.5"
4
4
  description = "One torch-native interface for any MDP environment"
5
5
  authors = [
6
6
  { name = "Phil Wang", email = "lucidrains@gmail.com" }
File without changes