humalab 0.0.5__py3-none-any.whl → 0.0.6__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 (37) hide show
  1. humalab/__init__.py +11 -0
  2. humalab/assets/__init__.py +2 -2
  3. humalab/assets/files/resource_file.py +29 -3
  4. humalab/assets/files/urdf_file.py +14 -10
  5. humalab/assets/resource_operator.py +91 -0
  6. humalab/constants.py +39 -5
  7. humalab/dists/bernoulli.py +2 -1
  8. humalab/dists/discrete.py +2 -2
  9. humalab/dists/gaussian.py +2 -2
  10. humalab/dists/log_uniform.py +2 -2
  11. humalab/dists/truncated_gaussian.py +4 -4
  12. humalab/episode.py +181 -11
  13. humalab/humalab.py +44 -28
  14. humalab/humalab_api_client.py +301 -94
  15. humalab/humalab_test.py +46 -17
  16. humalab/metrics/__init__.py +5 -5
  17. humalab/metrics/code.py +28 -0
  18. humalab/metrics/metric.py +41 -108
  19. humalab/metrics/scenario_stats.py +95 -0
  20. humalab/metrics/summary.py +24 -18
  21. humalab/run.py +180 -103
  22. humalab/scenarios/__init__.py +4 -0
  23. humalab/{scenario.py → scenarios/scenario.py} +120 -129
  24. humalab/scenarios/scenario_operator.py +82 -0
  25. humalab/{scenario_test.py → scenarios/scenario_test.py} +150 -269
  26. humalab/utils.py +37 -0
  27. {humalab-0.0.5.dist-info → humalab-0.0.6.dist-info}/METADATA +1 -1
  28. humalab-0.0.6.dist-info/RECORD +39 -0
  29. humalab/assets/resource_manager.py +0 -58
  30. humalab/evaluators/__init__.py +0 -16
  31. humalab/humalab_main.py +0 -119
  32. humalab/metrics/dist_metric.py +0 -22
  33. humalab-0.0.5.dist-info/RECORD +0 -37
  34. {humalab-0.0.5.dist-info → humalab-0.0.6.dist-info}/WHEEL +0 -0
  35. {humalab-0.0.5.dist-info → humalab-0.0.6.dist-info}/entry_points.txt +0 -0
  36. {humalab-0.0.5.dist-info → humalab-0.0.6.dist-info}/licenses/LICENSE +0 -0
  37. {humalab-0.0.5.dist-info → humalab-0.0.6.dist-info}/top_level.txt +0 -0
humalab/humalab.py CHANGED
@@ -1,23 +1,25 @@
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,
22
+ project: str,
21
23
  scenario: str | list | dict | None = None,
22
24
  scenario_id: str | None = None,) -> str | list | dict | None:
23
25
  if scenario_id is not None:
@@ -28,7 +30,7 @@ def _pull_scenario(client: HumaLabApiClient,
28
30
  scenario_version = int(scenario_arr[1]) if len(scenario_arr) > 1 else None
29
31
 
30
32
  scenario_response = client.get_scenario(
31
- project_name=project_name,
33
+ project_name=project,
32
34
  uuid=scenario_real_id, version=scenario_version)
33
35
  return scenario_response["yaml_content"]
34
36
  return scenario
@@ -41,12 +43,13 @@ def init(project: str | None = None,
41
43
  tags: list[str] | None = None,
42
44
  scenario: str | list | dict | None = None,
43
45
  scenario_id: str | None = None,
46
+ seed: int | None=None,
47
+ auto_create_scenario: bool = False,
48
+ # num_env: int | None = None,
49
+
44
50
  base_url: str | None = None,
45
51
  api_key: str | None = None,
46
- seed: int | None=None,
47
52
  timeout: float | None = None,
48
- # num_env: int | None = None,
49
- auto_create_scenario: bool = False,
50
53
  ) -> Generator[Run, None, None]:
51
54
  """
52
55
  Initialize a new HumaLab run.
@@ -63,38 +66,32 @@ def init(project: str | None = None,
63
66
  api_key: The API key for authentication.
64
67
  seed: An optional seed for scenario randomization.
65
68
  timeout: The timeout for API requests.
66
- # num_env: The number of parallel environments to run. (Not supported yet.)
67
69
  auto_create_scenario: Whether to automatically create the scenario if it does not exist.
70
+ # num_env: The number of parallel environments to run. (Not supported yet.)
68
71
  """
69
72
  global _cur_run
70
73
  run = None
71
74
  try:
72
- humalab_config = HumalabConfig()
73
- project = project or "default"
75
+ project = project or DEFAULT_PROJECT
74
76
  name = name or ""
75
77
  description = description or ""
76
78
  id = id or str(uuid.uuid4())
77
79
 
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
80
  api_client = HumaLabApiClient(base_url=base_url,
83
81
  api_key=api_key,
84
82
  timeout=timeout)
85
83
  final_scenario = _pull_scenario(client=api_client,
86
- project_name=project,
84
+ project=project,
87
85
  scenario=scenario,
88
86
  scenario_id=scenario_id)
89
87
 
90
88
  project_resp = api_client.create_project(name=project)
91
89
 
92
90
  scenario_inst = Scenario()
93
- scenario_inst.init(run_id=id,
94
- scenario=final_scenario,
91
+ scenario_inst.init(scenario=final_scenario,
95
92
  seed=seed,
96
- episode_id=str(uuid.uuid4()),
97
- #num_env=num_env
93
+ scenario_id=scenario_id,
94
+ #num_env=num_env,
98
95
  )
99
96
  if scenario_id is None and scenario is not None and auto_create_scenario:
100
97
  scenario_response = api_client.create_scenario(
@@ -108,6 +105,10 @@ def init(project: str | None = None,
108
105
  run_response = api_client.get_run(run_id=id)
109
106
  api_client.update_run(
110
107
  run_id=run_response['run_id'],
108
+ name=name,
109
+ description=description,
110
+ tags=tags,
111
+ status=RunStatus.RUNNING,
111
112
  )
112
113
 
113
114
  except requests.HTTPError as e:
@@ -137,20 +138,35 @@ def init(project: str | None = None,
137
138
  id=run_response['run_id'],
138
139
  tags=run_response.get("tags"),
139
140
  scenario=scenario_inst,
141
+
142
+ base_url=base_url,
143
+ api_key=api_key,
144
+ timeout=timeout
140
145
  )
141
146
 
142
147
  _cur_run = run
143
148
  yield run
144
- finally:
145
- if run:
146
- run.finish()
147
-
148
-
149
- def finish(status: EpisodeStatus = EpisodeStatus.PASS,
150
- quiet: bool | None = None) -> None:
149
+ except Exception as e:
150
+ if _cur_run:
151
+ exc_type, exc_value, exc_traceback = sys.exc_info()
152
+ formatted_traceback = ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
153
+ finish(status=RunStatus.ERRORED,
154
+ err_msg=formatted_traceback)
155
+ raise
156
+ else:
157
+ if _cur_run:
158
+ print("Finishing run...")
159
+ finish(status=RunStatus.FINISHED)
160
+
161
+ def discard() -> None:
162
+ finish(status=RunStatus.CANCELED)
163
+
164
+ def finish(status: RunStatus = RunStatus.FINISHED,
165
+ err_msg: str | None = None) -> None:
151
166
  global _cur_run
152
167
  if _cur_run:
153
- _cur_run.finish(status=status, quiet=quiet)
168
+ _cur_run.finish(status=status, err_msg=err_msg)
169
+ _cur_run = None
154
170
 
155
171
  def login(api_key: str | None = None,
156
172
  relogin: bool | None = None,