libinephany 0.15.3__tar.gz → 0.16.0__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 (65) hide show
  1. libinephany-0.16.0/CODE_VERSION.cfg +1 -0
  2. {libinephany-0.15.3/libinephany.egg-info → libinephany-0.16.0}/PKG-INFO +1 -1
  3. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/observation_utils.py +16 -2
  4. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/observer_pipeline.py +20 -9
  5. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/observers/observer_containers.py +13 -4
  6. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/pipeline_coordinator.py +9 -1
  7. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/schemas/observation_models.py +5 -1
  8. {libinephany-0.15.3 → libinephany-0.16.0/libinephany.egg-info}/PKG-INFO +1 -1
  9. libinephany-0.15.3/CODE_VERSION.cfg +0 -1
  10. {libinephany-0.15.3 → libinephany-0.16.0}/LICENSE +0 -0
  11. {libinephany-0.15.3 → libinephany-0.16.0}/MANIFEST.in +0 -0
  12. {libinephany-0.15.3 → libinephany-0.16.0}/README.md +0 -0
  13. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/__init__.py +0 -0
  14. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/aws/__init__.py +0 -0
  15. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/aws/s3_functions.py +0 -0
  16. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/__init__.py +0 -0
  17. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/observers/__init__.py +0 -0
  18. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/observers/base_observers.py +0 -0
  19. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/observers/global_observers.py +0 -0
  20. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/observers/local_observers.py +0 -0
  21. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/post_processors/__init__.py +0 -0
  22. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/post_processors/postprocessors.py +0 -0
  23. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/statistic_manager.py +0 -0
  24. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/observations/statistic_trackers.py +0 -0
  25. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/__init__.py +0 -0
  26. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/configs/__init__.py +0 -0
  27. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/configs/hyperparameter_configs.py +0 -0
  28. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/configs/observer_config.py +0 -0
  29. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/configs/outer_model_config.py +0 -0
  30. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/schemas/__init__.py +0 -0
  31. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/schemas/agent_info.py +0 -0
  32. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/schemas/inner_task_profile.py +0 -0
  33. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/schemas/request_schemas.py +0 -0
  34. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/schemas/response_schemas.py +0 -0
  35. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/schemas/tensor_statistics.py +0 -0
  36. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/states/__init__.py +0 -0
  37. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/pydantic_models/states/hyperparameter_states.py +0 -0
  38. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/__init__.py +0 -0
  39. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/agent_utils.py +0 -0
  40. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/asyncio_worker.py +0 -0
  41. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/backend_statuses.py +0 -0
  42. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/constants.py +0 -0
  43. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/directory_utils.py +0 -0
  44. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/dropout_utils.py +0 -0
  45. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/enums.py +0 -0
  46. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/error_severities.py +0 -0
  47. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/exceptions.py +0 -0
  48. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/import_utils.py +0 -0
  49. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/optim_utils.py +0 -0
  50. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/random_seeds.py +0 -0
  51. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/samplers.py +0 -0
  52. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/standardizers.py +0 -0
  53. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/torch_distributed_utils.py +0 -0
  54. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/torch_utils.py +0 -0
  55. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/transforms.py +0 -0
  56. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/utils/typing.py +0 -0
  57. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/web_apps/__init__.py +0 -0
  58. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/web_apps/error_logger.py +0 -0
  59. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany/web_apps/web_app_utils.py +0 -0
  60. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany.egg-info/SOURCES.txt +0 -0
  61. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany.egg-info/dependency_links.txt +0 -0
  62. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany.egg-info/requires.txt +0 -0
  63. {libinephany-0.15.3 → libinephany-0.16.0}/libinephany.egg-info/top_level.txt +0 -0
  64. {libinephany-0.15.3 → libinephany-0.16.0}/pyproject.toml +0 -0
  65. {libinephany-0.15.3 → libinephany-0.16.0}/setup.cfg +0 -0
@@ -0,0 +1 @@
1
+ 0.16.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libinephany
3
- Version: 0.15.3
3
+ Version: 0.16.0
4
4
  Summary: Inephany library containing code commonly used by multiple subpackages.
5
5
  Author-email: Inephany <info@inephany.com>
6
6
  License: Apache 2.0
@@ -167,6 +167,20 @@ def create_one_hot_depth_encoding(agent_controlled_modules: list[str], parameter
167
167
  return create_one_hot_observation(vector_length=3, one_hot_index=one_hot_index)
168
168
 
169
169
 
170
+ def check_if_tensor_is_xpu(tensor: torch.Tensor | None) -> bool:
171
+ """
172
+ :param tensor: Tensor to check whether it is an XPU tensor.
173
+ :return: Whether the tensor is an XPU tensor.
174
+ """
175
+
176
+ try:
177
+ xpu_available = torch.xpu.is_available()
178
+ return xpu_available and tensor.is_xpu
179
+
180
+ except AttributeError:
181
+ return False
182
+
183
+
170
184
  def tensor_on_local_rank(tensor: torch.Tensor | None) -> bool:
171
185
  """
172
186
  :param tensor: Tensor to check whether it is owned by the local rank, partially or entirely.
@@ -176,10 +190,10 @@ def tensor_on_local_rank(tensor: torch.Tensor | None) -> bool:
176
190
  valid_tensor = tensor is not None and tensor.numel() > 0
177
191
  device_index = tensor.device.index if valid_tensor else None
178
192
 
179
- xpu_available = torch.xpu.is_available()
193
+ is_xpu = check_if_tensor_is_xpu(tensor)
180
194
  cuda_available = torch.cuda.is_available()
181
195
 
182
- if valid_tensor and xpu_available and tensor.is_xpu:
196
+ if valid_tensor and is_xpu:
183
197
  current_device = torch.xpu.current_device()
184
198
  return device_index == current_device
185
199
 
@@ -4,6 +4,7 @@
4
4
  #
5
5
  # ======================================================================================================================
6
6
 
7
+ import copy
7
8
  from typing import Any
8
9
 
9
10
  import gymnasium as gym
@@ -216,33 +217,42 @@ class ObserverPipeline:
216
217
  hyperparameter_states: HyperparameterStates,
217
218
  tracked_statistics: dict[str, dict[str, float | TensorStatistics]],
218
219
  actions_taken: dict[str, float | int | None],
219
- ) -> tuple[dict[str, list[float | int]], bool]:
220
+ return_dict: bool = False,
221
+ ) -> tuple[dict[str, list[float | int]], bool, dict[str, dict[str, list[float | int]]] | None]:
220
222
  """
221
223
  :param observation_inputs: Observation input metrics not calculated with statistic trackers.
222
224
  :param hyperparameter_states: HyperparameterStates that manages the hyperparameters.
223
225
  :param tracked_statistics: Dictionary mapping statistic tracker class names to dictionaries mapping module
224
226
  names to floats or TensorStatistic models.
225
227
  :param actions_taken: Dictionary mapping agent IDs to actions taken by that agent.
226
- :return: Tuple of a dictionary mapping agent ID to that agent's completed observation vector and a boolean
227
- indicating whether an observation clip occurred.
228
+ :param return_dict: Whether to return a dictionary of observations as well as the normal vector.
229
+ :return: Tuple of a dictionary mapping agent ID to that agent's completed observation vector, a boolean
230
+ indicating whether an observation clip occurred and a dictionary of observations.
228
231
  """
229
232
 
230
- global_obs = self.global_observers.observe(
233
+ global_obs, global_obs_dict = self.global_observers.observe(
231
234
  observation_inputs=observation_inputs,
232
235
  hyperparameter_states=hyperparameter_states,
233
236
  tracked_statistics=tracked_statistics,
234
237
  action_taken=None,
238
+ return_dict=return_dict,
235
239
  )
236
240
 
237
- local_obs = {
238
- agent_id: agent_observers.observe(
241
+ local_obs: dict[str, list[float | int]] = {}
242
+ obs_as_dict: dict[str, dict[str, list[float | int]]] = {}
243
+
244
+ for agent_id, agent_observers in self.local_observers.items():
245
+ local_obs[agent_id], local_obs_dict = agent_observers.observe(
239
246
  observation_inputs=observation_inputs,
240
247
  hyperparameter_states=hyperparameter_states,
241
248
  tracked_statistics=tracked_statistics,
242
249
  action_taken=actions_taken[agent_id] if agent_id in actions_taken else None,
250
+ return_dict=return_dict,
243
251
  )
244
- for agent_id, agent_observers in self.local_observers.items()
245
- }
252
+
253
+ if return_dict:
254
+ obs_as_dict[agent_id] = copy.deepcopy(global_obs_dict)
255
+ obs_as_dict[agent_id].update(local_obs_dict)
246
256
 
247
257
  for post_processor in self.post_processors:
248
258
  global_obs, local_obs = post_processor.postprocess(
@@ -252,8 +262,9 @@ class ObserverPipeline:
252
262
  global_obs, local_obs, obs_clipped = self.clip_observations(
253
263
  globals_to_clip=global_obs, locals_to_clip=local_obs
254
264
  )
265
+ merged_obs = self.merge_globals_to_locals(global_obs=global_obs, local_obs=local_obs)
255
266
 
256
- return self.merge_globals_to_locals(global_obs=global_obs, local_obs=local_obs), obs_clipped
267
+ return merged_obs, obs_clipped, obs_as_dict if return_dict else None
257
268
 
258
269
  def inform(self) -> tuple[ObservationInformation, dict[str, ObservationInformation]]:
259
270
  """
@@ -132,27 +132,36 @@ class ObserverContainer(ABC):
132
132
  hyperparameter_states: HyperparameterStates,
133
133
  tracked_statistics: dict[str, dict[str, float | TensorStatistics]],
134
134
  action_taken: float | int | None,
135
- ) -> list[float | int]:
135
+ return_dict: bool = False,
136
+ ) -> tuple[list[float | int], dict[str, list[float | int]] | None]:
136
137
  """
137
138
  :param observation_inputs: Observation input metrics not calculated with statistic trackers.
138
139
  :param hyperparameter_states: HyperparameterStates that manages the hyperparameters.
139
140
  :param tracked_statistics: Dictionary mapping statistic tracker class names to dictionaries mapping module
140
141
  names to floats or TensorStatistic models.
141
142
  :param action_taken: Action taken by the agent this class instance is assigned to.
142
- :return: List of floats or integers to add to the agent's observation vector.
143
+ :param return_dict: Whether to return a dictionary of observations as well as the normal vector.
144
+ :return: Tuple of a list of floats or integers to add to the agent's observation vector and a dictionary of
145
+ observations as well as the normal vector.
143
146
  """
144
147
 
145
148
  observations = []
149
+ observations_dict = {}
146
150
 
147
151
  for observer in self._observers:
148
- observations += observer.observe(
152
+ observer_obs = observer.observe(
149
153
  observation_inputs=observation_inputs,
150
154
  hyperparameter_states=hyperparameter_states,
151
155
  tracked_statistics=tracked_statistics,
152
156
  action_taken=action_taken,
153
157
  )
154
158
 
155
- return observations
159
+ if return_dict:
160
+ observations_dict[observer.__class__.__name__] = observer_obs
161
+
162
+ observations += observer_obs
163
+
164
+ return observations, observations_dict if return_dict else None
156
165
 
157
166
  @final
158
167
  def inform(self) -> ObservationInformation:
@@ -120,6 +120,7 @@ class ObserverPipelineCoordinator:
120
120
  hyperparameter_states: HyperparameterStates,
121
121
  tracked_statistics: dict[str, dict[str, float | TensorStatistics]],
122
122
  actions_taken: dict[str, float | int | None],
123
+ return_dict: bool = False,
123
124
  ) -> Observations:
124
125
  """
125
126
  :param observation_inputs: Observation input metrics not calculated with statistic trackers.
@@ -127,18 +128,21 @@ class ObserverPipelineCoordinator:
127
128
  :param tracked_statistics: Dictionary mapping statistic tracker class names to dictionaries mapping module
128
129
  names to floats or TensorStatistic models.
129
130
  :param actions_taken: Dictionary mapping agent IDs to actions taken by that agent.
131
+ :param return_dict: Whether to return a dictionary of observations as well as the normal vector.
130
132
  :return: Observations pydantic model.
131
133
  """
132
134
 
133
135
  clipped_observations = False
134
136
  observations = {}
137
+ observations_as_dict: dict[str, dict[str, list[float | int]]] = {}
135
138
 
136
139
  for pipeline in self.pipelines:
137
- pipeline_observations, pipeline_clipped_observations = pipeline.observe(
140
+ pipeline_observations, pipeline_clipped_observations, pipeline_observations_dict = pipeline.observe(
138
141
  observation_inputs=observation_inputs,
139
142
  hyperparameter_states=hyperparameter_states,
140
143
  tracked_statistics=tracked_statistics,
141
144
  actions_taken=actions_taken,
145
+ return_dict=return_dict,
142
146
  )
143
147
 
144
148
  clipped_observations = clipped_observations if clipped_observations else pipeline_clipped_observations
@@ -152,10 +156,14 @@ class ObserverPipelineCoordinator:
152
156
 
153
157
  observations[agent_id] = agent_obs
154
158
 
159
+ if return_dict:
160
+ observations_as_dict[agent_id] = pipeline_observations_dict[agent_id]
161
+
155
162
  return Observations(
156
163
  observation_inputs=observation_inputs,
157
164
  agent_observations=observations,
158
165
  hit_invalid_value=clipped_observations,
166
+ observations_as_dict=observations_as_dict if return_dict else None,
159
167
  )
160
168
 
161
169
  def inform(self) -> AgentInfo:
@@ -51,9 +51,13 @@ class Observations(BaseModel):
51
51
  hit_invalid_value: bool
52
52
 
53
53
  agent_observations: dict[str, list[float | int]]
54
+ observations_as_dict: dict[str, dict[str, list[float | int]]] | None = None
54
55
 
55
56
  def observations_as_arrays(self, dtype: DTypeLike = np.float32) -> dict[str, np.ndarray]:
56
- """"""
57
+ """
58
+ :param dtype: Data type to cast the observations to.
59
+ :return: Dictionary mapping agent IDs to their observation vectors as numpy arrays.
60
+ """
57
61
 
58
62
  return {
59
63
  agent_id: np.array(observation_vector, dtype=dtype)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libinephany
3
- Version: 0.15.3
3
+ Version: 0.16.0
4
4
  Summary: Inephany library containing code commonly used by multiple subpackages.
5
5
  Author-email: Inephany <info@inephany.com>
6
6
  License: Apache 2.0
@@ -1 +0,0 @@
1
- 0.15.3
File without changes
File without changes
File without changes
File without changes