humalab 0.0.5__py3-none-any.whl → 0.0.7__py3-none-any.whl

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.

Potentially problematic release.


This version of humalab might be problematic. Click here for more details.

Files changed (42) hide show
  1. humalab/__init__.py +25 -0
  2. humalab/assets/__init__.py +8 -2
  3. humalab/assets/files/resource_file.py +96 -6
  4. humalab/assets/files/urdf_file.py +49 -11
  5. humalab/assets/resource_operator.py +139 -0
  6. humalab/constants.py +48 -5
  7. humalab/dists/__init__.py +7 -0
  8. humalab/dists/bernoulli.py +26 -1
  9. humalab/dists/categorical.py +25 -0
  10. humalab/dists/discrete.py +27 -2
  11. humalab/dists/distribution.py +11 -0
  12. humalab/dists/gaussian.py +27 -2
  13. humalab/dists/log_uniform.py +29 -3
  14. humalab/dists/truncated_gaussian.py +33 -4
  15. humalab/dists/uniform.py +24 -0
  16. humalab/episode.py +291 -11
  17. humalab/humalab.py +93 -38
  18. humalab/humalab_api_client.py +297 -95
  19. humalab/humalab_config.py +49 -0
  20. humalab/humalab_test.py +46 -17
  21. humalab/metrics/__init__.py +11 -5
  22. humalab/metrics/code.py +59 -0
  23. humalab/metrics/metric.py +69 -102
  24. humalab/metrics/scenario_stats.py +163 -0
  25. humalab/metrics/summary.py +45 -24
  26. humalab/run.py +224 -101
  27. humalab/scenarios/__init__.py +11 -0
  28. humalab/{scenario.py → scenarios/scenario.py} +130 -136
  29. humalab/scenarios/scenario_operator.py +114 -0
  30. humalab/{scenario_test.py → scenarios/scenario_test.py} +150 -269
  31. humalab/utils.py +37 -0
  32. {humalab-0.0.5.dist-info → humalab-0.0.7.dist-info}/METADATA +1 -1
  33. humalab-0.0.7.dist-info/RECORD +39 -0
  34. humalab/assets/resource_manager.py +0 -58
  35. humalab/evaluators/__init__.py +0 -16
  36. humalab/humalab_main.py +0 -119
  37. humalab/metrics/dist_metric.py +0 -22
  38. humalab-0.0.5.dist-info/RECORD +0 -37
  39. {humalab-0.0.5.dist-info → humalab-0.0.7.dist-info}/WHEEL +0 -0
  40. {humalab-0.0.5.dist-info → humalab-0.0.7.dist-info}/entry_points.txt +0 -0
  41. {humalab-0.0.5.dist-info → humalab-0.0.7.dist-info}/licenses/LICENSE +0 -0
  42. {humalab-0.0.5.dist-info → humalab-0.0.7.dist-info}/top_level.txt +0 -0
humalab/humalab.py CHANGED
@@ -1,25 +1,39 @@
1
1
  from contextlib import contextmanager
2
+ import sys
3
+ import traceback
2
4
 
3
5
  from omegaconf import OmegaConf
4
6
 
7
+ from humalab.constants import DEFAULT_PROJECT
5
8
  from humalab.run import Run
6
9
  from humalab.humalab_config import HumalabConfig
7
- from humalab.humalab_api_client import HumaLabApiClient
8
- from humalab.constants import EpisodeStatus
10
+ from humalab.humalab_api_client import HumaLabApiClient, RunStatus, EpisodeStatus
9
11
  import requests
10
12
 
11
13
  import uuid
12
14
 
13
15
  from collections.abc import Generator
14
16
 
15
- from humalab.scenario import Scenario
17
+ from humalab.scenarios.scenario import Scenario
16
18
 
17
19
  _cur_run: Run | None = None
18
20
 
19
21
  def _pull_scenario(client: HumaLabApiClient,
20
- project_name: str,
21
- scenario: str | list | dict | None = None,
22
- scenario_id: str | None = None,) -> str | list | dict | None:
22
+ project: str,
23
+ seed: int | None = None,
24
+ scenario: str | list | dict | Scenario | None = None,
25
+ scenario_id: str | None = None,) -> Scenario:
26
+ """Pull a scenario from the server if scenario_id is provided.
27
+
28
+ Args:
29
+ client (HumaLabApiClient): API client instance.
30
+ project (str): Project name.
31
+ scenario (str | list | dict | None): Local scenario configuration.
32
+ scenario_id (str | None): ID of scenario to pull from server.
33
+
34
+ Returns:
35
+ str | list | dict | None: The scenario configuration.
36
+ """
23
37
  if scenario_id is not None:
24
38
  scenario_arr = scenario_id.split(":")
25
39
  if len(scenario_arr) < 1:
@@ -28,10 +42,23 @@ def _pull_scenario(client: HumaLabApiClient,
28
42
  scenario_version = int(scenario_arr[1]) if len(scenario_arr) > 1 else None
29
43
 
30
44
  scenario_response = client.get_scenario(
31
- project_name=project_name,
32
- uuid=scenario_real_id, version=scenario_version)
33
- return scenario_response["yaml_content"]
34
- return scenario
45
+ project_name=project,
46
+ uuid=scenario_real_id,
47
+ version=scenario_version)
48
+ final_scenario = scenario_response["yaml_content"]
49
+ else:
50
+ final_scenario = scenario
51
+
52
+ if isinstance(final_scenario, Scenario):
53
+ scenario_inst = final_scenario
54
+ else:
55
+ scenario_inst = Scenario()
56
+ scenario_inst.init(scenario=final_scenario,
57
+ seed=seed,
58
+ scenario_id=scenario_id,
59
+ #num_env=num_env,
60
+ )
61
+ return scenario_inst
35
62
 
36
63
  @contextmanager
37
64
  def init(project: str | None = None,
@@ -39,14 +66,15 @@ def init(project: str | None = None,
39
66
  description: str | None = None,
40
67
  id: str | None = None,
41
68
  tags: list[str] | None = None,
42
- scenario: str | list | dict | None = None,
69
+ scenario: str | list | dict | Scenario | None = None,
43
70
  scenario_id: str | None = None,
71
+ seed: int | None=None,
72
+ auto_create_scenario: bool = False,
73
+ # num_env: int | None = None,
74
+
44
75
  base_url: str | None = None,
45
76
  api_key: str | None = None,
46
- seed: int | None=None,
47
77
  timeout: float | None = None,
48
- # num_env: int | None = None,
49
- auto_create_scenario: bool = False,
50
78
  ) -> Generator[Run, None, None]:
51
79
  """
52
80
  Initialize a new HumaLab run.
@@ -63,39 +91,28 @@ def init(project: str | None = None,
63
91
  api_key: The API key for authentication.
64
92
  seed: An optional seed for scenario randomization.
65
93
  timeout: The timeout for API requests.
66
- # num_env: The number of parallel environments to run. (Not supported yet.)
67
94
  auto_create_scenario: Whether to automatically create the scenario if it does not exist.
95
+ # num_env: The number of parallel environments to run. (Not supported yet.)
68
96
  """
69
97
  global _cur_run
70
98
  run = None
71
99
  try:
72
- humalab_config = HumalabConfig()
73
- project = project or "default"
100
+ project = project or DEFAULT_PROJECT
74
101
  name = name or ""
75
102
  description = description or ""
76
103
  id = id or str(uuid.uuid4())
77
104
 
78
- base_url = base_url or humalab_config.base_url
79
- api_key = api_key or humalab_config.api_key
80
- timeout = timeout or humalab_config.timeout
81
-
82
105
  api_client = HumaLabApiClient(base_url=base_url,
83
106
  api_key=api_key,
84
107
  timeout=timeout)
85
- final_scenario = _pull_scenario(client=api_client,
86
- project_name=project,
108
+ scenario_inst = _pull_scenario(client=api_client,
109
+ project=project,
110
+ seed=seed,
87
111
  scenario=scenario,
88
112
  scenario_id=scenario_id)
89
113
 
90
114
  project_resp = api_client.create_project(name=project)
91
-
92
- scenario_inst = Scenario()
93
- scenario_inst.init(run_id=id,
94
- scenario=final_scenario,
95
- seed=seed,
96
- episode_id=str(uuid.uuid4()),
97
- #num_env=num_env
98
- )
115
+
99
116
  if scenario_id is None and scenario is not None and auto_create_scenario:
100
117
  scenario_response = api_client.create_scenario(
101
118
  project_name=project_resp['name'],
@@ -108,6 +125,10 @@ def init(project: str | None = None,
108
125
  run_response = api_client.get_run(run_id=id)
109
126
  api_client.update_run(
110
127
  run_id=run_response['run_id'],
128
+ name=name,
129
+ description=description,
130
+ tags=tags,
131
+ status=RunStatus.RUNNING,
111
132
  )
112
133
 
113
134
  except requests.HTTPError as e:
@@ -137,26 +158,60 @@ def init(project: str | None = None,
137
158
  id=run_response['run_id'],
138
159
  tags=run_response.get("tags"),
139
160
  scenario=scenario_inst,
161
+
162
+ base_url=base_url,
163
+ api_key=api_key,
164
+ timeout=timeout
140
165
  )
141
166
 
142
167
  _cur_run = run
143
168
  yield run
144
- finally:
145
- if run:
146
- run.finish()
147
-
169
+ except Exception as e:
170
+ if _cur_run:
171
+ exc_type, exc_value, exc_traceback = sys.exc_info()
172
+ formatted_traceback = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
173
+ finish(status=RunStatus.ERRORED,
174
+ err_msg=formatted_traceback)
175
+ raise
176
+ else:
177
+ if _cur_run:
178
+ print("Finishing run...")
179
+ finish(status=RunStatus.FINISHED)
180
+
181
+ def discard() -> None:
182
+ """Discard the current run by finishing it with CANCELED status."""
183
+ finish(status=RunStatus.CANCELED)
184
+
185
+ def finish(status: RunStatus = RunStatus.FINISHED,
186
+ err_msg: str | None = None) -> None:
187
+ """Finish the current run.
148
188
 
149
- def finish(status: EpisodeStatus = EpisodeStatus.PASS,
150
- quiet: bool | None = None) -> None:
189
+ Args:
190
+ status (RunStatus): The final status of the run. Defaults to FINISHED.
191
+ err_msg (str | None): Optional error message if the run errored.
192
+ """
151
193
  global _cur_run
152
194
  if _cur_run:
153
- _cur_run.finish(status=status, quiet=quiet)
195
+ _cur_run.finish(status=status, err_msg=err_msg)
196
+ _cur_run = None
154
197
 
155
198
  def login(api_key: str | None = None,
156
199
  relogin: bool | None = None,
157
200
  host: str | None = None,
158
201
  force: bool | None = None,
159
202
  timeout: float | None = None) -> bool:
203
+ """Configure HumaLab authentication and connection settings.
204
+
205
+ Args:
206
+ api_key (str | None): API key for authentication.
207
+ relogin (bool | None): Unused parameter (for compatibility).
208
+ host (str | None): API host URL.
209
+ force (bool | None): Unused parameter (for compatibility).
210
+ timeout (float | None): Request timeout in seconds.
211
+
212
+ Returns:
213
+ bool: Always returns True.
214
+ """
160
215
  humalab_config = HumalabConfig()
161
216
  humalab_config.api_key = api_key or humalab_config.api_key
162
217
  humalab_config.base_url = host or humalab_config.base_url