molmospaces-resources 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.
Files changed (24) hide show
  1. molmospaces_resources-0.0.1/LICENSE +201 -0
  2. molmospaces_resources-0.0.1/PKG-INFO +139 -0
  3. molmospaces_resources-0.0.1/README.md +119 -0
  4. molmospaces_resources-0.0.1/molmospaces_resources/__init__.py +12 -0
  5. molmospaces_resources-0.0.1/molmospaces_resources/behaviors.py +114 -0
  6. molmospaces_resources-0.0.1/molmospaces_resources/compact_trie.py +108 -0
  7. molmospaces_resources-0.0.1/molmospaces_resources/constants.py +5 -0
  8. molmospaces_resources-0.0.1/molmospaces_resources/file_utils.py +64 -0
  9. molmospaces_resources-0.0.1/molmospaces_resources/indexing.py +125 -0
  10. molmospaces_resources-0.0.1/molmospaces_resources/lmdb_data.py +180 -0
  11. molmospaces_resources-0.0.1/molmospaces_resources/manager.py +766 -0
  12. molmospaces_resources-0.0.1/molmospaces_resources/remote_storage.py +202 -0
  13. molmospaces_resources-0.0.1/molmospaces_resources/scripts/__init__.py +0 -0
  14. molmospaces_resources-0.0.1/molmospaces_resources/scripts/toyblocks_downloader.py +167 -0
  15. molmospaces_resources-0.0.1/molmospaces_resources/setup_utils.py +143 -0
  16. molmospaces_resources-0.0.1/molmospaces_resources/threading_utils.py +140 -0
  17. molmospaces_resources-0.0.1/molmospaces_resources.egg-info/PKG-INFO +139 -0
  18. molmospaces_resources-0.0.1/molmospaces_resources.egg-info/SOURCES.txt +22 -0
  19. molmospaces_resources-0.0.1/molmospaces_resources.egg-info/dependency_links.txt +1 -0
  20. molmospaces_resources-0.0.1/molmospaces_resources.egg-info/entry_points.txt +4 -0
  21. molmospaces_resources-0.0.1/molmospaces_resources.egg-info/requires.txt +8 -0
  22. molmospaces_resources-0.0.1/molmospaces_resources.egg-info/top_level.txt +1 -0
  23. molmospaces_resources-0.0.1/pyproject.toml +30 -0
  24. molmospaces_resources-0.0.1/setup.cfg +4 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Allen Institute for AI (Ai2)
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.4
2
+ Name: molmospaces_resources
3
+ Version: 0.0.1
4
+ Summary: Resource manager for MolmoSpaces
5
+ Author: Allen Institute for AI (Ai2)
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/allenai/molmospaces-resources
8
+ Requires-Python: >=3.10
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: datasets
12
+ Requires-Dist: filelock
13
+ Requires-Dist: huggingface_hub
14
+ Requires-Dist: lmdb~=1.7.5
15
+ Requires-Dist: requests
16
+ Requires-Dist: tqdm>=4.65.0
17
+ Requires-Dist: tyro
18
+ Requires-Dist: zstandard~=0.25.0
19
+ Dynamic: license-file
20
+
21
+ # <img src="https://raw.githubusercontent.com/allenai/molmospaces-resources/main/molmospaces_resources/images/ai2_logo.png" width=22> MolmoSpaces-resources
22
+
23
+ Resource manager for [MolmoSpaces](https://github.com/allenai/molmospaces). Downloads, caches, and symlinks versioned data archives from remote buckets.
24
+
25
+ - Versioned, read-only download cache with symlink-based install directories
26
+ - Eager or on-demand archive extraction with parallel downloads
27
+ - Pluggable archive indexing for fast asset lookup
28
+ - Fork-resilient: safe to use across multiprocessing workers
29
+
30
+ ## Installation
31
+
32
+ ```bash
33
+ pip install molmospaces-resources
34
+ ```
35
+
36
+ ## Setup example
37
+
38
+ Data is assumed to be served from a gated Hugging Face dataset repo, so we typically need to pass a valid token:
39
+
40
+ ```python
41
+ import os
42
+ from molmospaces_resources import HFRemoteStorage, setup_resource_manager
43
+
44
+ source = HFRemoteStorage("allenai/molmospaces", repo_prefix="mujoco", token=os.environ["HF_TOKEN"])
45
+ mgr = setup_resource_manager(
46
+ source,
47
+ symlink_dir=SYMLINK_DIR,
48
+ versions=ASSETS_VERSIONS,
49
+ cache_dir=CACHE_DIR,
50
+ )
51
+ ```
52
+
53
+ Alternatively, we can use `R2RemoteStorage` for direct bucket access, including `"mujoco-thor-resources"`, `"isaac-thor-resources"`, and `"mujoco-thor-training-data"` (also available for Google Cloud Storage via `GCRemoteStorage` with `"molmospaces-isaac"`, `"molmospaces-mujoco"`, and `"molmobot-data"` buckets):
54
+
55
+ ```python
56
+ from molmospaces_resources import R2RemoteStorage, setup_resource_manager
57
+
58
+ source = R2RemoteStorage("mujoco-thor-resources") # known bucket name or full URL
59
+ mgr = setup_resource_manager(
60
+ source,
61
+ symlink_dir=SYMLINK_DIR,
62
+ versions=ASSETS_VERSIONS,
63
+ cache_dir=CACHE_DIR,
64
+ )
65
+ ```
66
+
67
+ Optionally, run project-specific logic after setup via `post_setup`:
68
+
69
+ ```python
70
+ def my_post_setup(manager):
71
+ ## Install all scenes (while skipping per-file symlinking):
72
+ # manager.install_all_for_data_type("scenes", skip_linking=True)
73
+
74
+ ## Install all objects (with per-dataset symlinking):
75
+ # manager.install_all_for_data_type("objects")
76
+ pass
77
+
78
+ mgr = setup_resource_manager(
79
+ source,
80
+ symlink_dir=SYMLINK_DIR,
81
+ versions=ASSETS_VERSIONS,
82
+ cache_dir=CACHE_DIR,
83
+ post_setup=my_post_setup,
84
+ force_post_setup=True, # run post_setup even if all data sources are configured
85
+ )
86
+ ```
87
+
88
+ ## Logging
89
+
90
+ By default, Python's logging shows `WARNING` and above, so the library will be quiet. To see detailed progress messages, either configure the root logger:
91
+
92
+ ```python
93
+ import logging
94
+ logging.basicConfig(level=logging.DEBUG)
95
+ ```
96
+
97
+ or set the `molmospaces_resources` logger level explicitly:
98
+
99
+ ```python
100
+ import logging
101
+ logger = logging.getLogger("molmospaces_resources")
102
+ logger.setLevel(logging.DEBUG)
103
+ if not logger.handlers:
104
+ logger.addHandler(logging.StreamHandler())
105
+ ```
106
+
107
+ ## FAQ
108
+
109
+ **FAQ 0\. I'm getting hard to parse errors when using the ResourceManager and I cannot resolve the issue by just erasing the involved subdirectories and the corresponding entries in the installed data manifests (`mjthor_data_type_to_source_to_versions.json`) under both install and cache dirs.**
110
+
111
+ Chances are it might be easiest to just fully erase both cache and symlink dirs (see the differences between both below) and then start populating new cache and symlink dirs by just setting up the resource manager with the desired data sources and versions (e.g. as described above). Note that some data sources, like thor objects or robots, will get fully extracted during the initial setup, which takes longer than usual to complete.
112
+
113
+ **FAQ 1\. What is the difference between `cache_dir` and `symlink_dir`?**
114
+
115
+ The resource manager uses two separate directory trees that must not overlap:
116
+
117
+ - **`cache_dir`** is the versioned download cache. Archives are extracted into a `<data_type>/<source>/<version>/` hierarchy, and multiple versions can coexist side by side. Files here are set read-only to prevent accidental modification. This directory can be safely shared across containers or workers.
118
+
119
+ - **`symlink_dir`** is the user-facing install directory. It presents a flat `<data_type>/<source>/` layout with no version in the path — the version is hidden behind symlinks that point into `cache_dir`. This allows application code to use stable, version-agnostic paths while the underlying data can be upgraded by simply re-pointing the symlinks.
120
+
121
+ These two directories **must resolve to different physical locations** and neither can be nested inside the other. The manager validates this at construction time and raises an error if the paths overlap.
122
+
123
+ **FAQ 2\. A process hangs waiting for a lock on a shared filesystem (e.g. WekaFS, NFS).**
124
+
125
+ The resource manager uses file-based locks (`.lock` files) to coordinate concurrent access to the cache and symlink directories. On local filesystems, the OS automatically releases these locks when a process dies. On shared/networked filesystems like WekaFS or NFS, if a container is destroyed without a clean shutdown (e.g. killed by the orchestrator, node crash), the lock may not be released immediately. The filesystem will typically detect the dead client eventually, but this can take a varying amount of time.
126
+
127
+ If setup appears stuck, you can manually remove the stale lock file (typically in the shared cache directory):
128
+
129
+ ```bash
130
+ rm /path/to/cache_dir/.lock
131
+ ```
132
+
133
+ If the interrupted process was mid-install, the cache may contain partially extracted archives. The safest recovery is to delete the entire affected `<data_type>/<source>/<version>/` directory under `cache_dir`, remove the corresponding entry from the local manifest files, and re-run setup. Partial cleanup (e.g. removing individual archives) is possible but requires checking the `.complete_extract` / `.complete_links` flag files as well.
134
+
135
+ In shared-cache scenarios with sufficient storage, we recommend installing all data eagerly with a single leader process and letting workers use the pre-populated cache without locks via `cache_lock=False`.
136
+
137
+ ## License
138
+
139
+ Apache 2.0 — see [LICENSE](LICENSE) for details.
@@ -0,0 +1,119 @@
1
+ # <img src="https://raw.githubusercontent.com/allenai/molmospaces-resources/main/molmospaces_resources/images/ai2_logo.png" width=22> MolmoSpaces-resources
2
+
3
+ Resource manager for [MolmoSpaces](https://github.com/allenai/molmospaces). Downloads, caches, and symlinks versioned data archives from remote buckets.
4
+
5
+ - Versioned, read-only download cache with symlink-based install directories
6
+ - Eager or on-demand archive extraction with parallel downloads
7
+ - Pluggable archive indexing for fast asset lookup
8
+ - Fork-resilient: safe to use across multiprocessing workers
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pip install molmospaces-resources
14
+ ```
15
+
16
+ ## Setup example
17
+
18
+ Data is assumed to be served from a gated Hugging Face dataset repo, so we typically need to pass a valid token:
19
+
20
+ ```python
21
+ import os
22
+ from molmospaces_resources import HFRemoteStorage, setup_resource_manager
23
+
24
+ source = HFRemoteStorage("allenai/molmospaces", repo_prefix="mujoco", token=os.environ["HF_TOKEN"])
25
+ mgr = setup_resource_manager(
26
+ source,
27
+ symlink_dir=SYMLINK_DIR,
28
+ versions=ASSETS_VERSIONS,
29
+ cache_dir=CACHE_DIR,
30
+ )
31
+ ```
32
+
33
+ Alternatively, we can use `R2RemoteStorage` for direct bucket access, including `"mujoco-thor-resources"`, `"isaac-thor-resources"`, and `"mujoco-thor-training-data"` (also available for Google Cloud Storage via `GCRemoteStorage` with `"molmospaces-isaac"`, `"molmospaces-mujoco"`, and `"molmobot-data"` buckets):
34
+
35
+ ```python
36
+ from molmospaces_resources import R2RemoteStorage, setup_resource_manager
37
+
38
+ source = R2RemoteStorage("mujoco-thor-resources") # known bucket name or full URL
39
+ mgr = setup_resource_manager(
40
+ source,
41
+ symlink_dir=SYMLINK_DIR,
42
+ versions=ASSETS_VERSIONS,
43
+ cache_dir=CACHE_DIR,
44
+ )
45
+ ```
46
+
47
+ Optionally, run project-specific logic after setup via `post_setup`:
48
+
49
+ ```python
50
+ def my_post_setup(manager):
51
+ ## Install all scenes (while skipping per-file symlinking):
52
+ # manager.install_all_for_data_type("scenes", skip_linking=True)
53
+
54
+ ## Install all objects (with per-dataset symlinking):
55
+ # manager.install_all_for_data_type("objects")
56
+ pass
57
+
58
+ mgr = setup_resource_manager(
59
+ source,
60
+ symlink_dir=SYMLINK_DIR,
61
+ versions=ASSETS_VERSIONS,
62
+ cache_dir=CACHE_DIR,
63
+ post_setup=my_post_setup,
64
+ force_post_setup=True, # run post_setup even if all data sources are configured
65
+ )
66
+ ```
67
+
68
+ ## Logging
69
+
70
+ By default, Python's logging shows `WARNING` and above, so the library will be quiet. To see detailed progress messages, either configure the root logger:
71
+
72
+ ```python
73
+ import logging
74
+ logging.basicConfig(level=logging.DEBUG)
75
+ ```
76
+
77
+ or set the `molmospaces_resources` logger level explicitly:
78
+
79
+ ```python
80
+ import logging
81
+ logger = logging.getLogger("molmospaces_resources")
82
+ logger.setLevel(logging.DEBUG)
83
+ if not logger.handlers:
84
+ logger.addHandler(logging.StreamHandler())
85
+ ```
86
+
87
+ ## FAQ
88
+
89
+ **FAQ 0\. I'm getting hard to parse errors when using the ResourceManager and I cannot resolve the issue by just erasing the involved subdirectories and the corresponding entries in the installed data manifests (`mjthor_data_type_to_source_to_versions.json`) under both install and cache dirs.**
90
+
91
+ Chances are it might be easiest to just fully erase both cache and symlink dirs (see the differences between both below) and then start populating new cache and symlink dirs by just setting up the resource manager with the desired data sources and versions (e.g. as described above). Note that some data sources, like thor objects or robots, will get fully extracted during the initial setup, which takes longer than usual to complete.
92
+
93
+ **FAQ 1\. What is the difference between `cache_dir` and `symlink_dir`?**
94
+
95
+ The resource manager uses two separate directory trees that must not overlap:
96
+
97
+ - **`cache_dir`** is the versioned download cache. Archives are extracted into a `<data_type>/<source>/<version>/` hierarchy, and multiple versions can coexist side by side. Files here are set read-only to prevent accidental modification. This directory can be safely shared across containers or workers.
98
+
99
+ - **`symlink_dir`** is the user-facing install directory. It presents a flat `<data_type>/<source>/` layout with no version in the path — the version is hidden behind symlinks that point into `cache_dir`. This allows application code to use stable, version-agnostic paths while the underlying data can be upgraded by simply re-pointing the symlinks.
100
+
101
+ These two directories **must resolve to different physical locations** and neither can be nested inside the other. The manager validates this at construction time and raises an error if the paths overlap.
102
+
103
+ **FAQ 2\. A process hangs waiting for a lock on a shared filesystem (e.g. WekaFS, NFS).**
104
+
105
+ The resource manager uses file-based locks (`.lock` files) to coordinate concurrent access to the cache and symlink directories. On local filesystems, the OS automatically releases these locks when a process dies. On shared/networked filesystems like WekaFS or NFS, if a container is destroyed without a clean shutdown (e.g. killed by the orchestrator, node crash), the lock may not be released immediately. The filesystem will typically detect the dead client eventually, but this can take a varying amount of time.
106
+
107
+ If setup appears stuck, you can manually remove the stale lock file (typically in the shared cache directory):
108
+
109
+ ```bash
110
+ rm /path/to/cache_dir/.lock
111
+ ```
112
+
113
+ If the interrupted process was mid-install, the cache may contain partially extracted archives. The safest recovery is to delete the entire affected `<data_type>/<source>/<version>/` directory under `cache_dir`, remove the corresponding entry from the local manifest files, and re-run setup. Partial cleanup (e.g. removing individual archives) is possible but requires checking the `.complete_extract` / `.complete_links` flag files as well.
114
+
115
+ In shared-cache scenarios with sufficient storage, we recommend installing all data eagerly with a single leader process and letting workers use the pre-populated cache without locks via `cache_lock=False`.
116
+
117
+ ## License
118
+
119
+ Apache 2.0 — see [LICENSE](LICENSE) for details.
@@ -0,0 +1,12 @@
1
+ from molmospaces_resources.manager import ResourceManager, SourceInfo
2
+ from molmospaces_resources.setup_utils import setup_resource_manager, str2bool
3
+ from molmospaces_resources.compact_trie import CompactPathTrie
4
+ from molmospaces_resources.remote_storage import (
5
+ RemoteStorage,
6
+ R2RemoteStorage,
7
+ HFRemoteStorage,
8
+ GCRemoteStorage,
9
+ )
10
+ from molmospaces_resources.lmdb_data import GenericLMDBMap, JSonLMDBMap, PickleLMDBMap
11
+ from molmospaces_resources.constants import LOCAL_MANIFEST_NAME, COMBINED_TRIES_NAME
12
+ from molmospaces_resources.indexing import split_query_tokens
@@ -0,0 +1,114 @@
1
+ from __future__ import annotations
2
+
3
+ import dataclasses
4
+ from dataclasses import dataclass
5
+ from enum import Enum
6
+ from typing import Any
7
+
8
+ from molmospaces_resources.indexing import ArchiveIndex, NumericIndex, SubstringIndex
9
+
10
+
11
+ class LinkStrategy(Enum):
12
+ """How a source is exposed under ``symlink_dir``.
13
+
14
+ **Why two strategies?**
15
+
16
+ Scene XML files contain relative paths to sibling directories
17
+ (e.g. ``../objects/thor/Bowl.xml``). MuJoCo's XML loader resolves
18
+ these relative to the *physical* file location, following symlinks.
19
+ If scenes used a ``GLOBAL`` directory symlink, the physical location
20
+ would be deep inside ``cache_dir``, and ``../objects/`` would resolve
21
+ to a nonexistent cache path instead of ``symlink_dir/objects/``.
22
+
23
+ ``PER_FILE`` avoids this: each scene file is an individual symlink
24
+ *inside* a real directory under ``symlink_dir``, so relative paths
25
+ resolve within the symlink tree where sibling data types are visible.
26
+
27
+ Data types that are leaf data (objects, grasps, etc.) don't reference
28
+ siblings via relative paths, so a single ``GLOBAL`` directory symlink
29
+ is safe and simpler.
30
+ """
31
+
32
+ PER_FILE = "per_file"
33
+ """Real directory with individual file symlinks into the cache."""
34
+
35
+ GLOBAL = "global"
36
+ """Single directory-level symlink pointing at the versioned cache dir."""
37
+
38
+
39
+ class InstallMode(Enum):
40
+ """When archive contents are extracted."""
41
+
42
+ EAGER = "eager"
43
+ """Extract all archives at setup time."""
44
+
45
+ ON_DEMAND = "on_demand"
46
+ """Only fetch manifests at setup; extract archives on first use."""
47
+
48
+
49
+ @dataclass
50
+ class SourceBehavior:
51
+ """Per-source behaviour configuration.
52
+
53
+ ``archive_index`` may be a *class* (instantiated per source in
54
+ ``_resolve_behavior``) or an *instance* (used as-is). Storing the
55
+ class in ``DATA_TYPE_DEFAULTS`` ensures each source gets its own
56
+ index instance with independent ``build()`` state.
57
+ """
58
+
59
+ link_strategy: LinkStrategy
60
+ install_mode: InstallMode
61
+ archive_index: type | ArchiveIndex | None = None
62
+
63
+
64
+ DATA_TYPE_DEFAULTS: dict[str, SourceBehavior] = {
65
+ "robots": SourceBehavior(LinkStrategy.PER_FILE, InstallMode.EAGER),
66
+ "scenes": SourceBehavior(
67
+ LinkStrategy.PER_FILE, InstallMode.ON_DEMAND, NumericIndex
68
+ ),
69
+ "objects": SourceBehavior(
70
+ LinkStrategy.GLOBAL, InstallMode.ON_DEMAND, SubstringIndex
71
+ ),
72
+ "grasps": SourceBehavior(
73
+ LinkStrategy.GLOBAL, InstallMode.ON_DEMAND, SubstringIndex
74
+ ),
75
+ "test_data": SourceBehavior(LinkStrategy.GLOBAL, InstallMode.EAGER),
76
+ "benchmarks": SourceBehavior(LinkStrategy.GLOBAL, InstallMode.EAGER),
77
+ "franka-rby1-training-data": SourceBehavior(
78
+ LinkStrategy.GLOBAL, InstallMode.ON_DEMAND, NumericIndex
79
+ ),
80
+ }
81
+
82
+ SOURCE_OVERRIDES: dict[tuple[str, str], dict[str, Any]] = {
83
+ ("objects", "thor"): {"install_mode": InstallMode.EAGER},
84
+ ("objects", "objathor_metadata"): {"install_mode": InstallMode.EAGER},
85
+ ("grasps", "droid"): {"install_mode": InstallMode.EAGER},
86
+ ("grasps", "rum"): {"install_mode": InstallMode.EAGER},
87
+ }
88
+
89
+
90
+ def _resolve_behavior(
91
+ data_type: str,
92
+ source: str,
93
+ defaults: dict[str, SourceBehavior],
94
+ overrides: dict[tuple[str, str], dict[str, Any]],
95
+ ) -> SourceBehavior:
96
+ """Return the effective ``SourceBehavior`` for *(data_type, source)*.
97
+
98
+ If ``archive_index`` is a class (type), it is instantiated so each
99
+ source gets its own index with independent ``build()`` state.
100
+ Instantiation happens *after* applying overrides, so an override can
101
+ replace the index class/instance.
102
+ """
103
+ base = defaults.get(data_type)
104
+ if base is None:
105
+ raise ValueError(
106
+ f"No default SourceBehavior for data_type={data_type!r}. "
107
+ f"Known types: {sorted(defaults)}"
108
+ )
109
+ patch = overrides.get((data_type, source))
110
+ result = dataclasses.replace(base, **patch) if patch else base
111
+ # Instantiate if archive_index is a class rather than an instance
112
+ if isinstance(result.archive_index, type):
113
+ result = dataclasses.replace(result, archive_index=result.archive_index())
114
+ return result