Repository navigation
Expand file tree
/
Copy pathverify_binary_dynamics.py
More file actions
1150 lines (1074 loc) · 36.2 KB
/
Copy pathverify_binary_dynamics.py
File metadata and controls
1150 lines (1074 loc) · 36.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
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
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
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
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
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""Validate the bundled SXS-driven binary dynamics and playback contract."""
from __future__ import annotations
import copy
import hashlib
import json
import math
from pathlib import Path
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
MANIFEST = ROOT / "assets" / "scenes" / "binary-sxs-bbh-0001-v2.json"
GENERATOR = ROOT / "scripts" / "generate_binary_sxs_dynamics.py"
EXPECTED_COLUMNS = [
"tProtocolM",
"separationM",
"orbitalPhaseUnwrappedRad",
"h22Real",
"h22Imag",
"renderTopologyBlend",
"individualHorizonsValid",
]
ERROR_CHANNELS = {
"separationM",
"orbitalPhaseUnwrappedRad",
"h22Real",
"h22Imag",
"renderTopologyBlend",
}
DECLARED_ERROR_LIMITS = {
"separationM": 0.003,
"orbitalPhaseUnwrappedRad": 0.003,
"h22Real": 0.0005,
"h22Imag": 0.0005,
"renderTopologyBlend": 0.0005,
}
EXPECTED_STATE_ABI = [
"separationM",
"orbitalPhaseUnwrappedRad",
"renderTopologyBlend",
"reserved",
]
EXPECTED_MASS_ABI = [
"bodyAMassFraction",
"bodyBMassFraction",
"remnantMassFraction",
"reserved",
]
PINNED_SOURCE = {
"metadata": (
4_170,
"099d4c93d9466fe4b7ecad6c94499cf3",
"329d0643f9d33361eafaeae7ef1818dcda3311b33477ecef4f002ead17f42668",
),
"horizons": (
3_501_232,
"484ea88842209e64983793159bcc7d7c",
"cf97de4a60a4cd5c6a56f219ea9fa81f1849647f134250e95ae79e40be4dd957",
),
"waveform": (
142_641_207,
"c271e0b905c74f434f00c9b14f67850c",
"d760add0693e458781f8db9958b4669971e816d7c026cdbe5f09b7d8fd6bd21f",
),
}
PINNED_SOURCE_PATHS = {
"metadata": "SXS:BBH:0001/Lev5/metadata.json",
"horizons": "SXS:BBH:0001/Lev5/Horizons.h5",
"waveform": (
"SXS:BBH:0001/Lev5/"
"rhOverM_Asymptotic_GeometricUnits_CoM.h5"
),
}
PINNED_REMNANT_MASS = 0.951609417715
PINNED_REMNANT_SPIN_Z = 0.686461676493
PINNED_REFERENCE_MASS_TOTAL = 1.000000327684
class ValidationError(RuntimeError):
pass
def require(condition: bool, message: str) -> None:
if not condition:
raise ValidationError(message)
def object_without_duplicates(pairs: list[tuple[str, Any]]) -> dict[str, Any]:
result: dict[str, Any] = {}
for key, value in pairs:
require(key not in result, f"duplicate JSON key: {key}")
result[key] = value
return result
def strict_json(path: Path) -> Any:
def reject_constant(value: str) -> None:
raise ValidationError(f"{path}: non-finite JSON constant {value!r}")
try:
with path.open(encoding="utf-8") as stream:
return json.load(
stream,
object_pairs_hook=object_without_duplicates,
parse_constant=reject_constant,
)
except (OSError, UnicodeError, json.JSONDecodeError) as error:
raise ValidationError(f"cannot read {path}: {error}") from error
def sha256(path: Path) -> str:
checksum = hashlib.sha256()
with path.open("rb") as stream:
while block := stream.read(1024 * 1024):
checksum.update(block)
return checksum.hexdigest()
def finite(value: Any, path: str) -> float:
require(
isinstance(value, (int, float)) and not isinstance(value, bool),
f"{path} must be numeric",
)
numeric = float(value)
require(math.isfinite(numeric), f"{path} must be finite")
return numeric
def integer(value: Any, path: str) -> int:
require(
isinstance(value, int) and not isinstance(value, bool),
f"{path} must be an integer",
)
return value
def boolean(value: Any, path: str) -> bool:
require(isinstance(value, bool), f"{path} must be boolean")
return value
def nonempty_string(value: Any, path: str) -> str:
require(
isinstance(value, str) and bool(value.strip()),
f"{path} must be a non-empty string",
)
return value
def vector3(value: Any, path: str) -> list[float]:
require(isinstance(value, list) and len(value) == 3, f"{path} must have 3 values")
return [finite(component, f"{path}[{index}]") for index, component in enumerate(value)]
def dimensionless_spin(value: Any, path: str) -> list[float]:
spin = vector3(value, path)
magnitude = math.sqrt(sum(component * component for component in spin))
require(magnitude <= 1.0 + 1.0e-12, f"{path} magnitude must not exceed one")
return spin
def sha256_text(value: Any, path: str) -> str:
digest = nonempty_string(value, path)
require(
len(digest) == 64
and all(character in "0123456789abcdef" for character in digest),
f"{path} must be a lowercase SHA-256",
)
return digest
def exact_keys(value: Any, expected: set[str], path: str) -> dict[str, Any]:
require(isinstance(value, dict), f"{path} must be an object")
actual = set(value)
require(
actual == expected,
f"{path} keys differ: missing={sorted(expected - actual)}, "
f"unknown={sorted(actual - expected)}",
)
return value
def linear_sample(rows: list[list[Any]], time_m: float) -> list[float]:
if time_m <= rows[0][0]:
return [float(value) for value in rows[0][:6]]
if time_m >= rows[-1][0]:
return [float(value) for value in rows[-1][:6]]
lower = 0
upper = len(rows) - 1
while upper - lower > 1:
middle = (lower + upper) // 2
if rows[middle][0] <= time_m:
lower = middle
else:
upper = middle
first = rows[lower]
second = rows[upper]
weight = (time_m - first[0]) / (second[0] - first[0])
return [
float(first[index] + (second[index] - first[index]) * weight)
for index in range(6)
]
def verify_physical_system(manifest: dict[str, Any]) -> None:
physical = exact_keys(
manifest["physicalSystem"],
{
"bodies",
"massRatioQ",
"referenceEccentricity",
"referenceTimeCodeUnits",
"remnant",
},
"$.physicalSystem",
)
bodies = physical["bodies"]
require(
isinstance(bodies, list) and len(bodies) == 2,
"$.physicalSystem.bodies must contain exactly A and B",
)
masses: list[float] = []
position_scales: list[float] = []
for index, expected_id in enumerate(("A", "B")):
path = f"$.physicalSystem.bodies[{index}]"
body = exact_keys(
bodies[index],
{
"id",
"massFraction",
"dimensionlessSpin",
"orbitPositionScale",
},
path,
)
require(body["id"] == expected_id, f"{path}.id must be {expected_id!r}")
mass = finite(body["massFraction"], f"{path}.massFraction")
require(0.0 < mass < 1.0, f"{path}.massFraction must be in (0,1)")
masses.append(mass)
dimensionless_spin(body["dimensionlessSpin"], f"{path}.dimensionlessSpin")
position_scales.append(
finite(body["orbitPositionScale"], f"{path}.orbitPositionScale")
)
require(
math.isclose(sum(masses), 1.0, rel_tol=0.0, abs_tol=1.0e-12),
"$.physicalSystem body mass fractions must sum to one",
)
require(
position_scales[0] < 0.0 < position_scales[1],
"$.physicalSystem orbit position scales must straddle the barycentre",
)
require(
math.isclose(
position_scales[1] - position_scales[0],
1.0,
rel_tol=0.0,
abs_tol=1.0e-12,
)
and math.isclose(
masses[0] * position_scales[0]
+ masses[1] * position_scales[1],
0.0,
rel_tol=0.0,
abs_tol=1.0e-12,
),
"$.physicalSystem orbit position scales violate the mass ABI",
)
mass_ratio = finite(physical["massRatioQ"], "$.physicalSystem.massRatioQ")
require(
mass_ratio > 0.0 and abs(mass_ratio - 1.0) <= 1.0e-6,
"$.physicalSystem.massRatioQ is not the pinned equal-mass system",
)
eccentricity = finite(
physical["referenceEccentricity"],
"$.physicalSystem.referenceEccentricity",
)
require(
0.0 <= eccentricity < 0.01,
"$.physicalSystem.referenceEccentricity is outside the quasi-circular gate",
)
require(
finite(
physical["referenceTimeCodeUnits"],
"$.physicalSystem.referenceTimeCodeUnits",
)
>= 0.0,
"$.physicalSystem.referenceTimeCodeUnits must be non-negative",
)
remnant = exact_keys(
physical["remnant"],
{
"massFraction",
"dimensionlessSpin",
"finalHorizonDiagnostic",
"metadataSource",
},
"$.physicalSystem.remnant",
)
remnant_mass = finite(
remnant["massFraction"],
"$.physicalSystem.remnant.massFraction",
)
require(
0.0 < remnant_mass <= 1.0,
"$.physicalSystem.remnant.massFraction must be in (0,1]",
)
dimensionless_spin(
remnant["dimensionlessSpin"],
"$.physicalSystem.remnant.dimensionlessSpin",
)
require(
remnant["metadataSource"] == "SXS:BBH:0001 Lev5 metadata.json",
"$.physicalSystem.remnant.metadataSource drifted",
)
diagnostic = exact_keys(
remnant["finalHorizonDiagnostic"],
{"massFraction", "dimensionlessSpin", "sourceTimeCodeUnits"},
"$.physicalSystem.remnant.finalHorizonDiagnostic",
)
diagnostic_mass = finite(
diagnostic["massFraction"],
"$.physicalSystem.remnant.finalHorizonDiagnostic.massFraction",
)
require(
0.0 < diagnostic_mass <= 1.0,
"$.physicalSystem.remnant final horizon mass must be in (0,1]",
)
dimensionless_spin(
diagnostic["dimensionlessSpin"],
"$.physicalSystem.remnant.finalHorizonDiagnostic.dimensionlessSpin",
)
require(
finite(
diagnostic["sourceTimeCodeUnits"],
"$.physicalSystem.remnant.finalHorizonDiagnostic.sourceTimeCodeUnits",
)
> finite(
physical["referenceTimeCodeUnits"],
"$.physicalSystem.referenceTimeCodeUnits",
),
"$.physicalSystem.remnant final diagnostic must follow the reference time",
)
def verify_time_and_events(manifest: dict[str, Any]) -> None:
time_reference = exact_keys(
manifest["timeReference"],
{
"protocolZeroEvent",
"waveformMapping",
"horizonMapping",
"waveformPeakSourceTimeM",
"waveformPeakAmplitude",
"alignmentCaveat",
},
"$.timeReference",
)
for name in ("waveformMapping", "horizonMapping", "alignmentCaveat"):
nonempty_string(time_reference[name], f"$.timeReference.{name}")
peak_time = finite(
time_reference["waveformPeakSourceTimeM"],
"$.timeReference.waveformPeakSourceTimeM",
)
require(peak_time > 0.0, "$.timeReference waveform source peak must be positive")
peak_amplitude = finite(
time_reference["waveformPeakAmplitude"],
"$.timeReference.waveformPeakAmplitude",
)
require(
0.0 < peak_amplitude < 1.0,
"$.timeReference waveform peak amplitude must be in (0,1)",
)
events = exact_keys(
manifest["events"],
{
"relaxation",
"individualHorizonsLast",
"commonApparentHorizonFirst",
"waveformPeak",
"playbackEnd",
},
"$.events",
)
for name, event in events.items():
path = f"$.events.{name}"
exact_keys(event, {"source", "tProtocolM"}, path)
nonempty_string(event["source"], f"{path}.source")
finite(event["tProtocolM"], f"{path}.tProtocolM")
def verify_dynamics_contract(manifest: dict[str, Any]) -> None:
dynamics = exact_keys(
manifest["dynamics"],
{
"asset",
"firstTimeM",
"finalTimeM",
"interpolation",
"sourceChannels",
"postHorizonPolicy",
"renderTransition",
"measuredMaxInterpolationError",
"declaredMaxInterpolationError",
},
"$.dynamics",
)
asset = exact_keys(
dynamics["asset"],
{
"schema",
"uri",
"encoding",
"columns",
"sampleCount",
"byteLength",
"sha256",
},
"$.dynamics.asset",
)
require(
asset["schema"] == "blackhole.binary-dynamics-samples/v1",
"$.dynamics.asset.schema changed",
)
require(
asset["encoding"] == "utf-8 minified JSON",
"$.dynamics.asset.encoding changed",
)
require(asset["columns"] == EXPECTED_COLUMNS, "$.dynamics.asset.columns changed")
require(
integer(asset["sampleCount"], "$.dynamics.asset.sampleCount") >= 100,
"$.dynamics.asset.sampleCount is implausibly small",
)
require(
integer(asset["byteLength"], "$.dynamics.asset.byteLength") > 0,
"$.dynamics.asset.byteLength must be positive",
)
sha256_text(asset["sha256"], "$.dynamics.asset.sha256")
first_time = finite(dynamics["firstTimeM"], "$.dynamics.firstTimeM")
final_time = finite(dynamics["finalTimeM"], "$.dynamics.finalTimeM")
require(
first_time < 0.0 < final_time,
"$.dynamics time range must contain the waveform peak",
)
require(
math.isclose(
first_time,
finite(
manifest["events"]["relaxation"]["tProtocolM"],
"$.events.relaxation.tProtocolM",
),
rel_tol=0.0,
abs_tol=1.0e-6,
)
and math.isclose(
final_time,
finite(
manifest["events"]["playbackEnd"]["tProtocolM"],
"$.events.playbackEnd.tProtocolM",
),
rel_tol=0.0,
abs_tol=1.0e-12,
),
"$.dynamics time range must be bounded by relaxation and playbackEnd",
)
require(
dynamics["interpolation"]
== "piecewise linear with validity-strict horizon hold",
"$.dynamics.interpolation changed",
)
nonempty_string(dynamics["postHorizonPolicy"], "$.dynamics.postHorizonPolicy")
source_channels = exact_keys(
dynamics["sourceChannels"],
{"separationM", "orbitalPhaseUnwrappedRad", "h22"},
"$.dynamics.sourceChannels",
)
for name, value in source_channels.items():
nonempty_string(value, f"$.dynamics.sourceChannels.{name}")
transition = exact_keys(
dynamics["renderTransition"],
{"kind", "startEvent", "completeEvent", "quantity"},
"$.dynamics.renderTransition",
)
require(
transition["kind"] == "smoothstep"
and transition["startEvent"] == "commonApparentHorizonFirst"
and transition["completeEvent"] == "waveformPeak",
"$.dynamics.renderTransition ABI changed",
)
require(
"presentation proxy" in nonempty_string(
transition["quantity"],
"$.dynamics.renderTransition.quantity",
),
"$.dynamics.renderTransition must remain labelled as a presentation proxy",
)
for map_name in (
"measuredMaxInterpolationError",
"declaredMaxInterpolationError",
):
error_map = exact_keys(
dynamics[map_name],
ERROR_CHANNELS,
f"$.dynamics.{map_name}",
)
for channel, value in error_map.items():
numeric = finite(value, f"$.dynamics.{map_name}.{channel}")
require(
numeric >= 0.0,
f"$.dynamics.{map_name}.{channel} must be non-negative",
)
if map_name == "declaredMaxInterpolationError":
require(
0.0 < numeric <= DECLARED_ERROR_LIMITS[channel],
f"$.dynamics.{map_name}.{channel} exceeds the v2 error budget",
)
def verify_renderer_contract(manifest: dict[str, Any]) -> None:
renderer = exact_keys(
manifest["rendererAdapter"],
{
"shaderBundleId",
"lightPropagation",
"nearZoneMetricConsumed",
"positionsFrozenPerRay",
"stateAbi",
"massAbi",
},
"$.rendererAdapter",
)
boolean(
renderer["nearZoneMetricConsumed"],
"$.rendererAdapter.nearZoneMetricConsumed",
)
boolean(
renderer["positionsFrozenPerRay"],
"$.rendererAdapter.positionsFrozenPerRay",
)
require(
renderer["nearZoneMetricConsumed"] is False
and renderer["positionsFrozenPerRay"] is True,
"$.rendererAdapter fast-light boundary changed",
)
require(
renderer["stateAbi"] == EXPECTED_STATE_ABI,
"$.rendererAdapter.stateAbi changed",
)
require(
renderer["massAbi"] == EXPECTED_MASS_ABI,
"$.rendererAdapter.massAbi changed",
)
defaults = exact_keys(
manifest["rendererDefaults"],
{
"observerRadiusM",
"fieldOfViewDeg",
"initialViewingInclinationDeg",
"exposure",
"raySteps",
},
"$.rendererDefaults",
)
require(
finite(defaults["observerRadiusM"], "$.rendererDefaults.observerRadiusM")
> 2.0,
"$.rendererDefaults.observerRadiusM must stay outside 2 M",
)
field_of_view = finite(
defaults["fieldOfViewDeg"],
"$.rendererDefaults.fieldOfViewDeg",
)
require(
1.0 < field_of_view < 179.0,
"$.rendererDefaults.fieldOfViewDeg must be in (1,179)",
)
inclination = finite(
defaults["initialViewingInclinationDeg"],
"$.rendererDefaults.initialViewingInclinationDeg",
)
require(
0.0 <= inclination <= 180.0,
"$.rendererDefaults.initialViewingInclinationDeg must be in [0,180]",
)
exposure = finite(defaults["exposure"], "$.rendererDefaults.exposure")
require(
0.0 < exposure <= 16.0,
"$.rendererDefaults.exposure must be in (0,16]",
)
ray_steps = integer(defaults["raySteps"], "$.rendererDefaults.raySteps")
require(
64 < ray_steps <= 512,
"$.rendererDefaults.raySteps must be an integer in [65,512]",
)
def verify_generation_contract(manifest: dict[str, Any]) -> None:
generation = exact_keys(
manifest["generation"],
{"command", "deterministic", "generator", "generatorSha256"},
"$.generation",
)
require(
generation["generator"] == "scripts/generate_binary_sxs_dynamics.py",
"$.generation.generator changed",
)
nonempty_string(generation["command"], "$.generation.command")
require(
boolean(generation["deterministic"], "$.generation.deterministic") is True,
"$.generation must remain deterministic",
)
sha256_text(generation["generatorSha256"], "$.generation.generatorSha256")
def verify_manifest(manifest: Any) -> None:
exact_keys(
manifest,
{
"schema",
"id",
"title",
"scientificStatus",
"source",
"units",
"physicalSystem",
"timeReference",
"events",
"dynamics",
"rendererAdapter",
"playback",
"rendererDefaults",
"generation",
},
"$",
)
require(
manifest["schema"] == "blackhole.binary-scene/v2",
"unexpected manifest schema",
)
require(
manifest["id"] == "binary-sxs-bbh-0001-v2",
"unexpected manifest id",
)
nonempty_string(manifest["title"], "$.title")
status = exact_keys(
manifest["scientificStatus"],
{
"classification",
"description",
"dynamicsSourceIsNumericalRelativity",
"nearZoneSpacetimeUsedForLightPropagation",
"slowLightGeodesicsIncluded",
"prohibitedClaim",
},
"$.scientificStatus",
)
nonempty_string(status["description"], "$.scientificStatus.description")
require(
status.get("classification")
== "NR-driven dynamics with weak-field fast-light rendering",
"scientific classification drifted",
)
require(
status.get("dynamicsSourceIsNumericalRelativity") is True,
"NR dynamics source must be explicit",
)
require(
status.get("nearZoneSpacetimeUsedForLightPropagation") is False
and status.get("slowLightGeodesicsIncluded") is False,
"manifest overclaims NR light propagation",
)
prohibited = str(status.get("prohibitedClaim", "")).lower()
require(
"do not" in prohibited and "nr ray tracing" in prohibited,
"prohibited image claim is missing",
)
source = exact_keys(
manifest["source"],
{
"catalog",
"simulation",
"level",
"recordId",
"recordDoi",
"license",
"waveformDataset",
"artifacts",
},
"$.source",
)
require(
source.get("catalog") == "SXS"
and source.get("simulation") == "SXS:BBH:0001"
and source.get("level") == "Lev5"
and source.get("recordId") == 3_273_935
and source.get("recordDoi")
== "https://doi.org/10.5281/zenodo.3273935",
"pinned SXS source drifted",
)
license_data = exact_keys(
source["license"],
{"status", "spdx", "attributionRequired"},
"$.source.license",
)
require(
license_data["status"] == "declared-in-pinned-zenodo-record"
and license_data["spdx"] == "CC-BY-4.0"
and boolean(
license_data["attributionRequired"],
"$.source.license.attributionRequired",
)
is True,
"source license declaration drifted",
)
require(
source.get("waveformDataset")
== "Extrapolated_N2.dir/Y_l2_m2.dat",
"waveform mode/extrapolation order drifted",
)
artifacts = source.get("artifacts")
require(
isinstance(artifacts, dict) and set(artifacts) == set(PINNED_SOURCE),
"source artifact roles changed",
)
for role, (byte_length, md5, expected_sha256) in PINNED_SOURCE.items():
artifact = exact_keys(
artifacts[role],
{"url", "path", "byteLength", "md5", "sha256"},
f"$.source.artifacts.{role}",
)
expected_path = PINNED_SOURCE_PATHS[role]
require(
artifact.get("byteLength") == byte_length
and artifact.get("md5") == md5
and artifact.get("sha256") == expected_sha256,
f"{role} pinned size/MD5/SHA-256 drifted",
)
require(
artifact.get("path") == expected_path
and artifact.get("url")
== (
"https://zenodo.org/api/records/3273935/files/"
f"{expected_path}/content"
),
f"{role} source URL is not pinned",
)
sha256_text(artifact["sha256"], f"$.source.artifacts.{role}.sha256")
units = exact_keys(
manifest["units"],
{
"system",
"G",
"c",
"massUnit",
"distanceUnit",
"timeUnit",
"referenceMassDefinition",
"referenceMassTotalInCodeUnits",
},
"$.units",
)
require(
units["system"] == "geometric"
and finite(units["G"], "$.units.G") == 1.0
and finite(units["c"], "$.units.c") == 1.0
and units["massUnit"] == "M"
and units["distanceUnit"] == "M"
and units["timeUnit"] == "M",
"geometric-unit ABI changed",
)
nonempty_string(
units["referenceMassDefinition"],
"$.units.referenceMassDefinition",
)
require(
math.isclose(
finite(
units["referenceMassTotalInCodeUnits"],
"$.units.referenceMassTotalInCodeUnits",
),
PINNED_REFERENCE_MASS_TOTAL,
rel_tol=0.0,
abs_tol=1.0e-12,
),
"$.units.referenceMassTotalInCodeUnits drifted from pinned metadata",
)
verify_physical_system(manifest)
verify_time_and_events(manifest)
verify_dynamics_contract(manifest)
verify_renderer_contract(manifest)
verify_generation_contract(manifest)
time_reference = manifest["timeReference"]
require(
time_reference.get("protocolZeroEvent")
== "maximum amplitude of Extrapolated_N2 h(2,2)",
"protocol zero is not the waveform peak",
)
require(
"distinct source coordinates"
in str(time_reference.get("alignmentCaveat", "")),
"waveform/horizon time-coordinate caveat is missing",
)
renderer = manifest["rendererAdapter"]
require(
renderer.get("shaderBundleId") == "binary-approx-v1"
and renderer.get("lightPropagation") == "weak-field-fast-light"
and renderer.get("nearZoneMetricConsumed") is False,
"renderer adapter boundary drifted",
)
def verify_samples(manifest: dict[str, Any]) -> dict[str, Any]:
asset = manifest["dynamics"]["asset"]
require(asset.get("uri") == "binary-sxs-bbh-0001-v2.samples.json", "asset URI changed")
require(asset.get("columns") == EXPECTED_COLUMNS, "manifest columns changed")
samples_path = MANIFEST.parent / asset["uri"]
require(samples_path.is_file(), "sample asset is missing")
require(
samples_path.stat().st_size == asset["byteLength"],
"sample byte length mismatch",
)
require(sha256(samples_path) == asset["sha256"], "sample SHA-256 mismatch")
payload = strict_json(samples_path)
exact_keys(payload, {"schema", "columns", "samples"}, "$samples")
require(
payload["schema"] == "blackhole.binary-dynamics-samples/v1",
"sample schema changed",
)
require(payload["columns"] == EXPECTED_COLUMNS, "sample columns changed")
rows = payload["samples"]
require(isinstance(rows, list), "samples must be an array")
require(len(rows) == asset["sampleCount"], "sample count mismatch")
require(len(rows) >= 100, "track is implausibly sparse")
previous_time = -math.inf
previous_phase = -math.inf
previous_blend = -math.inf
invalid_seen = False
first_invalid_values: tuple[float, float] | None = None
for index, row in enumerate(rows):
require(
isinstance(row, list) and len(row) == len(EXPECTED_COLUMNS),
f"sample {index} has the wrong width",
)
values = [
finite(value, f"samples[{index}][{column}]")
for column, value in enumerate(row[:6])
]
validity = row[6]
require(validity in (0, 1) and not isinstance(validity, bool), f"sample {index} validity is invalid")
require(values[0] > previous_time, f"sample {index} time does not increase")
require(values[1] > 0, f"sample {index} separation is invalid")
require(values[2] >= previous_phase, f"sample {index} phase runs backward")
require(
0 <= values[5] <= 1 and values[5] >= previous_blend,
f"sample {index} render blend is invalid",
)
if validity == 0:
if not invalid_seen:
first_invalid_values = (values[1], values[2])
invalid_seen = True
require(
first_invalid_values is not None
and math.isclose(values[1], first_invalid_values[0], abs_tol=1e-9)
and math.isclose(values[2], first_invalid_values[1], abs_tol=1e-9),
f"sample {index} invents post-horizon A/B motion",
)
else:
require(not invalid_seen, f"sample {index} restores expired horizons")
previous_time = values[0]
previous_phase = values[2]
previous_blend = values[5]
require(
math.isclose(rows[0][0], manifest["dynamics"]["firstTimeM"], abs_tol=1e-9)
and math.isclose(rows[-1][0], manifest["dynamics"]["finalTimeM"], abs_tol=1e-9),
"sample range disagrees with manifest",
)
require(rows[0][5] == 0 and rows[-1][5] == 1, "render transition is incomplete")
return payload
def verify_source_acceptance(
manifest: dict[str, Any],
payload: dict[str, Any],
) -> None:
rows = payload["samples"]
events = manifest["events"]
ordered = [
finite(events[name]["tProtocolM"], f"events.{name}.tProtocolM")
for name in (
"relaxation",
"individualHorizonsLast",
"commonApparentHorizonFirst",
"waveformPeak",
"playbackEnd",
)
]
require(
all(current > previous for previous, current in zip(ordered, ordered[1:])),
"physical/source events are not ordered",
)
require(ordered[3] == 0, "waveform peak must be protocol t=0")
peak = linear_sample(rows, 0.0)
peak_amplitude = math.hypot(peak[3], peak[4])
require(
math.isclose(
peak_amplitude,
manifest["timeReference"]["waveformPeakAmplitude"],
rel_tol=0,
abs_tol=2e-9,
),
"bundled h22 peak amplitude disagrees with source",
)
sampled_peak = max(
rows,
key=lambda row: math.hypot(float(row[3]), float(row[4])),
)
require(
math.isclose(sampled_peak[0], 0.0, abs_tol=1e-12),
"bundled waveform maximum is not at protocol t=0",
)
remnant = manifest["physicalSystem"]["remnant"]
mass = finite(remnant["massFraction"], "remnant.massFraction")
spin = [finite(value, "remnant.dimensionlessSpin") for value in remnant["dimensionlessSpin"]]
require(
math.isclose(mass, PINNED_REMNANT_MASS, abs_tol=1e-12),
"remnant mass disagrees with pinned metadata",
)
require(
math.isclose(spin[2], PINNED_REMNANT_SPIN_Z, abs_tol=1e-12),
"remnant spin disagrees with pinned metadata",
)
final_diagnostic = remnant["finalHorizonDiagnostic"]
require(
abs(final_diagnostic["massFraction"] - mass) / mass < 1e-3,
"metadata and final horizon mass differ by >= 0.1%",
)
require(
abs(final_diagnostic["dimensionlessSpin"][2] - spin[2]) / spin[2] < 1e-3,
"metadata and final horizon spin differ by >= 0.1%",
)
measured = manifest["dynamics"]["measuredMaxInterpolationError"]
declared = manifest["dynamics"]["declaredMaxInterpolationError"]
require(
measured["orbitalPhaseUnwrappedRad"] < 0.01,
"orbital phase interpolation residual exceeds 0.01 rad",
)
for channel in (
"separationM",
"orbitalPhaseUnwrappedRad",
"h22Real",
"h22Imag",
"renderTopologyBlend",
):
require(
0 <= measured[channel] <= declared[channel],
f"{channel} measured interpolation error exceeds declaration",
)
def verify_playback(manifest: dict[str, Any]) -> None:
playback = exact_keys(
manifest["playback"],
{
"cycleDurationSecondsAtNominalRate",
"endHoldSeconds",
"loop",
"scrubCoordinate",
"slowMotion",
},
"$.playback",
)
require(playback.get("scrubCoordinate") == "linear protocol time", "scrub coordinate changed")
require(
boolean(playback.get("loop"), "$.playback.loop") is True,
"binary playback must loop",
)
cycle_duration = finite(
playback.get("cycleDurationSecondsAtNominalRate"),
"$.playback.cycleDurationSecondsAtNominalRate",
)
require(