Assets lazy loading
Lazy download of large asset files from a public S3 bucket.
Most asset files (configs, poses, and the simplified default NeuroMechFly meshes)
are small enough to ship inside the flygym package. The high-resolution
fullsize meshes -- especially the FlyBody .obj meshes, which are an order
of magnitude larger than everything else combined -- would bloat the package and
the git repository, so they are hosted on an institution-managed S3 bucket and
pulled in the first time they are needed, similar to how PyTorch downloads
pretrained weights.
Downloaded files are cached on disk (see :func:get_cache_root) so the download
happens only once per machine. The bucket is public and served over a standard
S3-compatible HTTP endpoint, so plain urllib is enough -- no extra
dependencies (boto3 etc.) are required.
The bucket stores each remotely hosted asset directory as a flat, versioned
sub-prefix of :data:S3_ROOT_PREFIX, so future revisions can be uploaded under a
new name without disturbing existing releases. Bump the version constants below to
point a release at a new version. Example:
bucket: flygym_assets/neuromechfly_fullsize_meshes_20260623a/<file>
cache: ~/.cache/flygym_assets/neuromechfly_fullsize_meshes_20260623a/<file>
get_cache_root()
¶
Return the directory under which downloaded assets are cached.
Resolution order:
$FLYGYM_ASSET_CACHE_DIRif set (useful for CI caching or shared, read-only installs);$XDG_CACHE_HOME/flygym_assetsifXDG_CACHE_HOMEis set;~/.cache/flygym_assetsotherwise.
The directory is named flygym_assets to match the bucket's top-level
prefix (:data:S3_ROOT_PREFIX).
Source code in src/flygym/utils/assets_lazy_loading.py
lazy_load_asset_dir(rel_path)
¶
Return the absolute local path to a bucket asset directory, downloading it from S3 on first use.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rel_path
|
PathLike | str
|
Path of the directory within the bucket, relative to
:data: |
required |
The directory is cached under :func:get_cache_root keyed by rel_path. If
the cached copy already exists it is returned as-is (no network access);
otherwise the whole directory is downloaded into a temporary location and moved
into place atomically, so an interrupted or concurrent download never leaves a
partial cache.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If |
Source code in src/flygym/utils/assets_lazy_loading.py
prefetch_meshes()
¶
Eagerly download all remotely hosted meshes into the cache.
Useful for warming a CI cache or preparing an offline environment. Returns the list of local directories that now hold the assets.