humalab 0.0.4__tar.gz → 0.0.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.

Potentially problematic release.


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

Files changed (55) hide show
  1. humalab-0.0.5/.github/pull_request_template.md +8 -0
  2. {humalab-0.0.4/humalab.egg-info → humalab-0.0.5}/PKG-INFO +1 -1
  3. humalab-0.0.5/VERSION +1 -0
  4. humalab-0.0.5/humalab/assets/__init__.py +4 -0
  5. {humalab-0.0.4 → humalab-0.0.5}/humalab/assets/files/urdf_file.py +1 -1
  6. {humalab-0.0.4 → humalab-0.0.5}/humalab/assets/resource_manager.py +3 -2
  7. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/bernoulli.py +15 -0
  8. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/categorical.py +4 -0
  9. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/discrete.py +22 -0
  10. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/gaussian.py +22 -0
  11. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/log_uniform.py +22 -0
  12. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/truncated_gaussian.py +36 -0
  13. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/uniform.py +22 -0
  14. humalab-0.0.5/humalab/episode.py +26 -0
  15. humalab-0.0.5/humalab/evaluators/__init__.py +16 -0
  16. humalab-0.0.5/humalab/humalab.py +164 -0
  17. humalab-0.0.5/humalab/humalab_api_client.py +764 -0
  18. {humalab-0.0.4 → humalab-0.0.5}/humalab/humalab_config.py +0 -13
  19. humalab-0.0.5/humalab/humalab_main.py +119 -0
  20. {humalab-0.0.4 → humalab-0.0.5}/humalab/humalab_test.py +0 -12
  21. {humalab-0.0.4 → humalab-0.0.5}/humalab/run.py +0 -12
  22. {humalab-0.0.4 → humalab-0.0.5}/humalab/scenario.py +172 -16
  23. {humalab-0.0.4 → humalab-0.0.5/humalab.egg-info}/PKG-INFO +1 -1
  24. {humalab-0.0.4 → humalab-0.0.5}/humalab.egg-info/SOURCES.txt +4 -0
  25. {humalab-0.0.4 → humalab-0.0.5}/pyproject.toml +1 -1
  26. humalab-0.0.4/VERSION +0 -1
  27. humalab-0.0.4/humalab/assets/__init__.py +0 -4
  28. humalab-0.0.4/humalab/humalab.py +0 -217
  29. humalab-0.0.4/humalab/humalab_api_client.py +0 -273
  30. {humalab-0.0.4 → humalab-0.0.5}/.gitignore +0 -0
  31. {humalab-0.0.4 → humalab-0.0.5}/LICENSE +0 -0
  32. {humalab-0.0.4 → humalab-0.0.5}/Makefile +0 -0
  33. {humalab-0.0.4 → humalab-0.0.5}/README.md +0 -0
  34. {humalab-0.0.4 → humalab-0.0.5}/build.sh +0 -0
  35. {humalab-0.0.4 → humalab-0.0.5}/humalab/__init__.py +0 -0
  36. {humalab-0.0.4 → humalab-0.0.5}/humalab/assets/archive.py +0 -0
  37. {humalab-0.0.4 → humalab-0.0.5}/humalab/assets/files/__init__.py +0 -0
  38. {humalab-0.0.4 → humalab-0.0.5}/humalab/assets/files/resource_file.py +0 -0
  39. {humalab-0.0.4 → humalab-0.0.5}/humalab/constants.py +0 -0
  40. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/__init__.py +0 -0
  41. {humalab-0.0.4 → humalab-0.0.5}/humalab/dists/distribution.py +0 -0
  42. {humalab-0.0.4 → humalab-0.0.5}/humalab/metrics/__init__.py +0 -0
  43. {humalab-0.0.4 → humalab-0.0.5}/humalab/metrics/dist_metric.py +0 -0
  44. {humalab-0.0.4 → humalab-0.0.5}/humalab/metrics/metric.py +0 -0
  45. {humalab-0.0.4 → humalab-0.0.5}/humalab/metrics/summary.py +0 -0
  46. {humalab-0.0.4 → humalab-0.0.5}/humalab/scenario_test.py +0 -0
  47. {humalab-0.0.4 → humalab-0.0.5}/humalab.egg-info/dependency_links.txt +0 -0
  48. {humalab-0.0.4 → humalab-0.0.5}/humalab.egg-info/entry_points.txt +0 -0
  49. {humalab-0.0.4 → humalab-0.0.5}/humalab.egg-info/not-zip-safe +0 -0
  50. {humalab-0.0.4 → humalab-0.0.5}/humalab.egg-info/requires.txt +0 -0
  51. {humalab-0.0.4 → humalab-0.0.5}/humalab.egg-info/top_level.txt +0 -0
  52. {humalab-0.0.4 → humalab-0.0.5}/requirements-dev.txt +0 -0
  53. {humalab-0.0.4 → humalab-0.0.5}/requirements.txt +0 -0
  54. {humalab-0.0.4 → humalab-0.0.5}/setup.cfg +0 -0
  55. {humalab-0.0.4 → humalab-0.0.5}/setup.py +0 -0
@@ -0,0 +1,8 @@
1
+
2
+ ## Description
3
+ <!--- Describe your changes in detail -->
4
+
5
+ ## Related Issue
6
+ <!--- closes #<issue number> -->
7
+
8
+ ## Screenshots (if appropriate):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: humalab
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: Python SDK for HumaLab - A platform for adaptive AI validation.
5
5
  Home-page: https://github.com/humalab/humalab_sdk
6
6
  Author: HumaLab Team
humalab-0.0.5/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.5
@@ -0,0 +1,4 @@
1
+ from .resource_manager import ResourceManager
2
+ from .files import ResourceFile, URDFFile
3
+
4
+ __all__ = ["ResourceManager", "ResourceFile", "URDFFile"]
@@ -25,7 +25,7 @@ class URDFFile(ResourceFile):
25
25
 
26
26
  def _extract(self):
27
27
  working_path = os.path.dirname(self._filename)
28
- if not os.path.exists(working_path):
28
+ if os.path.exists(self._filename):
29
29
  _, ext = os.path.splitext(self._filename)
30
30
  ext = ext.lstrip('.') # Remove leading dot
31
31
  if ext.lower() != "urdf":
@@ -31,13 +31,14 @@ class ResourceManager:
31
31
  return False
32
32
 
33
33
  def download(self,
34
+ project: str,
34
35
  name: str,
35
36
  version: int | None=None) -> Any:
36
- resource = self._api_client.get_resource(name=name, version=version)
37
- file_content = self._api_client.download_resource(name="lerobot")
37
+ resource = self._api_client.get_resource(project_name=project, name=name, version=version)
38
38
  filename = os.path.basename(resource['resource_url'])
39
39
  filename = os.path.join(self._asset_dir(name, resource["version"]), filename)
40
40
  if self._create_asset_dir(name, resource["version"]):
41
+ file_content = self._api_client.download_resource(project_name=project, name="lerobot")
41
42
  with open(filename, "wb") as f:
42
43
  f.write(file_content)
43
44
 
@@ -20,6 +20,21 @@ class Bernoulli(Distribution):
20
20
  self._p = p
21
21
  self._size = size
22
22
 
23
+ @staticmethod
24
+ def validate(dimensions: int, *args) -> bool:
25
+ arg1 = args[0]
26
+ if dimensions == 0:
27
+ if not isinstance(arg1, (int, float)):
28
+ return False
29
+ return True
30
+ if dimensions == -1:
31
+ return True
32
+ if not isinstance(arg1, (int, float)):
33
+ if isinstance(arg1, (list, np.ndarray)):
34
+ if len(arg1) > dimensions:
35
+ return False
36
+ return True
37
+
23
38
  def _sample(self) -> int | float | np.ndarray:
24
39
  return self._generator.binomial(n=1, p=self._p, size=self._size)
25
40
 
@@ -25,6 +25,10 @@ class Categorical(Distribution):
25
25
  weights = [w / weight_sum for w in weights]
26
26
  self._weights = weights
27
27
 
28
+ @staticmethod
29
+ def validate(dimensions: int, *args) -> bool:
30
+ return True
31
+
28
32
  def _sample(self) -> int | float | np.ndarray:
29
33
  return self._generator.choice(self._choices, size=self._size, p=self._weights)
30
34
 
@@ -26,6 +26,28 @@ class Discrete(Distribution):
26
26
  self._high = np.array(high)
27
27
  self._size = size
28
28
  self._endpoint = endpoint if endpoint is not None else True
29
+
30
+ @staticmethod
31
+ def validate(dimensions: int, *args) -> bool:
32
+ arg1 = args[0]
33
+ arg2 = args[1]
34
+ if dimensions == 0:
35
+ if not isinstance(arg1, int):
36
+ return False
37
+ if not isinstance(arg2, int):
38
+ return False
39
+ return True
40
+ if dimensions == -1:
41
+ return True
42
+ if not isinstance(arg1, int):
43
+ if isinstance(arg1, (list, np.ndarray)):
44
+ if len(arg1) > dimensions:
45
+ return False
46
+ if not isinstance(arg2, int):
47
+ if isinstance(arg2, (list, np.ndarray)):
48
+ if len(arg2) > dimensions:
49
+ return False
50
+ return True
29
51
 
30
52
  def _sample(self) -> int | float | np.ndarray:
31
53
  return self._generator.integers(self._low, self._high, size=self._size, endpoint=self._endpoint)
@@ -23,6 +23,28 @@ class Gaussian(Distribution):
23
23
  self._scale = scale
24
24
  self._size = size
25
25
 
26
+ @staticmethod
27
+ def validate(dimensions: int, *args) -> bool:
28
+ arg1 = args[0]
29
+ arg2 = args[1]
30
+ if dimensions == 0:
31
+ if not isinstance(arg1, (int, float)):
32
+ return False
33
+ if not isinstance(arg2, (int, float)):
34
+ return False
35
+ return True
36
+ if dimensions == -1:
37
+ return True
38
+ if not isinstance(arg1, (int, float)):
39
+ if isinstance(arg1, (list, np.ndarray)):
40
+ if len(arg1) > dimensions:
41
+ return False
42
+ if not isinstance(arg2, (int, float)):
43
+ if isinstance(arg2, (list, np.ndarray)):
44
+ if len(arg2) > dimensions:
45
+ return False
46
+ return True
47
+
26
48
  def _sample(self) -> int | float | np.ndarray:
27
49
  return self._generator.normal(loc=self._loc, scale=self._scale, size=self._size)
28
50
 
@@ -22,6 +22,28 @@ class LogUniform(Distribution):
22
22
  self._log_low = np.log(np.array(low))
23
23
  self._log_high = np.log(np.array(high))
24
24
  self._size = size
25
+
26
+ @staticmethod
27
+ def validate(dimensions: int, *args) -> bool:
28
+ arg1 = args[0]
29
+ arg2 = args[1]
30
+ if dimensions == 0:
31
+ if not isinstance(arg1, (int, float)):
32
+ return False
33
+ if not isinstance(arg2, (int, float)):
34
+ return False
35
+ return True
36
+ if dimensions == -1:
37
+ return True
38
+ if not isinstance(arg1, (int, float)):
39
+ if isinstance(arg1, (list, np.ndarray)):
40
+ if len(arg1) > dimensions:
41
+ return False
42
+ if not isinstance(arg2, (int, float)):
43
+ if isinstance(arg2, (list, np.ndarray)):
44
+ if len(arg2) > dimensions:
45
+ return False
46
+ return True
25
47
 
26
48
  def _sample(self) -> int | float | np.ndarray:
27
49
  return np.exp(self._generator.uniform(self._log_low, self._log_high, size=self._size))
@@ -29,6 +29,42 @@ class TruncatedGaussian(Distribution):
29
29
  self._high = high
30
30
  self._size = size
31
31
 
32
+ @staticmethod
33
+ def validate(dimensions: int, *args) -> bool:
34
+ arg1 = args[0]
35
+ arg2 = args[1]
36
+ arg3 = args[2]
37
+ arg4 = args[3]
38
+ if dimensions == 0:
39
+ if not isinstance(arg1, (int, float)):
40
+ return False
41
+ if not isinstance(arg2, (int, float)):
42
+ return False
43
+ if not isinstance(arg3, (int, float)):
44
+ return False
45
+ if not isinstance(arg4, (int, float)):
46
+ return False
47
+ return True
48
+ if dimensions == -1:
49
+ return True
50
+ if not isinstance(arg1, (int, float)):
51
+ if isinstance(arg1, (list, np.ndarray)):
52
+ if len(arg1) > dimensions:
53
+ return False
54
+ if not isinstance(arg2, (int, float)):
55
+ if isinstance(arg2, (list, np.ndarray)):
56
+ if len(arg2) > dimensions:
57
+ return False
58
+ if not isinstance(arg3, (int, float)):
59
+ if isinstance(arg3, (list, np.ndarray)):
60
+ if len(arg3) > dimensions:
61
+ return False
62
+ if not isinstance(arg4, (int, float)):
63
+ if isinstance(arg4, (list, np.ndarray)):
64
+ if len(arg4) > dimensions:
65
+ return False
66
+ return True
67
+
32
68
  def _sample(self) -> int | float | np.ndarray:
33
69
  samples = self._generator.normal(loc=self._loc, scale=self._scale, size=self._size)
34
70
  mask = (samples < self._low) | (samples > self._high)
@@ -23,6 +23,28 @@ class Uniform(Distribution):
23
23
  self._high = np.array(high)
24
24
  self._size = size
25
25
 
26
+ @staticmethod
27
+ def validate(dimensions: int, *args) -> bool:
28
+ arg1 = args[0]
29
+ arg2 = args[1]
30
+ if dimensions == 0:
31
+ if not isinstance(arg1, (int, float)):
32
+ return False
33
+ if not isinstance(arg2, (int, float)):
34
+ return False
35
+ return True
36
+ if dimensions == -1:
37
+ return True
38
+ if not isinstance(arg1, (int, float)):
39
+ if isinstance(arg1, (list, np.ndarray)):
40
+ if len(arg1) > dimensions:
41
+ return False
42
+ if not isinstance(arg2, (int, float)):
43
+ if isinstance(arg2, (list, np.ndarray)):
44
+ if len(arg2) > dimensions:
45
+ return False
46
+ return True
47
+
26
48
  def _sample(self) -> int | float | np.ndarray:
27
49
  return self._generator.uniform(self._low, self._high, size=self._size)
28
50
 
@@ -0,0 +1,26 @@
1
+
2
+ from humalab.scenario import Scenario
3
+ from omegaconf import DictConfig, OmegaConf
4
+
5
+
6
+ class Episode:
7
+ def __init__(self, run_id: str, episode_id: str, scenario_conf: DictConfig):
8
+ self.run_id = run_id
9
+ self.episode_id = episode_id
10
+ self.scenario_conf = scenario_conf
11
+
12
+ @property
13
+ def scenario(self) -> DictConfig:
14
+ return self.scenario_conf
15
+
16
+ def finish(self):
17
+ print(f"Finishing episode {self.episode_id} for scenario {self.scenario.name}")
18
+
19
+ @property
20
+ def yaml(self) -> str:
21
+ """The current scenario configuration as a YAML string.
22
+
23
+ Returns:
24
+ str: The current scenario as a YAML string.
25
+ """
26
+ return OmegaConf.to_yaml(self.scenario_conf)
@@ -0,0 +1,16 @@
1
+ import random
2
+
3
+ def evaluate(video_path: str | list, task: str | list) -> dict | list[dict]:
4
+ """
5
+ Evaluate the video and return metrics.
6
+ """
7
+ # Placeholder implementation
8
+ if isinstance(video_path, list):
9
+ return [{"video_path": vp, "task": t,
10
+ "score": random.uniform(0, 1),
11
+ "confidence": random.uniform(0, 1)} for vp, t in zip(video_path, task)]
12
+ else:
13
+ return {"video_path": video_path, "task": task, "score": random.uniform(0, 1),
14
+ "confidence": random.uniform(0, 1)}
15
+
16
+ __all__ = ["evaluate"]
@@ -0,0 +1,164 @@
1
+ from contextlib import contextmanager
2
+
3
+ from omegaconf import OmegaConf
4
+
5
+ from humalab.run import Run
6
+ from humalab.humalab_config import HumalabConfig
7
+ from humalab.humalab_api_client import HumaLabApiClient
8
+ from humalab.constants import EpisodeStatus
9
+ import requests
10
+
11
+ import uuid
12
+
13
+ from collections.abc import Generator
14
+
15
+ from humalab.scenario import Scenario
16
+
17
+ _cur_run: Run | None = None
18
+
19
+ 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:
23
+ if scenario_id is not None:
24
+ scenario_arr = scenario_id.split(":")
25
+ if len(scenario_arr) < 1:
26
+ raise ValueError("Invalid scenario_id format. Expected 'scenario_id' or 'scenario_name:version'.")
27
+ scenario_real_id = scenario_arr[0]
28
+ scenario_version = int(scenario_arr[1]) if len(scenario_arr) > 1 else None
29
+
30
+ 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
35
+
36
+ @contextmanager
37
+ def init(project: str | None = None,
38
+ name: str | None = None,
39
+ description: str | None = None,
40
+ id: str | None = None,
41
+ tags: list[str] | None = None,
42
+ scenario: str | list | dict | None = None,
43
+ scenario_id: str | None = None,
44
+ base_url: str | None = None,
45
+ api_key: str | None = None,
46
+ seed: int | None=None,
47
+ timeout: float | None = None,
48
+ # num_env: int | None = None,
49
+ auto_create_scenario: bool = False,
50
+ ) -> Generator[Run, None, None]:
51
+ """
52
+ Initialize a new HumaLab run.
53
+
54
+ Args:
55
+ project: The project name under which to create the run.
56
+ name: The name of the run.
57
+ description: A description of the run.
58
+ id: The unique identifier for the run. If None, a new UUID will be generated.
59
+ tags: A list of tags to associate with the run.
60
+ scenario: The scenario configuration as a string, list, or dict.
61
+ scenario_id: The unique identifier of a pre-defined scenario to use.
62
+ base_url: The base URL of the HumaLab server.
63
+ api_key: The API key for authentication.
64
+ seed: An optional seed for scenario randomization.
65
+ timeout: The timeout for API requests.
66
+ # num_env: The number of parallel environments to run. (Not supported yet.)
67
+ auto_create_scenario: Whether to automatically create the scenario if it does not exist.
68
+ """
69
+ global _cur_run
70
+ run = None
71
+ try:
72
+ humalab_config = HumalabConfig()
73
+ project = project or "default"
74
+ name = name or ""
75
+ description = description or ""
76
+ id = id or str(uuid.uuid4())
77
+
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
+ api_client = HumaLabApiClient(base_url=base_url,
83
+ api_key=api_key,
84
+ timeout=timeout)
85
+ final_scenario = _pull_scenario(client=api_client,
86
+ project_name=project,
87
+ scenario=scenario,
88
+ scenario_id=scenario_id)
89
+
90
+ 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
+ )
99
+ if scenario_id is None and scenario is not None and auto_create_scenario:
100
+ scenario_response = api_client.create_scenario(
101
+ project_name=project_resp['name'],
102
+ name=f"{name} scenario",
103
+ description="Auto-created scenario",
104
+ yaml_content=OmegaConf.to_yaml(scenario_inst.template),
105
+ )
106
+ scenario_id = scenario_response['uuid']
107
+ try:
108
+ run_response = api_client.get_run(run_id=id)
109
+ api_client.update_run(
110
+ run_id=run_response['run_id'],
111
+ )
112
+
113
+ except requests.HTTPError as e:
114
+ if e.response.status_code == 404:
115
+ # If not found then create a new run,
116
+ # so ignore not found error.
117
+ run_response = None
118
+ else:
119
+ # Otherwise re-raise the exception.
120
+ raise
121
+
122
+ if run_response is None:
123
+ run_response = api_client.create_run(name=name,
124
+ project_name=project_resp['name'],
125
+ description=description,
126
+ tags=tags)
127
+ id = run_response['run_id']
128
+ api_client.update_run(
129
+ run_id=id,
130
+ description=description,
131
+ )
132
+
133
+ run = Run(
134
+ project=project_resp['name'],
135
+ name=run_response["name"],
136
+ description=run_response.get("description"),
137
+ id=run_response['run_id'],
138
+ tags=run_response.get("tags"),
139
+ scenario=scenario_inst,
140
+ )
141
+
142
+ _cur_run = run
143
+ 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:
151
+ global _cur_run
152
+ if _cur_run:
153
+ _cur_run.finish(status=status, quiet=quiet)
154
+
155
+ def login(api_key: str | None = None,
156
+ relogin: bool | None = None,
157
+ host: str | None = None,
158
+ force: bool | None = None,
159
+ timeout: float | None = None) -> bool:
160
+ humalab_config = HumalabConfig()
161
+ humalab_config.api_key = api_key or humalab_config.api_key
162
+ humalab_config.base_url = host or humalab_config.base_url
163
+ humalab_config.timeout = timeout or humalab_config.timeout
164
+ return True