humalab 0.0.1__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 (40) hide show
  1. humalab-0.0.1/.gitignore +207 -0
  2. humalab-0.0.1/LICENSE +21 -0
  3. humalab-0.0.1/PKG-INFO +43 -0
  4. humalab-0.0.1/README.md +2 -0
  5. humalab-0.0.1/humalab/__init__.py +9 -0
  6. humalab-0.0.1/humalab/assets/__init__.py +0 -0
  7. humalab-0.0.1/humalab/assets/archive.py +101 -0
  8. humalab-0.0.1/humalab/assets/resource_file.py +28 -0
  9. humalab-0.0.1/humalab/assets/resource_handler.py +175 -0
  10. humalab-0.0.1/humalab/constants.py +7 -0
  11. humalab-0.0.1/humalab/dists/__init__.py +17 -0
  12. humalab-0.0.1/humalab/dists/bernoulli.py +44 -0
  13. humalab-0.0.1/humalab/dists/categorical.py +49 -0
  14. humalab-0.0.1/humalab/dists/discrete.py +56 -0
  15. humalab-0.0.1/humalab/dists/distribution.py +38 -0
  16. humalab-0.0.1/humalab/dists/gaussian.py +49 -0
  17. humalab-0.0.1/humalab/dists/log_uniform.py +49 -0
  18. humalab-0.0.1/humalab/dists/truncated_gaussian.py +64 -0
  19. humalab-0.0.1/humalab/dists/uniform.py +49 -0
  20. humalab-0.0.1/humalab/humalab.py +149 -0
  21. humalab-0.0.1/humalab/humalab_api_client.py +273 -0
  22. humalab-0.0.1/humalab/humalab_config.py +86 -0
  23. humalab-0.0.1/humalab/humalab_test.py +510 -0
  24. humalab-0.0.1/humalab/metrics/__init__.py +11 -0
  25. humalab-0.0.1/humalab/metrics/dist_metric.py +22 -0
  26. humalab-0.0.1/humalab/metrics/metric.py +129 -0
  27. humalab-0.0.1/humalab/metrics/summary.py +54 -0
  28. humalab-0.0.1/humalab/run.py +214 -0
  29. humalab-0.0.1/humalab/scenario.py +225 -0
  30. humalab-0.0.1/humalab/scenario_test.py +911 -0
  31. humalab-0.0.1/humalab.egg-info/PKG-INFO +43 -0
  32. humalab-0.0.1/humalab.egg-info/SOURCES.txt +38 -0
  33. humalab-0.0.1/humalab.egg-info/dependency_links.txt +1 -0
  34. humalab-0.0.1/humalab.egg-info/entry_points.txt +2 -0
  35. humalab-0.0.1/humalab.egg-info/not-zip-safe +1 -0
  36. humalab-0.0.1/humalab.egg-info/requires.txt +11 -0
  37. humalab-0.0.1/humalab.egg-info/top_level.txt +1 -0
  38. humalab-0.0.1/pyproject.toml +97 -0
  39. humalab-0.0.1/setup.cfg +4 -0
  40. humalab-0.0.1/setup.py +74 -0
@@ -0,0 +1,207 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+ #poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ #pdm.lock
116
+ #pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ #pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # SageMath parsed files
135
+ *.sage.py
136
+
137
+ # Environments
138
+ .env
139
+ .envrc
140
+ .venv
141
+ env/
142
+ venv/
143
+ ENV/
144
+ env.bak/
145
+ venv.bak/
146
+
147
+ # Spyder project settings
148
+ .spyderproject
149
+ .spyproject
150
+
151
+ # Rope project settings
152
+ .ropeproject
153
+
154
+ # mkdocs documentation
155
+ /site
156
+
157
+ # mypy
158
+ .mypy_cache/
159
+ .dmypy.json
160
+ dmypy.json
161
+
162
+ # Pyre type checker
163
+ .pyre/
164
+
165
+ # pytype static type analyzer
166
+ .pytype/
167
+
168
+ # Cython debug symbols
169
+ cython_debug/
170
+
171
+ # PyCharm
172
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
173
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
174
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
175
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
176
+ #.idea/
177
+
178
+ # Abstra
179
+ # Abstra is an AI-powered process automation framework.
180
+ # Ignore directories containing user credentials, local state, and settings.
181
+ # Learn more at https://abstra.io/docs
182
+ .abstra/
183
+
184
+ # Visual Studio Code
185
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
186
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
187
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
188
+ # you could uncomment the following to ignore the entire vscode folder
189
+ # .vscode/
190
+
191
+ # Ruff stuff:
192
+ .ruff_cache/
193
+
194
+ # PyPI configuration file
195
+ .pypirc
196
+
197
+ # Cursor
198
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
199
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
200
+ # refer to https://docs.cursor.com/context/ignore-files
201
+ .cursorignore
202
+ .cursorindexingignore
203
+
204
+ # Marimo
205
+ marimo/_static/
206
+ marimo/_lsp/
207
+ __marimo__/
humalab-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 HumaLab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
humalab-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,43 @@
1
+ Metadata-Version: 2.4
2
+ Name: humalab
3
+ Version: 0.0.1
4
+ Summary: Python SDK for HumaLab - A platform for adaptive AI validation.
5
+ Home-page: https://github.com/humalab/humalab_sdk
6
+ Author: HumaLab Team
7
+ Author-email: HumaLab Team <info@humalab.ai>
8
+ License-Expression: MIT
9
+ Project-URL: Homepage, https://github.com/humalab/humalab_sdk
10
+ Project-URL: Documentation, https://docs.humalab.ai
11
+ Project-URL: Repository, https://github.com/humalab/humalab_sdk
12
+ Project-URL: Bug Tracker, https://github.com/humalab/humalab_sdk/issues
13
+ Keywords: robotics,simulation,machine-learning,validation,sdk
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Topic :: Scientific/Engineering :: Physics
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Programming Language :: Python :: 3.9
22
+ Classifier: Programming Language :: Python :: 3.10
23
+ Classifier: Programming Language :: Python :: 3.11
24
+ Requires-Python: >=3.8
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Requires-Dist: numpy>=1.20.0
28
+ Requires-Dist: omegaconf>=2.1.0
29
+ Requires-Dist: requests>=2.25.0
30
+ Requires-Dist: pyyaml>=5.4.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=6.0.0; extra == "dev"
33
+ Requires-Dist: pytest-cov>=2.10.0; extra == "dev"
34
+ Requires-Dist: black>=21.0; extra == "dev"
35
+ Requires-Dist: flake8>=3.9.0; extra == "dev"
36
+ Requires-Dist: mypy>=0.910; extra == "dev"
37
+ Dynamic: author
38
+ Dynamic: home-page
39
+ Dynamic: license-file
40
+ Dynamic: requires-python
41
+
42
+ # humalab_sdk
43
+ Python SDK for HumaLab - A platform for adaptive AI validation.
@@ -0,0 +1,2 @@
1
+ # humalab_sdk
2
+ Python SDK for HumaLab - A platform for adaptive AI validation.
@@ -0,0 +1,9 @@
1
+ from humalab_sdk.humalab import init, finish, login
2
+ from humalab_sdk.run import Run
3
+
4
+ __all__ = [
5
+ "init",
6
+ "finish",
7
+ "login",
8
+ "Run",
9
+ ]
File without changes
@@ -0,0 +1,101 @@
1
+ import shutil
2
+ import zipfile
3
+ import tarfile
4
+ import gzip
5
+ import bz2
6
+ import lzma
7
+ from pathlib import Path
8
+
9
+
10
+ try:
11
+ import py7zr # for .7z
12
+ except ImportError:
13
+ py7zr = None
14
+
15
+ try:
16
+ import rarfile # for .rar
17
+ except ImportError:
18
+ rarfile = None
19
+
20
+
21
+ # ---------- Detection ---------------------------------------------------------
22
+ def detect_archive_type(path: str | Path) -> str:
23
+ """Return a simple string label for the archive type, else 'unknown'."""
24
+ p = Path(path).with_suffix("").name.lower() # strip double-suffix like .tar.gz
25
+ ext = Path(path).suffix.lower()
26
+
27
+ if ext == ".zip":
28
+ return "zip"
29
+ if ext in {".tar"}:
30
+ return "tar"
31
+ if ext in {".gz"} and p.endswith(".tar"):
32
+ return "tar.gz"
33
+ if ext in {".bz2"} and p.endswith(".tar"):
34
+ return "tar.bz2"
35
+ if ext in {".xz"} and p.endswith(".tar"):
36
+ return "tar.xz"
37
+ if ext == ".gz":
38
+ return "gzip"
39
+ if ext == ".bz2":
40
+ return "bzip2"
41
+ if ext == ".xz":
42
+ return "xz"
43
+ if ext == ".7z":
44
+ return "7z"
45
+ if ext == ".rar":
46
+ return "rar"
47
+ return "unknown"
48
+
49
+
50
+ def _extract_stream(open_func, path: Path, out_dir: Path):
51
+ """Helper for single-file compressed streams (.gz, .bz2, .xz)."""
52
+ out_dir.mkdir(parents=True, exist_ok=True)
53
+ out_file = out_dir / path.with_suffix("").name
54
+ with open_func(path, "rb") as f_in, open(out_file, "wb") as f_out:
55
+ shutil.copyfileobj(f_in, f_out)
56
+
57
+
58
+ # ---------- Extraction --------------------------------------------------------
59
+ def extract_archive(path: str | Path, out_dir: str | Path) -> None:
60
+ """Detect the archive type and extract it into out_dir."""
61
+ path, out_dir = Path(path), Path(out_dir)
62
+ archive_type = detect_archive_type(path)
63
+
64
+ match archive_type:
65
+ # --- ZIP
66
+ case "zip":
67
+ with zipfile.ZipFile(path) as zf:
68
+ zf.extractall(out_dir)
69
+
70
+ # --- tar.* (auto-deduces compression)
71
+ case "tar" | "tar.gz" | "tar.bz2" | "tar.xz":
72
+ with tarfile.open(path, mode="r:*") as tf:
73
+ tf.extractall(out_dir)
74
+
75
+ # --- single-file streams
76
+ case "gzip":
77
+ _extract_stream(gzip.open, path, out_dir)
78
+ case "bzip2":
79
+ _extract_stream(bz2.open, path, out_dir)
80
+ case "xz":
81
+ _extract_stream(lzma.open, path, out_dir)
82
+
83
+ # --- 7-Zip
84
+ case "7z":
85
+ if py7zr is None:
86
+ raise ImportError("py7zr not installed - run `pip install py7zr`")
87
+ with py7zr.SevenZipFile(path, mode="r") as z:
88
+ z.extractall(path=out_dir)
89
+
90
+ # --- RAR
91
+ case "rar":
92
+ if rarfile is None:
93
+ raise ImportError("rarfile not installed - run `pip install rarfile`")
94
+ if not rarfile.is_rarfile(path):
95
+ raise rarfile.BadRarFile(f"{path} is not a valid RAR archive")
96
+ with rarfile.RarFile(path) as rf:
97
+ rf.extractall(out_dir)
98
+
99
+ # --- fallback
100
+ case _:
101
+ raise ValueError(f"Unsupported or unknown archive type: {archive_type}")
@@ -0,0 +1,28 @@
1
+
2
+
3
+ class ResourceFile:
4
+ def __init__(self,
5
+ name: str,
6
+ version: int,
7
+ resource_type: str,
8
+ filepath: str):
9
+ self._name = name
10
+ self._version = version
11
+ self._resource_type = resource_type
12
+ self._filepath = filepath
13
+
14
+ @property
15
+ def name(self) -> str:
16
+ return self._name
17
+
18
+ @property
19
+ def version(self) -> int:
20
+ return self._version
21
+
22
+ @property
23
+ def resource_type(self) -> str:
24
+ return self._resource_type
25
+
26
+ @property
27
+ def filepath(self) -> str:
28
+ return self._filepath
@@ -0,0 +1,175 @@
1
+ import mongoengine as me
2
+ from minio import Minio
3
+ import os
4
+ import glob
5
+ import tempfile
6
+ import trimesh
7
+ from humalab_service.humalab_host import HumaLabHost
8
+ from humalab_service.services.stores.obj_store import ObjStore
9
+ from humalab_service.services.stores.namespace import ObjectType
10
+ from humalab_service.db.resource import ResourceDocument
11
+ from humalab_sdk.assets.archive import extract_archive
12
+
13
+
14
+ ASSET_TYPE_TO_EXTENSIONS = {
15
+ "urdf": {"urdf"},
16
+ "mjcf": {"xml"},
17
+ "mesh": trimesh.available_formats(),
18
+ "usd": {"usd"},
19
+ "controller": {"py"},
20
+ "global_controller": {"py"},
21
+ "terminator": {"py"},
22
+ "data": {},
23
+ }
24
+
25
+ class ResourceHandler:
26
+ def __init__(self, working_path: str=tempfile.gettempdir()):
27
+ self._minio_client = Minio(
28
+ HumaLabHost.get_minio_service_address(),
29
+ access_key="humalab",
30
+ secret_key="humalab123",
31
+ secure=False
32
+ )
33
+ self._obj_store = ObjStore(self._minio_client)
34
+ self.working_path_root = working_path
35
+
36
+ def search_resource_file(self, resource_filename: str | None, working_path: str, morph_type: str) -> str | None:
37
+ found_filename = None
38
+ if resource_filename:
39
+ search_path = os.path.join(working_path, "**")
40
+ search_pattern = os.path.join(search_path, resource_filename)
41
+ files = glob.glob(search_pattern, recursive=True)
42
+ if len(files) > 0:
43
+ found_filename = files[0]
44
+
45
+ if found_filename is None:
46
+ for ext in ASSET_TYPE_TO_EXTENSIONS[morph_type]:
47
+ search_pattern = os.path.join(working_path, "**", f"*.{ext}")
48
+ files = glob.glob(search_pattern, recursive=True)
49
+ if len(files) > 0:
50
+ found_filename = files[0]
51
+ break
52
+ return found_filename
53
+
54
+ def _save_file(self, filepath: str, data: bytes) -> str:
55
+ os.makedirs(os.path.dirname(filepath), exist_ok=True)
56
+ with open(filepath, "wb") as f:
57
+ f.write(data)
58
+ return filepath
59
+
60
+ def _save_and_extract(self, working_path: str, local_filepath: str, file_content: bytes, file_type: str):
61
+ os.makedirs(working_path, exist_ok=True)
62
+ saved_filepath = self._save_file(local_filepath, file_content)
63
+ _, ext = os.path.splitext(saved_filepath)
64
+ ext = ext.lstrip('.') # Remove leading dot
65
+ if ext not in ASSET_TYPE_TO_EXTENSIONS[file_type]:
66
+ extract_archive(saved_filepath, working_path)
67
+ try:
68
+ os.remove(saved_filepath)
69
+ except Exception as e:
70
+ print(f"Error removing saved file {saved_filepath}: {e}")
71
+
72
+ def save_file(self,
73
+ resource_name: str,
74
+ resource_version: int,
75
+ object_type: ObjectType,
76
+ file_content: bytes,
77
+ file_url: str,
78
+ resource_type: str,
79
+ filename: str | None = None) -> str:
80
+ working_path = self.get_working_path(object_type, resource_name, resource_version)
81
+ local_filepath = os.path.join(working_path, os.path.basename(file_url))
82
+ local_filename = None
83
+ if os.path.exists(os.path.dirname(working_path)):
84
+ # if directory exists, try to search for the file
85
+ local_filename = self.search_resource_file(filename, working_path, resource_type)
86
+ if local_filename is None:
87
+ # if not found, save the file and extract the archive,
88
+ # then search for the file again
89
+ self._save_and_extract(working_path, local_filepath, file_content, resource_type)
90
+ local_filename = self.search_resource_file(filename, working_path, resource_type)
91
+ if local_filename is None:
92
+ # if still not found, raise an error
93
+ raise ValueError(f"Resource filename {filename} not found in {working_path}")
94
+ return local_filename
95
+
96
+ def get_working_path(self, obj_type: ObjectType, uuid: str, version: int) -> str:
97
+ return os.path.join(self.working_path_root, "humalab", obj_type.value, uuid + "_" + str(version))
98
+
99
+ def query_and_download_resource(self, resource_name: str, resource_version: int | None = None) -> tuple[str, str]:
100
+ """ Query the resource from the database and download it from the object store.
101
+ Args:
102
+ resource_name (str): The name of the resource.
103
+ resource_version (int | None): The version of the resource. If None, the latest version will be used.
104
+ Returns:
105
+ tuple[str, str]: A tuple containing the local filename of the resource and the working directory
106
+ where the resource was downloaded and extracted.
107
+ """
108
+ me.connect("humalab", host=f"mongodb://{HumaLabHost.get_mongodb_service_address()}")
109
+ if resource_version is None:
110
+ resource = ResourceDocument.objects(name=resource_name.strip(), latest=True).first()
111
+ else:
112
+ resource = ResourceDocument.objects(name=resource_name.strip(), version=resource_version).first()
113
+ if resource is None:
114
+ raise ValueError(f"Resource {resource_name}:{resource_version} not found")
115
+ return self.download_resource(resource.name, resource.version, resource.file_url, resource.resource_type.value, resource.filename)
116
+
117
+ def download_resource(self,
118
+ resource_name: str,
119
+ resource_version: int,
120
+ resource_url: str,
121
+ resource_type: str,
122
+ resource_filename: str | None = None) -> tuple[str, str]:
123
+ """ Download a resource from the object store.
124
+ Args:
125
+ resource_name (str): The name of the resource.
126
+ resource_version (int): The version of the resource.
127
+ resource_url (str): The URL of the resource in the object store.
128
+ resource_type (str): The type of the resource (e.g., "urdf", "mjcf", "mesh", etc.).
129
+ resource_filename (str | None): The specific filename to search for within the resource directory. If None, the first file found will be used.
130
+ Returns:
131
+ tuple[str, str]: A tuple containing the local filename of the resource and the working directory
132
+ where the resource was downloaded and extracted.
133
+ """
134
+ return self._download_resource(resource_name,
135
+ resource_version,
136
+ ObjectType.RESOURCE,
137
+ resource_url,
138
+ resource_type,
139
+ resource_filename)
140
+
141
+ def _download_resource(self,
142
+ resource_name: str,
143
+ resource_version: int,
144
+ object_type: ObjectType,
145
+ resource_url: str,
146
+ resource_type: str,
147
+ resource_filename: str | None = None) -> tuple[str, str]:
148
+ """
149
+ Download an asset from the object store and extract it if necessary.
150
+
151
+ Args:
152
+ asset_uuid (str): The UUID of the asset.
153
+ asset_version (int): The version of the asset.
154
+ asset_type (ObjectType): The type of the asset (e.g., URDF, MJCF, Mesh, etc.).
155
+ asset_url (str): The URL of the asset in the object store.
156
+ asset_file_type (str): The type of the asset file (e.g., "urdf", "mjcf", "mesh", etc.).
157
+ asset_filename (str | None): The specific filename to search for within the asset directory. If None, the first file found will be used.
158
+
159
+ Returns:
160
+ tuple[str, str]: A tuple containing the local filename of the asset and the working directory
161
+ where the asset was downloaded and extracted.
162
+ """
163
+ working_path = self.get_working_path(object_type, resource_name, resource_version)
164
+ local_filepath = os.path.join(working_path, os.path.basename(resource_url))
165
+ if not os.path.exists(working_path):
166
+ os.makedirs(working_path, exist_ok=True)
167
+ self._obj_store.download_file(object_type, resource_url, local_filepath)
168
+ _, ext = os.path.splitext(resource_url)
169
+ ext = ext.lower().lstrip('.')
170
+ if ext not in ASSET_TYPE_TO_EXTENSIONS[resource_type]:
171
+ extract_archive(local_filepath, working_path)
172
+ local_filename = self.search_resource_file(resource_filename, working_path, resource_type)
173
+ if local_filename is None:
174
+ raise ValueError(f"Resource filename {resource_filename} not found in {working_path}")
175
+ return local_filename, working_path
@@ -0,0 +1,7 @@
1
+ from enum import Enum
2
+
3
+ class EpisodeStatus(Enum):
4
+ PASS = "pass"
5
+ FAILED = "failed"
6
+ CANCELED = "canceled"
7
+ ERROR = "error"
@@ -0,0 +1,17 @@
1
+ from .bernoulli import Bernoulli
2
+ from .categorical import Categorical
3
+ from .discrete import Discrete
4
+ from .gaussian import Gaussian
5
+ from .log_uniform import LogUniform
6
+ from .truncated_gaussian import TruncatedGaussian
7
+ from .uniform import Uniform
8
+
9
+ __all__ = [
10
+ "Bernoulli",
11
+ "Categorical",
12
+ "Discrete",
13
+ "LogUniform",
14
+ "Gaussian",
15
+ "TruncatedGaussian",
16
+ "Uniform",
17
+ ]
@@ -0,0 +1,44 @@
1
+ from humalab_sdk.dists.distribution import Distribution
2
+
3
+ from typing import Any
4
+ import numpy as np
5
+
6
+ class Bernoulli(Distribution):
7
+ def __init__(self,
8
+ generator: np.random.Generator,
9
+ p: float | Any,
10
+ size: int | tuple[int, ...] | None = None) -> None:
11
+ """
12
+ Initialize the Bernoulli distribution.
13
+
14
+ Args:
15
+ generator (np.random.Generator): The random number generator.
16
+ p (float | Any): The probability of success.
17
+ size (int | tuple[int, ...] | None): The size of the output.
18
+ """
19
+ super().__init__(generator=generator)
20
+ self._p = p
21
+ self._size = size
22
+
23
+ def _sample(self) -> int | float | np.ndarray:
24
+ return self._generator.binomial(n=1, p=self._p, size=self._size)
25
+
26
+ def __repr__(self) -> str:
27
+ return f"Bernoulli(p={self._p}, size={self._size})"
28
+
29
+ @staticmethod
30
+ def create(generator: np.random.Generator,
31
+ p: float | Any,
32
+ size: int | tuple[int, ...] | None = None) -> 'Bernoulli':
33
+ """
34
+ Create a Bernoulli distribution.
35
+
36
+ Args:
37
+ generator (np.random.Generator): The random number generator.
38
+ p (float | Any): The probability of success.
39
+ size (int | tuple[int, ...] | None): The size of the output.
40
+
41
+ Returns:
42
+ Bernoulli: The created Bernoulli distribution.
43
+ """
44
+ return Bernoulli(generator=generator, p=p, size=size)