Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions projects/data/data.smk
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ The PSDs are those of the last fetched train-background chunk.
lowpass=config["lowpass"] or "null",
snr_threshold=config["snr_threshold"],
max_num_samples=config["max_num_samples"],
# offset by branch so each branch samples different parameters
seed=lambda wc: config["seed"] + int(wc.vbranch_id),
shell:
"generate-validation-waveforms"
" --num_signals {params.num_signals}"
Expand All @@ -429,6 +431,7 @@ The PSDs are those of the last fetched train-background chunk.
" --snr_threshold {params.snr_threshold}"
" --psd {input.psd_file}"
" --max_num_samples {params.max_num_samples}"
" --seed {params.seed}"
" --output_file {output}"
" &> {log}"

Expand Down
6 changes: 6 additions & 0 deletions projects/data/data/waveforms/rejection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import numpy as np
import torch
from bilby.core.utils import random as bilby_random
from data.waveforms.utils import convert_to_detector_frame, load_psds
from ledger.injections import (
BilbyParameterSet,
Expand All @@ -30,7 +31,12 @@ def rejection_sample(
snr_threshold: float,
psd: Path | torch.Tensor,
max_num_samples: int,
seed: int | None = None,
) -> tuple[ResponseSetFields, InjectionParameterSet]:
# bilby priors sample from bilby's own generator
if seed is not None:
bilby_random.seed(seed)

# get the detector tensors and vertices
# for projecting our waveforms
tensors, vertices = get_ifo_geometry(*ifos)
Expand Down
8 changes: 6 additions & 2 deletions projects/data/data/waveforms/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import hashlib
import logging
import random
import time
from pathlib import Path
from zlib import adler32

import h5py
import numpy as np
import torch
from bilby.core.utils import random as bilby_random
from gwpy.timeseries import TimeSeriesDict


Expand All @@ -22,13 +23,16 @@ def seed_worker(
start: float, stop: float, shifts: list[float], seed: int
) -> np.random.Generator:
fingerprint = str((start, stop) + tuple(shifts))
worker_hash = adler32(fingerprint.encode())
digest = hashlib.sha256(fingerprint.encode()).digest()
worker_hash = int.from_bytes(digest[:8], "big")
combined = seed + worker_hash
logging.info(
f"Seeding data generation with seed {seed}, "
f"augmented by worker seed {worker_hash}"
)
random.seed(combined)
# bilby priors sample from bilby's own generator
bilby_random.seed(combined)
return np.random.default_rng(combined)


Expand Down
Loading