Skip to content

Add lightweight realization helpers and serialization options#18

Merged
bryce-wedig merged 6 commits into
mainfrom
collapse-romanisim-step-dir
Jul 22, 2026
Merged

Add lightweight realization helpers and serialization options#18
bryce-wedig merged 6 commits into
mainfrom
collapse-romanisim-step-dir

Conversation

@bryce-wedig

Copy link
Copy Markdown
Collaborator

This pull request introduces a new "lightweight" serialization mode for subhalo realizations, significantly reducing the disk space required for storing lensing simulation outputs by stripping the large pyHalo realization object after its information is baked into the lens model. The changes add support for this mode across the pipeline, including configuration, realization generation, CSV export, and a one-off script to compact existing outputs. The implementation ensures that essential metadata (the substructure flag) is preserved and that downstream steps remain compatible.

The most important changes are:

Serialization and Disk Usage Improvements:

  • Added a serialization option (full or lightweight) to all relevant survey configuration YAML files, allowing users to choose whether to keep or strip the heavy pyHalo realization object in step 03 pickles. The "lightweight" mode reduces file size by ~76%. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

  • Updated _03_generate_subhalos.py to respect the new serialization config, invoking the new strip_realization function after adding the realization if "lightweight" is selected. This function drops the heavy realization and preserves the substructure flag. [1] [2] [3]

  • Added strip_realization and substructure_flag utilities to lensing.py for stripping the realization and reliably extracting the substructure model abbreviation, ensuring metadata is retained.

Pipeline and Data Management:

  • Added compact_03_realizations.py, a stand-alone, atomic script to retroactively strip realizations from existing step 03 pickles, making them lightweight without re-running pyHalo. This script is idempotent and safe to run at any point.

Downstream Compatibility and Metadata Handling:

  • Updated make_substructure_csv.py to read the substructure flag from the new location when using lightweight serialization, ensuring CSV exports remain correct and compatible regardless of serialization mode.

Other Minor Changes:

  • Cleaned up unused imports and ensured consistent handling of the substructure flag throughout the pipeline. [1] [2] [3]

These changes together enable much more efficient storage and handling of large lensing simulation datasets, while preserving all necessary metadata for downstream analysis.

Add substructure_flag() to derive the model abbreviation (CDM/WDM/...)
from a pyHalo realization, and strip_realization() to drop the ~59 MB
realization object from a StrongLens for lightweight serialization,
recording the substructure flag and leaving a truthy sentinel so
has_realization semantics still hold.
Add a subhalos.serialization config key ('full' or 'lightweight') to
every config. In lightweight mode, step 03 strips the pyHalo realization
object from each subhalo'd pickle (~76% smaller) since step 04
ray-shoots from the baked-in kwargs_lens, not the realization.
make_substructure_csv reads the flag stored at strip time when the
realization is gone, else derives it via lensing.substructure_flag. The
roman_data_challenge configs opt into lightweight; the rest keep full.
The pipeline test is parametrized over both modes.
Rewrite already-written full step-03 pickles the way lightweight
serialization would have, without re-running pyHalo. Resumable,
idempotent (skips None / already-stripped pickles), and atomic (writes
to .tmp and os.replace-s into place). Safe to run whether or not step 04
has consumed the output.
Cover substructure_flag derivation, strip_realization preserving the
lensing inputs while shrinking the pickle, the sentinel round-trip and
its agreement with LightweightStrongLens, image positions unchanged
after stripping, and the compact_03_realizations round-trip.
Relocate the rung-1 subhalo script (byte-identical) from the shared
pipeline directory to the project it belongs to.
@bryce-wedig
bryce-wedig merged commit 70a0ab4 into main Jul 22, 2026
1 check passed
@bryce-wedig
bryce-wedig deleted the collapse-romanisim-step-dir branch July 22, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant