Skip to main content

gwmock-pop

Python CI pre-commit.ci status Documentation Status codecov PyPI Version Python Versions License Ruff DOI SPEC 0 — Minimum Supported Dependencies

gwmock-pop is a Python package for simulating populations of gravitational-wave sources.

Current package surface

  • Protocols: GWPopSimulator (population simulators), ExternalPopulationLoader (catalogue loaders).
  • Graph-driven sampling: GraphSimulator from a YAML/TOML parameters graph (packaged presets via list_presets() / GraphSimulator.from_preset).
  • Graph-backed CBC simulators: CBCSimulator, BBHSimulator, BNSSimulator, and NSBHSimulator — configurable priors built on the graph engine; override any parameter's distribution via the parameters= argument.
  • Composition: MixtureSimulator, PoissonEventSampler (event-count helper used in mixture workflows).
  • Catalogues: FilePopulationLoader and read_population_catalogue / write_population_catalogue for CSV and HDF5 (structured or group-of-datasets layouts), including remote URL loading with local caching and CBC canonicalization in the loader.
  • Catalogue draws: gwmock_pop.catalogue draws a seeded population from a published merger catalogue at real distances into injection parameters, with a detector-frame band cut and the per-class band composition. The catalogues are downloaded on demand and verified against a pinned SHA-256, so they are not shipped with the package.
  • Provenance: gwmock_pop.provenance — every written catalogue carries a machine-readable record of the run behind it, and replay_catalogue redraws that run from the record alone.
  • Quality checks: validate_sample for arrays returned by simulators.

Public re-exports live in gwmock_pop.__all__; full module reference is in the API docs.

Requirements

  • Python >=3.12 (tested on 3.12–3.14)
  • Linux, macOS, or Windows

Floating-point precision

Importing gwmock_pop enables 64-bit JAX floats (jax_enable_x64). GPS-scale parameters such as coa_time (~1.6 × 10⁹ s) are unusable in JAX's 32-bit default, where the float32 spacing at that magnitude is 128 s. The flag is global JAX state, so it also affects arrays your own code creates after the import. To keep JAX's 32-bit default (e.g. for GPU-throughput studies that do not sample absolute times), set GWMOCK_POP_DISABLE_X64=1 in the environment before importing the package.

The flag is requested by setting JAX_ENABLE_X64=1 in os.environ, so that importing gwmock_pop does not have to import JAX (see below). Two consequences worth knowing: child processes started afterwards inherit the same precision, and GWMOCK_POP_DISABLE_X64 takes precedence over JAX_ENABLE_X64 whoever set it. Call jax.config.update("jax_enable_x64", True) yourself if you want 64-bit floats while opting out of this package's default.

Import cost

Importing gwmock_pop does not import JAX. The samplers, distributions and transforms are JAX code and import it when they are loaded, but reading a population catalogue, resolving a configuration or running gwmock-pop --help does not reach them — and so does not pay for JAX's import (about 240 ms) or start XLA's thread pools, which is also what keeps such a process safe to fork().

Installation

Install from PyPI:

uv venv --python 3.12
source .venv/bin/activate  # Windows: .venv\Scripts\activate
uv pip install gwmock-pop

Install from source:

git clone git@github.com:Leuven-Gravity-Institute/gwmock-pop.git
cd gwmock-pop
uv venv --python 3.12
source .venv/bin/activate  # Windows: .venv\Scripts\activate
uv sync --no-dev

Developer setup:

uv sync --group dev
uv run prek install

Docs setup:

uv sync --group docs
uv run zensical serve

Getting started (CLI)

The gwmock-pop CLI uses Typer. Typical flow: pick a packaged preset or a graph config file, set the sample count, and write a CSV or HDF5 catalogue.

# Packaged preset (see `gwmock-pop list` for names)
gwmock-pop simulate --config gwtc4 --n 1000 --output population.csv --seed 42

# Or a graph YAML/TOML (top-level `parameters:` as in `examples/gwtc4/bbh_population.yaml`)
gwmock-pop simulate --config examples/gwtc4/bbh_population.yaml --n 500 --output out.h5

A config file may also carry the run and output blocks that MainConfiguration describes, and simulate honours them: run.seed, run.n_samples, run.name and run.output.*. Command-line options win over the file.

Other commands:

Command Purpose
gwmock-pop simulate Sample a packaged preset or graph config into a catalogue
gwmock-pop catalogue Draw the published population and report its detector-frame band composition
gwmock-pop convert Convert population files between CSV and HDF5; optional --column-map JSON/YAML
gwmock-pop validate Check a graph config without sampling
gwmock-pop inspect Summary statistics for a population file
gwmock-pop list List presets and public simulator classes
gwmock-pop --help
gwmock-pop simulate --help

Getting started (library)

from gwmock_pop import CBCSimulator

sim = CBCSimulator(seed=42)
population = sim.simulate(100)
assert population["detector_frame_mass_1"].shape == (100,)

Use GraphSimulator.from_config_file(...) or GraphSimulator.from_preset(...) for full graph configs (see examples/ and gwmock_pop.simulators.graph).

Sample from a packaged preset (run gwmock-pop list or list_presets() for the available names):

from gwmock_pop import GraphSimulator, list_presets

print(list_presets())  # e.g. ["gwtc4", ...]
sim = GraphSimulator.from_preset("gwtc4")
catalogue = sim.simulate(1000)

Provenance

Every catalogue written by gwmock-pop simulate — and by Simulator.save_catalogue — carries a machine-readable record of the run that produced it: the package version and, from a checkout, the commit and dirty flag; the complete resolved configuration with sampler defaults filled in; the RNG seed as actually used, so a run started without --seed is still repeatable; the source type, row count and column names in output order; and the creation time and writing tool.

HDF5 files carry the record in a metadata group beside data. CSV files get a <name>.csv.provenance.json sidecar — which is why HDF5 is the format to publish in: a sidecar can be separated from the catalogue it describes.

from gwmock_pop.provenance import read_provenance, replay_catalogue

record = read_provenance("population.h5")
catalogue = replay_catalogue(record)  # the same samples, from the record alone

Set run.output.save_metadata to false to write the samples on their own.

FilePopulationLoader also accepts http://, https://, s3://, and zenodo://<record>/<file> sources. Remote catalogues are cached under ${GWMOCK_POP_CACHE_DIR} or ${XDG_CACHE_HOME:-~/.cache}/gwmock-pop, and CBC catalogues are validated and rewritten to canonical gwmock-pop parameter names before sampling.

Verification

gwmock-pop --help
python -c "import gwmock_pop; print(gwmock_pop.__version__)"

Testing

Default test run excludes integration-marked tests:

uv run pytest

Run integration tests explicitly:

uv run pytest -m integration

Documentation

License

BSD 3-Clause, see LICENSE.

Metadata

Release files for gwmock-pop 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gwmock-pop 0.14.0
File Size Uploaded
gwmock_pop-0.14.0.tar.gz 408.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gwmock-pop 0.14.0
File Interpreter ABI Platform
gwmock_pop-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 559.9 kB

Release files / gwmock_pop-0.14.0.tar.gz

Download URL gwmock_pop-0.14.0.tar.gz
Size 408.3 kB
Tags Source
SHA-256 checksum
How to use checksums
450b99caeddcab957bcbc357b77a1739e8eedc2ceef05de14c6d67bbaea65813
BLAKE2b-256 checksum
How to use checksums
aa2cdf9c38eb6c7ecf9bb563a11184192218802f12dc4159b46c2fcfc441d0bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / gwmock_pop-0.14.0-py3-none-any.whl

Download URL gwmock_pop-0.14.0-py3-none-any.whl
Size 151.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0144cd147ab8f9ad743c9e048629a2adf2f0240701a8314455dbf498c856deb3
BLAKE2b-256 checksum
How to use checksums
ba12e623936d3b3e417d89dfcffea5e04c47537acaf558a1c64665c7cb5042dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.14.3

2 release files

0.14.1

2 release files

This release

0.14.0 This release

2 release files

0.13.2

2 release files

0.12.0

2 release files

0.11.7

2 release files

0.11.6

2 release files

0.11.4

2 release files

0.11.3

2 release files

0.11.2

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page