How ml4gw/ml4gw works
1. What this repo is
- ml4gw is a PyTorch-based scientific library for gravitational-wave ML workflows, not an application server or standalone pipeline.
- Its architecture is organized around reusable building blocks for signal generation, preprocessing, dataset loading, and neural-network modules.
2. Core data flow
- Typical flow is: raw or simulated time-series data → signal-conditioning transforms → optional augmentation/rescaling → dataset wrappers → neural network models.
- A second major flow is waveform synthesis: astrophysical parameters → waveform generators → injected or standalone strain-like tensors used in training/evaluation.
3. Time-series transforms subsystem
- ml4gw/transforms is the main preprocessing layer.
- It contains operations for decimation, heterodyning, IIR filtering, integration, Pearson correlation, spectral estimation, spectrograms, Q-transforms, spline interpolation, scaling, SNR rescaling, and whitening.
- These modules are the main boundary between raw detector-like signals and model-ready tensors.
4. Waveform generation subsystem
- ml4gw/waveforms generates synthetic gravitational-wave signals.
- It splits into cbc (compact binary coalescence models such as TaylorF2, PhenomD, PhenomP) and adhoc (e.g. sine-Gaussian and ringdown-style signals).
- generator.py and conversion.py suggest a parameterization layer that converts physical parameters into waveform tensors.
5. Data loading subsystem
- ml4gw/dataloading provides training data adapters for different storage/streaming patterns.
- in_memory_dataset.py, hdf5_dataset.py, and chunked_dataset.py imply support for small local datasets, large on-disk datasets, and chunked access for scalable training.
- This is the main I/O boundary between persisted data and the model-training stack.
6. Neural network components
- ml4gw/nn contains reusable model components rather than a single end-to-end model.
- Subpackages include resnet for 1D/2D residual architectures, autoencoder for convolutional autoencoders, ssm/s4d.py for state-space sequence modeling, streaming for online inference helpers, and norm.py for normalization layers.
- These modules are designed to consume preprocessed GW-like tensors produced by the transforms and datasets.
7. Utilities and physics helpers
- ml4gw/utils contains low-level helpers such as interferometer-related utilities and slicing.
- Top-level modules like gw.py, spectral.py, augmentations.py, distributions.py, constants.py, and types.py provide shared physics/math helpers, tensor utilities, and type definitions used across the package.
8. Streaming / online inference boundary
- The nn/streaming package introduces explicit online-processing support through components like snapshotter and online_average.
- This indicates the library is not limited to offline training; it also supports sliding-window or incremental inference over time series.
9. Testing strategy
- tests/ mirrors the package layout almost one-to-one, which makes the architecture easy to map and suggests strong module-level isolation.
- There are dedicated test groups for dataloading, transforms, waveform synthesis, utilities, and each NN subsystem.
- benchmarks/ mirrors major functional areas as well, indicating the project tracks performance for compute-heavy signal-processing and model components.
10. Documentation and examples
- docs/ is a first-class part of the repo, with tutorials, installation docs, and example pages for augmentation, distributions, GW utilities, and transform families.
- The notebooks under docs/tutorials/ act as higher-level integration examples that likely demonstrate the intended end-to-end flow from signals to models.
11. Packaging and release
- The project is packaged as a Python library via pyproject.toml and pinned with uv.lock.
- GitHub Actions handles documentation builds, pre-commit checks, unit tests, and publishing, so the repo’s operational boundary is standard library CI/CD rather than runtime infrastructure.
12. Architecture summary for a diagram
- The cleanest diagram would show three main capability layers: signal generation, signal preprocessing/data access, and ML models/streaming inference.
- Shared utilities and spectral/physics helpers sit beneath those layers, while tests/docs/benchmarks wrap the whole codebase as validation and usability scaffolding.
Main entry points: transforms Transforms · waveforms Waveforms · nn Neural nets · ml4gw Shared helpers
Components 27
Signal generation
Synthetic waveform and parameter-to-strain synthesis
- Waveforms · Top-level waveform generation package
ml4gw/waveforms - CBC models · Compact binary coalescence waveform models
ml4gw/waveforms/cbc - Ad hoc signals · Sine-Gaussian and ringdown-style synthetic signals
ml4gw/waveforms/adhoc - Conversion · Physical-parameter to waveform conversion layer
ml4gw/waveforms/conversion.py - Generator · Waveform assembly and generation entry point
ml4gw/waveforms/generator.py
Preprocessing and data
Transforms and dataset adapters that prepare training tensors
- Transforms · Main signal-conditioning and feature-extraction layer
ml4gw/transforms - Spectral tools · Spectral density and frequency-domain helpers
ml4gw/transforms/spectral.py - Whitening · Noise whitening and conditioning transforms
ml4gw/transforms/whitening.py - Q transform · Q-transform feature extraction
ml4gw/transforms/qtransform.py - Scaling · Amplitude and SNR rescaling utilities
ml4gw/transforms/scaler.py - Datasets · Training data adapters and storage backends
ml4gw/dataloading - In-memory · Small local dataset wrapper
ml4gw/dataloading/in_memory_dataset.py - HDF5 · On-disk HDF5 dataset wrapper
ml4gw/dataloading/hdf5_dataset.py - Chunked · Chunked access for scalable training
ml4gw/dataloading/chunked_dataset.py
Models and inference
Reusable neural components and streaming inference helpers
- Neural nets · Reusable neural network building blocks
ml4gw/nn - ResNet · 1D and 2D residual architectures
ml4gw/nn/resnet - Autoencoder · Convolutional autoencoder components
ml4gw/nn/autoencoder - S4D · State-space sequence modeling module
ml4gw/nn/ssm/s4d.py - Streaming · Sliding-window and incremental inference helpers
ml4gw/nn/streaming
Shared core
Package-wide physics, math, and utility helpers
- Shared helpers · Package-wide physics, math, and type helpers
ml4gw - GW utils · Gravitational-wave domain utilities
ml4gw/gw.py - Utilities · Interferometer and slicing helpers
ml4gw/utils - Augmentations · Shared augmentation utilities
ml4gw/augmentations.py - Distributions · Sampling and parameter distribution helpers
ml4gw/distributions.py
Validation and docs
Tests, benchmarks, and documentation that mirror the library
- Tests · Module-level test suite mirroring the package layout
tests - Benchmarks · Performance coverage for compute-heavy components
benchmarks - Docs · User guides, examples, and tutorials
docs
Connections 36
- Waveforms → CBC models: contains · Waveform family for compact binaries
- Waveforms → Ad hoc signals: contains · Waveform family for synthetic ad hoc signals
- Waveforms → Conversion: uses · Converts physical parameters into waveform tensors
- Waveforms → Generator: exposes · Builds waveform generation workflows
- Generator → Conversion: parameterizes · Maps source parameters into generator inputs
- Transforms → Spectral tools: includes · Frequency-domain estimation helpers
- Transforms → Whitening: includes · Noise conditioning layer
- Transforms → Q transform: includes · Time-frequency feature extraction
- Transforms → Scaling: includes · Amplitude and SNR rescaling
- Datasets → In-memory: contains · Small-dataset adapter
- Datasets → HDF5: contains · Persistent on-disk dataset adapter
- Datasets → Chunked: contains · Chunked streaming dataset adapter
- Neural nets → ResNet: contains · Residual feature extractors
- Neural nets → Autoencoder: contains · Convolutional representation models
- Neural nets → S4D: contains · State-space sequence model
- Neural nets → Streaming: contains · Online inference helpers
- Streaming → S4D: supports · Streaming-friendly sequence processing
- Shared helpers → GW utils: provides · Domain-specific gravitational-wave helpers
- Shared helpers → Utilities: provides · Low-level utility boundary
- Shared helpers → Augmentations: provides · Reusable augmentation helpers
- Shared helpers → Distributions: provides · Sampling and prior helpers
- Transforms → Shared helpers: depends on · Transforms use shared physics and utility helpers
- Waveforms → Shared helpers: depends on · Waveform code reuses common helpers
- Datasets → Transforms: feeds · Datasets supply tensors to preprocessing and training
- Transforms → Neural nets: feeds · Conditioned tensors flow into model components
- Waveforms → Transforms: feeds · Synthetic signals can be injected into preprocessing
- Tests → Transforms: covers · Mirrors transform modules
- Tests → Waveforms: covers · Mirrors waveform modules
- Tests → Datasets: covers · Mirrors dataset adapters
- Tests → Neural nets: covers · Mirrors neural network components
- Benchmarks → Transforms: measures · Benchmarks signal-processing routines
- Benchmarks → Waveforms: measures · Benchmarks waveform generation
- Benchmarks → Neural nets: measures · Benchmarks model components
- Docs → Transforms: documents · Examples and tutorials for preprocessing
- Docs → Waveforms: documents · Examples for waveform generation
- Docs → Shared helpers: documents · Examples for shared helpers and utilities