humalab 0.0.3__py3-none-any.whl → 0.0.5__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.
- humalab/assets/__init__.py +4 -0
- humalab/assets/files/__init__.py +4 -0
- humalab/assets/files/resource_file.py +41 -0
- humalab/assets/files/urdf_file.py +65 -0
- humalab/assets/resource_manager.py +58 -0
- humalab/dists/bernoulli.py +15 -0
- humalab/dists/categorical.py +7 -0
- humalab/dists/discrete.py +22 -0
- humalab/dists/gaussian.py +22 -0
- humalab/dists/log_uniform.py +22 -0
- humalab/dists/truncated_gaussian.py +36 -0
- humalab/dists/uniform.py +22 -0
- humalab/episode.py +26 -0
- humalab/evaluators/__init__.py +16 -0
- humalab/humalab.py +80 -65
- humalab/humalab_api_client.py +540 -49
- humalab/humalab_config.py +0 -13
- humalab/humalab_main.py +119 -0
- humalab/humalab_test.py +0 -12
- humalab/run.py +0 -12
- humalab/scenario.py +172 -16
- {humalab-0.0.3.dist-info → humalab-0.0.5.dist-info}/METADATA +1 -1
- humalab-0.0.5.dist-info/RECORD +37 -0
- humalab/assets/resource_file.py +0 -28
- humalab/assets/resource_handler.py +0 -175
- humalab-0.0.3.dist-info/RECORD +0 -32
- {humalab-0.0.3.dist-info → humalab-0.0.5.dist-info}/WHEEL +0 -0
- {humalab-0.0.3.dist-info → humalab-0.0.5.dist-info}/entry_points.txt +0 -0
- {humalab-0.0.3.dist-info → humalab-0.0.5.dist-info}/licenses/LICENSE +0 -0
- {humalab-0.0.3.dist-info → humalab-0.0.5.dist-info}/top_level.txt +0 -0
|
@@ -1,175 +0,0 @@
|
|
|
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.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
|
humalab-0.0.3.dist-info/RECORD
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
humalab/__init__.py,sha256=LIL4eEPT_Boiond6pZegbAPvZwNX-ZWHHMVPkv3ehcU,140
|
|
2
|
-
humalab/constants.py,sha256=YSiUI7R7g0gkImD6ezufRlOMdIBS5wJ--dLy11Qb2qY,135
|
|
3
|
-
humalab/humalab.py,sha256=8FE6YpoiSMb2I_8RzwvPU-p30_JqrAG7WuKDOQWLGls,5588
|
|
4
|
-
humalab/humalab_api_client.py,sha256=V1PSe1pVngfBUJgxWW-lJzrM1ElQH2ZIolHiDieXlec,8806
|
|
5
|
-
humalab/humalab_config.py,sha256=CdjPgZFGYmmeYq5qsL84ZN8tGdoRP2TjaqS3wojKejg,2698
|
|
6
|
-
humalab/humalab_test.py,sha256=X07HDp9JLllGMuJ2kYxs4WB1o1r1VErn30AAvmn4zuM,19005
|
|
7
|
-
humalab/run.py,sha256=QloVqoZAWlBL5eYVCOqdIRWsjaUoY9BVQvd1BvNEgmY,7841
|
|
8
|
-
humalab/scenario.py,sha256=Zc9ymN5VI-cSnXhX7KYQOM62FCCm8GeAYSyUiUBZl_8,8275
|
|
9
|
-
humalab/scenario_test.py,sha256=9AyDj_l_43bO_ovhzhIvADTh4bAkq8YaMnPQ_sRPTog,28604
|
|
10
|
-
humalab/assets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
humalab/assets/archive.py,sha256=PALZRnpNExDfXiURVNEj6xxWqcW4nd9UBZ7QIHa8mI8,3119
|
|
12
|
-
humalab/assets/resource_file.py,sha256=u-1VhnO9xG5I8BtxNWalPjrCAAOISty-No0-HtKMilU,630
|
|
13
|
-
humalab/assets/resource_handler.py,sha256=A1fOLBJRzsU7l4Sum4u_Xa8f8uSTVNKyHifFF5WGz5Y,8733
|
|
14
|
-
humalab/dists/__init__.py,sha256=Q7zQbFGC_CnTgExMcnRtJdqJitqy1oBk4D6Qyvunlqc,387
|
|
15
|
-
humalab/dists/bernoulli.py,sha256=6JdeuEPdoL2hVwcP94anmTbIDk_TsSeUctooCzugQag,1500
|
|
16
|
-
humalab/dists/categorical.py,sha256=V2xyw8w7oWBlB-uryxTlE_EsqGQUI-_G1_d9dhxreik,1861
|
|
17
|
-
humalab/dists/discrete.py,sha256=Yk-JebgGyBgmTrtibmaF5sJLIsdgsCSUwa8arO8XUHQ,2167
|
|
18
|
-
humalab/dists/distribution.py,sha256=t0qTUjS_N0adiy_j2fdf-NHSlRs1pr0swpnszizs04I,1048
|
|
19
|
-
humalab/dists/gaussian.py,sha256=ueGm8CLTj8cVxfU4fi5cQKZVnPRI6dBy_PLzUMqn2-A,1838
|
|
20
|
-
humalab/dists/log_uniform.py,sha256=TeQdZA3JJHh5ptqEvKNLoOgTxafiSkCfF7HIThULo3Y,1868
|
|
21
|
-
humalab/dists/truncated_gaussian.py,sha256=b7LP8O7l5fobdTutatkdGneA_FThurz7fnMpdX9csKs,2691
|
|
22
|
-
humalab/dists/uniform.py,sha256=BBPlL10EUMAbV7UWuktfGlUDEZhRrqHYKi1qY92j7pk,1793
|
|
23
|
-
humalab/metrics/__init__.py,sha256=e0PPkAMP5nW-kGfb67SjMMlgxK9Bkp7nQVD-JWoV-qw,246
|
|
24
|
-
humalab/metrics/dist_metric.py,sha256=C7IpdFolw-VpkTHv-HTAK63kafH-WUjRTLxbF7h4W7g,921
|
|
25
|
-
humalab/metrics/metric.py,sha256=W1mWQKEPVs9x257zzJvJQmAadRNnDqGAEU2BAq1skwM,4194
|
|
26
|
-
humalab/metrics/summary.py,sha256=CloYeVkYgZAiaeM2gS6V8_tABukTkxAFJt0mpfmpbLI,2255
|
|
27
|
-
humalab-0.0.3.dist-info/licenses/LICENSE,sha256=Gy0Nw_Z9pbrNSu-loW-PCDWJyrC8eWpIqqIGW-DFtp8,1064
|
|
28
|
-
humalab-0.0.3.dist-info/METADATA,sha256=Fzzn5WuqhYjxVF7cYOUlAxujVrfUOwrvu9JHc7Jdtm8,1704
|
|
29
|
-
humalab-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
30
|
-
humalab-0.0.3.dist-info/entry_points.txt,sha256=aY-hS7Kg8y5kGgYA14YmtTz5odBrgJIZ2fQMXAbVW_U,49
|
|
31
|
-
humalab-0.0.3.dist-info/top_level.txt,sha256=hp7XXBDE40hi9T3Jx6mPFc6wJbAMzektD5VWXlSCW6o,8
|
|
32
|
-
humalab-0.0.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|