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. The row is the waveform segment zero-padded by
:func:~gwmock_signal.projection.resampling.edge_padding samples at each end before
projection, as :func:~gwmock_signal.projection.network.project_polarizations_to_network
pads, so n_samples here is the waveform's length plus twice that padding and epoch
(and start_index) describe the padded row.
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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
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
each is resampled onto the segment's lattice, as
:func:~gwmock_signal.injection.inject_strain does, 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 | TimeSeries]] | None
|
Optional per-segment backgrounds, aligned with
|
None
|
interpolate_if_offset
|
bool
|
Whether to resample, as |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[DetectorStrainStack]
|
class: |
list[DetectorStrainStack]
|
entry in |
|
list[DetectorStrainStack]
|
|
Source code in src/gwmock_signal/jax_batch.py
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 1168 1169 1170 1171 | |
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
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
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
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
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
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
simulate_cbc_batch(approximant, detector_names, *, sampling_frequency, minimum_frequency, parameters, backend=None, effects=None, ephemeris=None, output_grid=None, earth_rotation=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.
Like that function, the batch pads each waveform segment by
:func:~gwmock_signal.projection.resampling.edge_padding samples at each end before projecting,
so the geocentre-to-detector delay cannot move signal past either end. Each row is therefore
2 * edge_padding(sampling_frequency) samples longer than the waveform segment and starts
edge_padding(sampling_frequency) samples earlier, with the same start and length as the host
projection of the same waveform; epoch and start_index in the result describe that
padded row.
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
|
effects
|
ProjectionEffects | None
|
Which physical effects the projection includes, as on the host; see
:class: |
None
|
ephemeris
|
SolarSystemEphemeris | None
|
The Earth and Sun tables for the solar-system delays; the LALPulsar DE405 tables by default. |
None
|
earth_rotation
|
bool | None
|
Deprecated; |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
BatchedDetectorStrain
|
class: |
BatchedDetectorStrain
|
n_samples + 2 * edge_padding(sampling_frequency)) |
|
BatchedDetectorStrain
|
waveform segment's length, and per-event timing metadata describing the padded rows. |
Source code in src/gwmock_signal/jax_batch.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 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 | |
simulate_cbc_catalogue(approximant, detector_names, *, sampling_frequency, minimum_frequency, parameters, segment_duration, start_time, end_time, backend=None, effects=None, ephemeris=None, n_chirp_mass_bins=1, chunk_size=None, memory_fraction=_DEFAULT_MEMORY_FRACTION, align_to_output_grid=True, interpolate_if_offset=True, earth_rotation=None)
¶
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
|
effects
|
ProjectionEffects | None
|
Forwarded to :func: |
None
|
ephemeris
|
SolarSystemEphemeris | None
|
Forwarded to :func: |
None
|
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
|
earth_rotation
|
bool | None
|
Deprecated; |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[DetectorStrainStack]
|
class: |
list[DetectorStrainStack]
|
segment, in time order. |
Source code in src/gwmock_signal/jax_batch.py
1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 | |
For the narrative guide and examples, see Batched GPU simulation. For the single-event CPU path, see Pipeline and Simulator.