Batched simulation
gwmock_signal.jax_batch
¶
Batched, on-device CBC simulation for catalogue-scale generation.
Generates a whole catalogue of compact-binary signals on device: ripple
frequency-domain waveforms under jax.vmap (one shared, worst-case grid), then
the JAX antenna pattern + geocenter delay + inverse FFT per event and detector.
The result is raw strain arrays plus timing metadata; injecting those signals into
fixed-duration data-segment files (including signals spanning several segments) is
a separate assembly step.
Requires the optional [jax] extra (via :class:RippleBackend). JAX is imported
lazily so the package still imports without it.
BatchedDetectorStrain
dataclass
¶
Catalogue-scale detector strain as raw arrays plus timing metadata.
strain has shape (n_events, n_detectors, n_samples) and is a JAX array
(on device). Each event/detector row is a time series with sample spacing
1 / sampling_frequency; coalescence sits -epoch seconds from the start of the
buffer, near its end.
Where the buffer begins depends on whether it was aligned to an output lattice:
- Aligned (
gridandstart_indexset): the first sample is atgrid.time_of(start_index), exactly on the lattice, so superposing the signal onto a segment of that grid is an integer-offset add. - Unaligned (both
None): the first sample is atepoch + coa_time[event], an arbitrary time, and a consumer must resample to place it -- which is accurate only for heavily oversampled strain.
The signals are not yet placed on a shared timeline or segmented into files; that assembly step is handled separately.
Source code in src/gwmock_signal/jax_batch.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
assemble_segments(batch, *, segment_duration, segment_start_times, backgrounds=None, interpolate_if_offset=True)
¶
Scatter the batched signals into fixed-duration data segments (in memory).
Each output segment spans [start, start + segment_duration). A signal longer than
segment_duration contributes its overlapping part to each of the consecutive segments
it spans.
When batch was generated against a :class:~gwmock_signal.sampling_grid.SamplingGrid
-- see output_grid on :func:simulate_cbc_batch -- every signal already starts on the
output lattice and superposition is an exact integer-offset add. The segment starts are
then required to lie on that same grid, and are rejected rather than rounded if they do
not. Otherwise signals fall between samples and
:func:~gwmock_signal.injection.inject_strains_sequential resamples them, which is only
accurate for heavily oversampled strain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
BatchedDetectorStrain
|
Batched per-event/detector strain from :func: |
required |
segment_duration
|
float
|
Duration of every output segment, in seconds. |
required |
segment_start_times
|
Sequence[float]
|
GPS start time of each output segment (typically a
contiguous tiling, e.g. |
required |
backgrounds
|
Sequence[Mapping[str, TimeSeries]] | None
|
Optional per-segment backgrounds, aligned with
|
None
|
interpolate_if_offset
|
bool
|
Forwarded to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[DetectorStrainStack]
|
class: |
list[DetectorStrainStack]
|
entry in |
|
list[DetectorStrainStack]
|
|
Source code in src/gwmock_signal/jax_batch.py
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
available_device_memory_bytes()
¶
Return the memory limit of the default JAX device, or None if unknown.
CPU devices do not report a limit, and neither do some older backends, so callers must
treat None as "cannot check" rather than as "no limit".
Source code in src/gwmock_signal/jax_batch.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
estimate_batch_memory_bytes(n_events, n_detectors, n_samples, *, earth_rotation=True)
¶
Estimate peak device memory for one :func:simulate_cbc_batch call.
A vmapped batch holds far more than the strain it returns: the measured peak for an
IMRPhenomXPHM batch was about 28x its own output. The estimate is therefore
n_events * n_samples * 8 * (generation + per_detector * n_detectors), with the
coefficients above.
One calibration point
The coefficients come from a single A100 measurement with IMRPhenomXPHM, and the split between detector-independent and per-detector buffers is assumed rather than measured. Treat this as an order-of-magnitude guard that produces a useful error message, not as an accurate predictor. Approximants with smaller graphs than IMRPhenomXPHM will be over-estimated, which only costs a smaller chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_events
|
int
|
Events in the batch. |
required |
n_detectors
|
int
|
Detectors projected onto. |
required |
n_samples
|
int
|
Samples per event segment. |
required |
earth_rotation
|
bool
|
Whether the rotating projection is used, which needs more simultaneous buffers per detector. |
True
|
Returns:
| Type | Description |
|---|---|
int
|
Estimated peak bytes. |
Source code in src/gwmock_signal/jax_batch.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
recommend_chunk_size(n_detectors, n_samples, *, earth_rotation=True, memory_fraction=_DEFAULT_MEMORY_FRACTION, available_bytes=None)
¶
Return the largest event count expected to fit, or None if unknown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_detectors
|
int
|
Detectors projected onto. |
required |
n_samples
|
int
|
Samples per event segment. |
required |
earth_rotation
|
bool
|
Whether the rotating projection is used. |
True
|
memory_fraction
|
float
|
Fraction of device memory the batch may occupy; must be in |
_DEFAULT_MEMORY_FRACTION
|
available_bytes
|
int | None
|
Device memory limit; queried from JAX when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
int | None
|
A chunk size of at least 1, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/gwmock_signal/jax_batch.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
simulate_cbc_batch(approximant, detector_names, *, sampling_frequency, minimum_frequency, parameters, backend=None, earth_rotation=True, output_grid=None)
¶
Simulate a catalogue of CBC signals on device, one strain per event and detector.
Evaluates ripple frequency-domain waveforms for the whole catalogue under
jax.vmap (a single grid sized worst-case for the longest inspiral), then
projects each event onto each detector with the JAX antenna pattern and geocenter
delay and inverse-FFTs to strain. The antenna pattern and delay are evaluated per
sample by default and once per event at the segment midpoint when
earth_rotation=False, matching the two branches of
:func:gwmock_signal.projection.network.project_polarizations_to_network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
approximant
|
str
|
A supported ripple approximant name. |
required |
detector_names
|
Sequence[DetectorSpec]
|
Built-in LAL interferometer codes (e.g. |
required |
sampling_frequency
|
float
|
Sample rate in Hz. |
required |
minimum_frequency
|
float
|
Low-frequency cutoff in Hz. |
required |
parameters
|
Mapping[str, object]
|
Mapping of canonical gwmock-pop parameter names (no aliases)
to equal-length 1-D arrays. In addition to the waveform parameters
(masses, spins, distance, inclination, coa_phase) this must include
|
required |
backend
|
RippleBackend | None
|
Optional configured :class: |
None
|
output_grid
|
SamplingGrid | None
|
Sample lattice the returned strain should start on. When given, each
event's first sample is placed exactly on the grid and the sub-sample remainder is
absorbed into the shift the projection already applies -- an exact resampling
rather than a second, cruder one downstream. Superposition then becomes an
integer-offset add. When omitted, buffers start at the arbitrary time
|
None
|
earth_rotation
|
bool
|
If |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
BatchedDetectorStrain
|
class: |
BatchedDetectorStrain
|
n_samples)`` strain and per-event timing metadata. |
Source code in src/gwmock_signal/jax_batch.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
simulate_cbc_catalogue(approximant, detector_names, *, sampling_frequency, minimum_frequency, parameters, segment_duration, start_time, end_time, backend=None, earth_rotation=True, n_chirp_mass_bins=1, chunk_size=None, memory_fraction=_DEFAULT_MEMORY_FRACTION, align_to_output_grid=True, interpolate_if_offset=True)
¶
Generate a catalogue on device and assemble it into fixed-duration segments.
Convenience wrapper that runs :func:simulate_cbc_batch and then
:func:assemble_segments, tiling [start_time, end_time) into contiguous
zero-noise segments of segment_duration. Signals are placed at their
coa_time and split across the segments they span; signals outside the span
simply do not appear. For non-zero backgrounds use the two-step API
(:func:simulate_cbc_batch then :func:assemble_segments) so you can supply a
background per segment.
Two independent memory controls (composable):
chunk_sizebounds the peak generation memory by processing at most that many events per batched call. All chunks of a bin share that bin's grid, so chunking leaves the model untouched -- it agrees with processing the whole bin at once to a few times 1e-13 of peak, measured on both the aligned and unaligned assembly paths. It is not bit-for-bit: XLA picks different reduction orderings for different batch shapes, so the same event generated in a batch of four and a batch of two differs in the last few bits. Nothing physical changes; see :func:_check_batch_fits.n_chirp_mass_binsbounds the buffer length by generating heavier events on shorter grids. Because each bin uses a different frequency resolution, binning is not bit-identical to a single grid (see below).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
approximant
|
str
|
A supported ripple approximant name. |
required |
detector_names
|
Sequence[DetectorSpec]
|
Built-in LAL interferometer codes (e.g. |
required |
sampling_frequency
|
float
|
Sample rate in Hz. |
required |
minimum_frequency
|
float
|
Low-frequency cutoff in Hz. |
required |
parameters
|
Mapping[str, object]
|
Canonical catalogue parameters as struct-of-arrays (see
:func: |
required |
segment_duration
|
float
|
Duration of every output segment, in seconds. |
required |
start_time
|
float
|
GPS start of the first segment. |
required |
end_time
|
float
|
GPS time the tiling must cover up to; the final segment is the
first one whose span reaches or passes |
required |
backend
|
RippleBackend | None
|
Optional configured :class: |
None
|
earth_rotation
|
bool
|
Forwarded to :func: |
True
|
n_chirp_mass_bins
|
int
|
Number of chirp-mass groups generated separately, each on
its own worst-case grid (lightest first), injected on top of the
earlier bins. |
1
|
chunk_size
|
int | None
|
Generate at most this many events per batched call (within each bin).
Model-preserving whatever the value -- it only bounds peak memory, and agrees
with an unchunked run to a few times 1e-13 of peak rather than bitwise. When omitted,
a size is chosen from the device memory limit and the grid actually selected
(see :func: |
None
|
memory_fraction
|
float
|
Fraction of device memory an automatically chosen chunk may
occupy. Ignored when |
_DEFAULT_MEMORY_FRACTION
|
align_to_output_grid
|
bool
|
Generate every batch on the lattice defined by this function's
own segment starts, so superposition is an exact integer-offset add. Defaults to
|
True
|
interpolate_if_offset
|
bool
|
Forwarded to :func: |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[DetectorStrainStack]
|
class: |
list[DetectorStrainStack]
|
segment, in time order. |
Source code in src/gwmock_signal/jax_batch.py
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 | |
For the narrative guide and examples, see Batched GPU simulation. For the single-event CPU path, see Pipeline and Simulator.