nmbackend 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. nmbackend/__init__.py +22 -0
  2. nmbackend/adapters/__init__.py +4 -0
  3. nmbackend/adapters/rift.py +95 -0
  4. nmbackend/constants.py +55 -0
  5. nmbackend/cooling/README.md +159 -0
  6. nmbackend/cooling/__init__.py +13 -0
  7. nmbackend/cooling/build_nscool.sh +51 -0
  8. nmbackend/cooling/isothermal.py +76 -0
  9. nmbackend/cooling/nscool_nmbackend.patch +310 -0
  10. nmbackend/cooling/physics/__init__.py +18 -0
  11. nmbackend/cooling/physics/_spline.py +71 -0
  12. nmbackend/cooling/physics/blanket.py +66 -0
  13. nmbackend/cooling/physics/conduct.py +196 -0
  14. nmbackend/cooling/physics/core_conduct.py +68 -0
  15. nmbackend/cooling/physics/core_nu.py +268 -0
  16. nmbackend/cooling/physics/crust.py +113 -0
  17. nmbackend/cooling/physics/crust_nu.py +93 -0
  18. nmbackend/cooling/physics/curve.py +42 -0
  19. nmbackend/cooling/physics/envelope.py +37 -0
  20. nmbackend/cooling/physics/gaps.py +164 -0
  21. nmbackend/cooling/physics/geometry.py +131 -0
  22. nmbackend/cooling/physics/heat.py +125 -0
  23. nmbackend/cooling/physics/native.py +138 -0
  24. nmbackend/cooling/physics/reference.py +53 -0
  25. nmbackend/cooling/physics/star.py +225 -0
  26. nmbackend/cooling/physics/superfluid.py +41 -0
  27. nmbackend/cooling/physics/whole.py +136 -0
  28. nmbackend/cooling/runner.py +583 -0
  29. nmbackend/cooling/validate.py +120 -0
  30. nmbackend/data/crust_sly_dh2001.dat +81 -0
  31. nmbackend/data/frib_scenario_ladder.yaml +100 -0
  32. nmbackend/durca.py +111 -0
  33. nmbackend/ejecta.py +614 -0
  34. nmbackend/eos/__init__.py +19 -0
  35. nmbackend/eos/base.py +523 -0
  36. nmbackend/eos/compose.py +251 -0
  37. nmbackend/eos/coolcomp.py +67 -0
  38. nmbackend/eos/crust.py +318 -0
  39. nmbackend/eos/ddrmf.py +388 -0
  40. nmbackend/eos/hybrid.py +173 -0
  41. nmbackend/eos/leptons.py +74 -0
  42. nmbackend/eos/metamodel.py +303 -0
  43. nmbackend/eos/polytrope.py +33 -0
  44. nmbackend/eos/rmft.py +450 -0
  45. nmbackend/eos/skyrme.py +352 -0
  46. nmbackend/inference/__init__.py +13 -0
  47. nmbackend/inference/fisher.py +174 -0
  48. nmbackend/inference/synthetic.py +83 -0
  49. nmbackend/ipad.py +102 -0
  50. nmbackend/lab_likelihood.py +587 -0
  51. nmbackend/nscool_io.py +112 -0
  52. nmbackend/postmerger.py +264 -0
  53. nmbackend/priors/__init__.py +16 -0
  54. nmbackend/priors/bridge.py +437 -0
  55. nmbackend/priors/bridge_jax.py +435 -0
  56. nmbackend/priors/gp_pca.py +325 -0
  57. nmbackend/reference/__init__.py +11 -0
  58. nmbackend/reference/reprimand.py +108 -0
  59. nmbackend/reference/scipy_tov.py +289 -0
  60. nmbackend/rift/__init__.py +26 -0
  61. nmbackend/rift/compressed.py +194 -0
  62. nmbackend/rift/evidence.py +276 -0
  63. nmbackend/rift/sequence.py +428 -0
  64. nmbackend/rotating/__init__.py +7 -0
  65. nmbackend/rotating/rns.py +197 -0
  66. nmbackend/rotating/tabulated.py +249 -0
  67. nmbackend/thermal/__init__.py +1 -0
  68. nmbackend/thermal/diffusion.py +86 -0
  69. nmbackend/tov/__init__.py +15 -0
  70. nmbackend/tov/central.py +72 -0
  71. nmbackend/tov/family.py +155 -0
  72. nmbackend/tov/phase_transition.py +93 -0
  73. nmbackend/tov/solver.py +475 -0
  74. nmbackend/validation/__init__.py +5 -0
  75. nmbackend/validation/model_diagnostic.py +67 -0
  76. nmbackend/validation/reference_matrix.py +216 -0
  77. nmbackend-0.4.0.dist-info/METADATA +168 -0
  78. nmbackend-0.4.0.dist-info/RECORD +81 -0
  79. nmbackend-0.4.0.dist-info/WHEEL +5 -0
  80. nmbackend-0.4.0.dist-info/licenses/LICENSE +21 -0
  81. nmbackend-0.4.0.dist-info/top_level.txt +1 -0
nmbackend/nscool_io.py ADDED
@@ -0,0 +1,112 @@
1
+ """NSCool star EOS file ("NEW" version, like NSCool's EOS/APR_EOS_Cat.dat).
2
+
3
+ Layout, read by NSCool ``precool.f`` (get_core_chemistry) and ``TOV/TOV.f``
4
+ (subroutine eos):
5
+
6
+ * line 1: ``6 Imax Icore``; lines 2-7 text (TOV.f skips exactly 6 lines);
7
+ * Icore core rows, densest first, 17 columns: rho [g cm^-3], P [dyn cm^-2],
8
+ n_B [fm^-3], Ye, Ymu, Yn, Yp, Yla, Ysm, Ys0, Ysp, then m*/m of p, n, la,
9
+ sm, s0, sp (hyperon columns zero);
10
+ * crust rows, densest first: rho, P, n_B.
11
+
12
+ The rows are the nodes of the model's own EOSTable, so TOV.f integrates the
13
+ same p(eps) as nmbackend. The table must be built with the SLy crust
14
+ (``crust="sly"``, the paper-6 default) at join density ``n_t``. Core rows
15
+ are the uniform-matter nodes above the crust-core power-law segment of
16
+ :func:`nmbackend.eos.crust.attach_crust`; their composition is interpolated
17
+ (linear in n) from a :class:`nmbackend.eos.coolcomp.CoolingComposition`.
18
+
19
+ Crust rows carry no A_cell, A_ion, Z: TOV.f reads only three columns, and
20
+ NSCool takes the crust chemistry from its separate crust file.
21
+ """
22
+ from __future__ import annotations
23
+
24
+ import numpy as np
25
+
26
+ from .eos.crust import (N_CRUST_PTS, N_SEG_PTS, N_T_DEFAULT,
27
+ _DYN_CM2_TO_MEVFM3, _G_CM3_TO_MEVFM3)
28
+
29
+ __all__ = ["write_tables", "read_star_eos", "MAX_CORE_ROWS", "MAX_ROWS"]
30
+
31
+ MAX_CORE_ROWS = 500 # NSCool precool.f arrays
32
+ MAX_ROWS = 1000 # TOV.f read limit
33
+ _FMT = "{:13.6E}"
34
+ _COLS = ("Rho Press nbar Ye Ymu Yn Yp Yla Ysm Ys0 Ysp "
35
+ "mstp mstn mstla mstsm msts0 mstsp")
36
+
37
+
38
+ def _core_start(n, n_t):
39
+ """Index of the first core node of a SLy-crust table (see module doc)."""
40
+ i = N_CRUST_PTS + N_SEG_PTS
41
+ if len(n) <= i or abs(n[N_CRUST_PTS - 1] / n_t - 1.0) > 0.05:
42
+ raise ValueError(f"table does not have the SLy crust at n_t={n_t}")
43
+ return i
44
+
45
+
46
+ def write_tables(table, composition, crust=N_T_DEFAULT, path="EOS_Cat.dat",
47
+ title="nmbackend EOS", n_max=None):
48
+ """Write the NSCool star EOS file for one EOS draw.
49
+
50
+ ``table``: EOSTable built with the SLy crust joined at ``crust`` = n_t
51
+ (fm^-3). ``composition``: CoolingComposition of the same model and
52
+ parameters, covering the core rows. ``n_max`` (fm^-3), e.g. the central
53
+ density of the maximum-mass star: rows above the first node at or beyond
54
+ it are dropped. Rows past M_max can carry a pressure plateau or, for
55
+ Skyrme, a negative m*_n; with ``n_max`` they are not written or checked.
56
+
57
+ Returns dict(path, icore, imax, n_core, rho_core), where n_core and
58
+ rho_core are the least dense core row (fm^-3, g cm^-3). NSCool's
59
+ ``rhocore`` should not be below rho_core: under it, NSCool extrapolates
60
+ the core composition from the two least dense core rows. Raises
61
+ ValueError for NaN tables (rejected cores), non-monotone rows or tables
62
+ beyond NSCool's row limits."""
63
+ n = np.asarray(table.n, float)
64
+ rho = np.asarray(table.eps_mevfm3, float) / _G_CM3_TO_MEVFM3
65
+ P = np.asarray(table.p_mevfm3, float) / _DYN_CM2_TO_MEVFM3
66
+ if n_max is not None:
67
+ k = min(int(np.searchsorted(n, n_max)) + 1, len(n))
68
+ n, rho, P = n[:k], rho[:k], P[:k]
69
+ if not np.all(np.isfinite(n) & np.isfinite(rho) & np.isfinite(P)):
70
+ raise ValueError("non-finite EOS table (rejected core)")
71
+ ic = _core_start(n, crust)
72
+ icore, imax = len(n) - ic, len(n)
73
+ if icore > MAX_CORE_ROWS or imax > MAX_ROWS:
74
+ raise ValueError(f"{icore} core / {imax} rows; NSCool limits are "
75
+ f"{MAX_CORE_ROWS} / {MAX_ROWS}")
76
+ nc = np.asarray(composition.n, float)
77
+ if n[ic] < nc[0] or n[-1] > nc[-1]:
78
+ raise ValueError(f"composition covers n = {nc[0]:.3g}-{nc[-1]:.3g}, "
79
+ f"core rows {n[ic]:.3g}-{n[-1]:.3g} fm^-3")
80
+ f = lambda a: np.interp(n[ic:], nc, np.asarray(a, float))
81
+ x_p, x_e, x_mu = f(composition.x_p), f(composition.x_e), f(composition.x_mu)
82
+ if np.max(np.abs(x_p - x_e - x_mu)) > 1e-3:
83
+ raise ValueError("composition not charge neutral")
84
+ zero = np.zeros_like(x_p)
85
+ core = np.stack([rho[ic:], P[ic:], n[ic:], x_e, x_mu, 1.0 - x_p, x_p,
86
+ zero, zero, zero, zero, f(composition.mst_p),
87
+ f(composition.mst_n), zero, zero, zero, zero], axis=1)
88
+ rows = [" ".join(_FMT.format(v) for v in r) for r in core[::-1]]
89
+ rows += [" ".join(_FMT.format(v) for v in r)
90
+ for r in np.stack([rho[:ic], P[:ic], n[:ic]], axis=1)[::-1]]
91
+ chk = np.array([[float(v) for v in r.split()[:3]] for r in rows])
92
+ if not np.all(np.diff(chk, axis=0) < 0.0):
93
+ raise ValueError("rho, P, n_B not strictly monotone after formatting")
94
+ head = [f"{6:7d}{imax:7d}{icore:7d} Itext Imax Icore", "",
95
+ f" {title}", "", " " + _COLS,
96
+ " g/cm3 dyne/cm2 #/fm3 (crust rows: rho P nbar only)", ""]
97
+ with open(path, "w") as fh:
98
+ fh.write("\n".join(head + rows) + "\n")
99
+ return dict(path=path, icore=icore, imax=imax, n_core=float(n[ic]),
100
+ rho_core=float(rho[ic]))
101
+
102
+
103
+ def read_star_eos(path):
104
+ """Parse a star EOS file: dict(core=(Icore, 17) array, crust=(Imax-Icore,
105
+ 3) array (first three columns), itext, imax, icore)."""
106
+ with open(path) as fh:
107
+ lines = fh.read().splitlines()
108
+ itext, imax, icore = (int(v) for v in lines[0].split()[:3])
109
+ data = [ln.split() for ln in lines[1 + itext:] if ln.strip()][:imax]
110
+ core = np.array([[float(v) for v in r[:17]] for r in data[:icore]])
111
+ crust = np.array([[float(v) for v in r[:3]] for r in data[icore:]])
112
+ return dict(core=core, crust=crust, itext=itext, imax=imax, icore=icore)
@@ -0,0 +1,264 @@
1
+ """Postmerger observable hooks (pure numpy).
2
+
3
+ Quasi-universal-fit likelihood factors for postmerger observables, usable
4
+ over the same EOS draw pools as the GW/NICER evidence hooks. Design note
5
+ (paper-4 "structural" result): a fit whose regressor is an inspiral-scale
6
+ static (D-tilde, Lambda-tilde, R_1.6) can only re-sharpen information the
7
+ inspiral already carries; genuine high-density reach enters through fit
8
+ RESIDUALS correlating with high-density structure, or through
9
+ threshold-type observables (M_thresh / prompt collapse) keyed to TOV-scale
10
+ properties. Both channel types belong here; a forecast built only on
11
+ statics-regressed f_peak fits is circular.
12
+
13
+ Implemented:
14
+ - ``dtilde`` binary intrinsic tidal response, 2607.15588 Eq. (18)
15
+ - ``FPeakFit`` M_tot f_pk = fit(D-tilde) families, Eqs. (19)-(21)
16
+ - ``STROUD2026_EXP`` verified Tab. II exponential coefficients
17
+ - ``fpeak_lnlike`` Gaussian-in-ln-f likelihood with fit systematic
18
+ - ``MthreshFit`` linear prompt-collapse threshold k = slope C + b
19
+ - ``BAUSWEIN2013`` verified linear fit, C*_1.6 compactness
20
+ - ``KOEPPEL2019_LIN`` verified linear fit, C_TOV compactness
21
+ - ``MthreshNonlinFit`` nonlinear threshold k = a - b/(1 - c C)
22
+ - ``KOEPPEL2019_NONLIN`` verified Koeppel Eq. (4) nonlinear fit
23
+ - ``mthresh_lnlike`` prompt-collapse (non)detection likelihood
24
+
25
+ House rule: every literature coefficient above is verified against the
26
+ source PDF (never memory / web extraction) and pinned by a numeric anchor
27
+ test that the source paper itself quotes. PDF text extraction can drop
28
+ minus signs -- treat every sign as suspect until an anchor confirms it.
29
+ """
30
+ from dataclasses import dataclass
31
+
32
+ import numpy as np
33
+
34
+ # G Msun / c^2 in km: the package constant (IAU 2015 B3 nominal), re-exported
35
+ # (it is in __all__). Until 2026-10-14 this module defined its own rounded
36
+ # 1.4766, which shadowed constants.GMSUN_KM under `from nmbackend.postmerger
37
+ # import *`.
38
+ from .constants import GMSUN_KM
39
+
40
+ __all__ = ["MSUN_S", "GMSUN_KM", "dtilde", "FPeakFit", "STROUD2026_EXP",
41
+ "fpeak_lnlike", "MthreshFit", "BAUSWEIN2013", "KOEPPEL2019_LIN",
42
+ "MthreshNonlinFit", "KOEPPEL2019_NONLIN", "mthresh_lnlike"]
43
+
44
+ #: G Msun / c^3 in seconds.
45
+ MSUN_S = 4.925490947e-6
46
+
47
+
48
+ def dtilde(m1, m2, D1, D2):
49
+ """Binary intrinsic tidal response, 2607.15588 Eq. (18).
50
+
51
+ Same mass weighting as Lambda-tilde; equal masses give
52
+ dtilde(m, m, D, D) = D exactly.
53
+ """
54
+ m1, m2 = np.asarray(m1, float), np.asarray(m2, float)
55
+ D1, D2 = np.asarray(D1, float), np.asarray(D2, float)
56
+ mt5 = (m1 + m2) ** 5
57
+ return (16.0 / 13.0) * ((m1 + 12.0 * m2) * m1**4 * D1
58
+ + (m2 + 12.0 * m1) * m2**4 * D2) / mt5
59
+
60
+
61
+ @dataclass(frozen=True)
62
+ class FPeakFit:
63
+ """A quasi-universal fit M_tot f_pk = form(D-tilde).
64
+
65
+ ``sigma_lnf`` is the EOS-systematic scatter (in ln f) to be added in
66
+ quadrature to any measurement error; treat it as a model parameter of
67
+ the likelihood, not a constant of nature.
68
+ """
69
+ name: str
70
+ form: str # "linear" | "exp" | "power"
71
+ m: float
72
+ b: float
73
+ sigma_lnf: float
74
+ reference: str
75
+
76
+ def mfpk(self, Dt):
77
+ Dt = np.asarray(Dt, dtype=float)
78
+ if self.form == "linear":
79
+ return self.m * Dt + self.b
80
+ if self.form == "exp":
81
+ return self.b * np.exp(-self.m * Dt)
82
+ if self.form == "power":
83
+ return self.b * Dt**self.m
84
+ raise ValueError(self.form)
85
+
86
+ def fpk_hz(self, mtot_msun, Dt):
87
+ """Peak frequency in Hz for total mass ``mtot_msun``."""
88
+ return self.mfpk(Dt) / (np.asarray(mtot_msun, float) * MSUN_S)
89
+
90
+
91
+ #: 2607.15588 Tab. II exponential fit — coefficients verified against the
92
+ #: source PDF 2026-07-24 (m = 3.38e-3 +/- 1.85e-4, b = 5.51e-2 +/- 1.10e-3,
93
+ #: R^2 = 0.811, from Tab. II on PDF page 22).
94
+ #:
95
+ #: sigma_lnf residual refit (2026-07-24). Exact (D-tilde, M f_pk) pairs
96
+ #: CANNOT be reconstructed from the PDF: the only tables are Tab. I (runs:
97
+ #: Model, M_NS, E_GW, J_GW, f_pk, t_BH -- PDF page 18) and Tab. II (fit
98
+ #: coefficients); D-tilde is never tabulated, and the CoRe points that
99
+ #: also enter the fit appear only as markers in Fig. 11. Fallback used:
100
+ #: from Tab. I take the N=8 non-collapsing equal-mass runs with a quoted
101
+ #: f_pk (EOS-II/III/IV/V), form M f_pk = (G M_tot/c^3) f_pk with
102
+ #: M_tot = 2 M_NS; these span M f_pk in [0.0289, 0.0405]. With R^2 = 0.811
103
+ #: the residual scatter is sqrt(1 - R^2) * std(ln M f_pk) = 0.051 (and
104
+ #: sqrt(1-R^2)*std(M f_pk)/mean = 0.050), hence sigma_lnf = 0.051.
105
+ #: CAVEAT: this is a LOWER BOUND -- it uses only the tabulated simulation
106
+ #: subset, whose M f_pk spread (0.029-0.040) is narrower than the full
107
+ #: fitted set. The full Fig. 11 range (M f_pk ~ 0.02-0.06, read off the
108
+ #: axis) with R^2 = 0.811 implies scatter as large as ~0.10-0.13 if the
109
+ #: CoRe points dominate the variance; treat sigma_lnf as uncertain at the
110
+ #: factor-of-2 level and prefer the larger value where conservatism on the
111
+ #: EOS systematic matters. Fit calibrated on ~1.3-1.4 Msun near-equal-mass
112
+ #: binaries.
113
+ STROUD2026_EXP = FPeakFit(
114
+ name="stroud2026-dtilde-exp", form="exp",
115
+ m=3.38e-3, b=5.51e-2, sigma_lnf=0.051,
116
+ reference="Stroud, Radice & Reddy, arXiv:2607.15588, Tab. II",
117
+ )
118
+
119
+
120
+ def fpeak_lnlike(f_obs_hz, sigma_obs_hz, f_pred_hz, sigma_lnf):
121
+ """ln L for an observed peak frequency, Gaussian in ln f.
122
+
123
+ Combines the relative measurement error and the fit's EOS-systematic
124
+ width in quadrature. Broadcasts over draw arrays in ``f_pred_hz``.
125
+ """
126
+ f_obs = float(f_obs_hz)
127
+ sig_ln = np.hypot(float(sigma_obs_hz) / f_obs, float(sigma_lnf))
128
+ z = (np.log(np.asarray(f_pred_hz, float)) - np.log(f_obs)) / sig_ln
129
+ return -0.5 * z**2 - np.log(sig_ln) - 0.5 * np.log(2.0 * np.pi)
130
+
131
+
132
+ # GMSUN_KM (G Msun / c^2 in km) is the package constant, imported above.
133
+
134
+
135
+ @dataclass(frozen=True)
136
+ class MthreshFit:
137
+ """Linear prompt-collapse threshold fit M_thresh = k * M_max with
138
+ k = slope * C + intercept, where C is a compactness built from
139
+ TOV-scale statics. ``sigma_k`` is the fit residual scale in k.
140
+ """
141
+ name: str
142
+ slope: float
143
+ intercept: float
144
+ sigma_k: float
145
+ compactness: str # "C*_1.6" (G Mmax / c^2 R_1.6) or "C_TOV"
146
+ reference: str
147
+
148
+ def k(self, C):
149
+ return self.slope * np.asarray(C, float) + self.intercept
150
+
151
+ def mthresh(self, mmax_msun, radius_km):
152
+ """Threshold total mass [Msun]; ``radius_km`` is R_1.6 or R_TOV
153
+ per ``compactness``."""
154
+ C = GMSUN_KM * np.asarray(mmax_msun, float) / np.asarray(radius_km, float)
155
+ return self.k(C) * np.asarray(mmax_msun, float)
156
+
157
+
158
+ #: Bauswein, Baumgarte & Janka, PRL 111, 131101 (2013), verified against
159
+ #: the arXiv:1307.5191 PDF 2026-07-24: k = -3.606 C*_1.6 + 2.380 with
160
+ #: C*_1.6 = G Mmax / (c^2 R_1.6); maximum residual 0.025 in k. Anchor
161
+ #: check against their table: TMA (Mmax 2.02, R_1.6 13.73) -> 3.23 vs
162
+ #: simulated 3.25; IUF (1.95, 12.57) -> 3.03 vs 3.05.
163
+ BAUSWEIN2013 = MthreshFit(
164
+ name="bauswein2013-C16", slope=-3.606, intercept=2.380, sigma_k=0.025,
165
+ compactness="C*_1.6",
166
+ reference="Bauswein, Baumgarte & Janka, PRL 111, 131101 (2013)",
167
+ )
168
+
169
+ #: Koeppel, Bovard & Rezzolla, ApJL 872, L16 (2019) linear variant:
170
+ #: k = -3.38 C_TOV + 2.43. CAUTION: the PDF text layer drops the minus
171
+ #: sign; the sign is fixed here by their own lowest-order quote
172
+ #: Mth/M_TOV ~ 1.415 at C_TOV ~ 0.30 and by physical monotonicity.
173
+ #: Their nonlinear fit (their Eq. 4) is preferred at extreme compactness
174
+ #: and is NOT yet implemented. sigma_k from their Delta Mth ~ 0.05 Msun
175
+ #: at Mmax ~ 2 -> ~0.025.
176
+ KOEPPEL2019_LIN = MthreshFit(
177
+ name="koeppel2019-linear-CTOV", slope=-3.38, intercept=2.43, sigma_k=0.025,
178
+ compactness="C_TOV",
179
+ reference="Koeppel, Bovard & Rezzolla, ApJL 872, L16 (2019)",
180
+ )
181
+
182
+
183
+ @dataclass(frozen=True)
184
+ class MthreshNonlinFit:
185
+ """Nonlinear prompt-collapse threshold fit, Koeppel-Bovard-Rezzolla
186
+ (2019) Eq. (4):
187
+
188
+ k(C) = Mth / M_TOV = a - b / (1 - c C), a = 2 b / (2 - c),
189
+
190
+ where C is a TOV-scale compactness (C_TOV = G Mmax / c^2 R_TOV). The
191
+ tie a = 2b/(2-c) is imposed by the authors so the black-hole limit
192
+ Mth / M_TOV -> 0 holds at C -> 1/2 (a maximally compact configuration
193
+ is already collapsing); ``a`` is therefore a derived property, not a
194
+ free field, and cannot drift out of sync with (b, c). ``sigma_k`` is
195
+ the fit residual scale in k. Same call surface as ``MthreshFit`` so it
196
+ drops straight into ``mthresh_lnlike``.
197
+ """
198
+ name: str
199
+ b: float
200
+ c: float
201
+ sigma_k: float
202
+ compactness: str # "C_TOV"
203
+ reference: str
204
+
205
+ @property
206
+ def a(self):
207
+ return 2.0 * self.b / (2.0 - self.c)
208
+
209
+ def k(self, C):
210
+ C = np.asarray(C, float)
211
+ return self.a - self.b / (1.0 - self.c * C)
212
+
213
+ def mthresh(self, mmax_msun, radius_km):
214
+ """Threshold total mass [Msun]; ``radius_km`` is R_TOV."""
215
+ C = GMSUN_KM * np.asarray(mmax_msun, float) / np.asarray(radius_km, float)
216
+ return self.k(C) * np.asarray(mmax_msun, float)
217
+
218
+
219
+ #: Koeppel, Bovard & Rezzolla, ApJL 872, L16 (2019) nonlinear threshold fit
220
+ #: (preferred over the linear variant at extreme compactness). Their
221
+ #: Eq. (4), verified against arXiv:1901.09977 PDF (pages 3-4) 2026-07-24:
222
+ #: Mth / M_TOV = a - b/(1 - c C_TOV), a = 2 b/(2 - c),
223
+ #: with b = 1.01, c = 1.34 (=> a = 3.0606). The a = 2b/(2-c) tie is the
224
+ #: authors' imposed black-hole limit Mth/M_TOV -> 0 at C_TOV -> 1/2.
225
+ #: Anchors from the paper: k(0.288) = 1.416 reproduces their lowest-order
226
+ #: quote Mth/M_TOV ~ 1.415 (their Eq. 3, near C_TOV ~ 0.30); k(0.5) = 0
227
+ #: exactly (BH limit); k is monotonically decreasing on C_TOV in
228
+ #: [0.24, 0.35]; it stays within their stated "8% at most" of the linear
229
+ #: variant over that range (7.1% at C_TOV = 0.35) and within ~3% near
230
+ #: C_TOV ~ 0.30. sigma_k as for the linear variant (their Delta Mth ~
231
+ #: 0.05 Msun at Mmax ~ 2 -> ~0.025).
232
+ KOEPPEL2019_NONLIN = MthreshNonlinFit(
233
+ name="koeppel2019-nonlinear-CTOV", b=1.01, c=1.34, sigma_k=0.025,
234
+ compactness="C_TOV",
235
+ reference="Koeppel, Bovard & Rezzolla, ApJL 872, L16 (2019), Eq. (4)",
236
+ )
237
+
238
+
239
+ def _norm_cdf(x):
240
+ from math import erf
241
+ x = np.asarray(x, float)
242
+ return 0.5 * (1.0 + np.vectorize(erf)(x / np.sqrt(2.0)))
243
+
244
+
245
+ def mthresh_lnlike(prompt_collapse, mtot_msun, sigma_mtot_msun,
246
+ mmax_msun, radius_km, fit=BAUSWEIN2013):
247
+ """ln L of observing prompt collapse (or not) at total mass ``mtot``.
248
+
249
+ This is the postmerger channel that carries TOV-scale information
250
+ (paper-4 structural argument): M_thresh is keyed to (Mmax, R) of the
251
+ maximum-mass configuration, which inspiral leaves undetermined.
252
+
253
+ Parameters broadcast over draw arrays in ``mmax_msun``/``radius_km``.
254
+ ``prompt_collapse`` True: L = P(Mtot > M_thresh); False: 1 - that.
255
+ The threshold uncertainty combines the fit residual (sigma_k * Mmax)
256
+ and the measurement error on Mtot in quadrature.
257
+ """
258
+ mth = fit.mthresh(mmax_msun, radius_km)
259
+ sigma = np.hypot(fit.sigma_k * np.asarray(mmax_msun, float),
260
+ float(sigma_mtot_msun))
261
+ z = (float(mtot_msun) - mth) / sigma
262
+ p = _norm_cdf(z)
263
+ p = np.clip(p if prompt_collapse else 1.0 - p, 1e-300, 1.0)
264
+ return np.log(p)
@@ -0,0 +1,16 @@
1
+ """Nonparametric EOS priors.
2
+
3
+ Currently: the constrained Brownian-bridge prior of Gorda, Komoltsev, Kurkela &
4
+ Sunde (arXiv:2512.18044) -- stable, causal, thermodynamically consistent EOS draws
5
+ by construction, bridging a low-density nuclear anchor (our metamodel band) to the
6
+ perturbative-QCD limit. See :mod:`nmbackend.priors.bridge`.
7
+ """
8
+ from .bridge import (kk_volume, sample_point_in_volume, fractal_refine,
9
+ diffuse_mu_of_n, draw_bridge_eos, draw_prior_ensemble,
10
+ pqcd_anchor, PQCD_TABLE)
11
+ from .gp_pca import CoefficientPrior, write_pca_draws, iterative_refinement
12
+
13
+ __all__ = ["kk_volume", "sample_point_in_volume", "fractal_refine",
14
+ "diffuse_mu_of_n", "draw_bridge_eos", "draw_prior_ensemble",
15
+ "pqcd_anchor", "PQCD_TABLE",
16
+ "CoefficientPrior", "write_pca_draws", "iterative_refinement"]