Skip to content

Commit 07e2b2b

Browse files
committed
xed accuracy check
1 parent c4b85e2 commit 07e2b2b

3 files changed

Lines changed: 98 additions & 26 deletions

File tree

ABCMB/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def add_derived_parameters(self, param_in : dict) -> dict:
361361

362362
Neff_raw = (rho_nu+rho_extra)/rho_g * (8./7.) * (11./4.)**(4./3.) # Uncorrected Neff using T_nu_massive today
363363
rho_nu_early = 7/8 * (params["N_nu_massless"] + params["N_nu_massive"]) * params["T_nu_massless"]**4 * rho_g # Correct using massless neutrino temp.
364-
params["Neff"] = (rho_nu_tot+rho_extra)/rho_g * (8./7.) * (11./4.)**(4./3.)
364+
params["Neff"] = (rho_nu_early+rho_extra)/rho_g * (8./7.) * (11./4.)**(4./3.)
365365
params["N_nu_massless"] = params["N_nu_massless"] + params["Neff"] - Neff_raw # Add difference to massless sector.
366366

367367
if self.bbn_type.lower() == "table":
@@ -466,11 +466,11 @@ def add_derived_parameters(self, param_in : dict) -> dict:
466466
rho1nu = 7/8 * (4/11)**(4/3) * rho_g
467467

468468
params['N_nu_massless'] = (params["Neff"] - rho_extra/rho1nu) * ((4/11)**(1/3) / params["T_nu_massless"])**4
469-
if params['N_nu_massless'] < 0:
470-
print("ABCMB got a negative N_nu_massless. This is most likely because you included an extra relativistic fluid but did not\n"
471-
+"account for its contribution to Neff when inputting Neff. For this reason when studying BSM radiation we recommend inputting\n"
472-
+"N_nu_massless and T_nu_massless instead of Neff to safely fix the neutrino contributions.")
473-
sys.exit()
469+
# if params['N_nu_massless'] < 0:
470+
# print("ABCMB got a negative N_nu_massless. This is most likely because you included an extra relativistic fluid but did not\n"
471+
# +"account for its contribution to Neff when inputting Neff. For this reason when studying BSM radiation we recommend inputting\n"
472+
# +"N_nu_massless and T_nu_massless instead of Neff to safely fix the neutrino contributions.")
473+
# sys.exit()
474474

475475
# Loop over matter fluids to compute total matter density today.
476476
rho_m = 0.

Module_Tests/spectrum_test.ipynb

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"name": "stderr",
2222
"output_type": "stream",
2323
"text": [
24-
"ERROR:2025-12-01 13:56:42,161:jax._src.xla_bridge:487: Jax plugin configuration error: Exception when calling jax_plugins.xla_cuda12.initialize()\n",
24+
"ERROR:2025-12-01 16:24:48,469:jax._src.xla_bridge:487: Jax plugin configuration error: Exception when calling jax_plugins.xla_cuda12.initialize()\n",
2525
"Traceback (most recent call last):\n",
2626
" File \"/ext3/miniforge3/lib/python3.12/site-packages/jax/_src/xla_bridge.py\", line 485, in discover_pjrt_plugins\n",
2727
" plugin_module.initialize()\n",
@@ -50,7 +50,7 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": 3,
53+
"execution_count": 4,
5454
"id": "e6a32b4c-2b9b-44d8-acd8-40d337ff4469",
5555
"metadata": {},
5656
"outputs": [],
@@ -69,6 +69,24 @@
6969
"from ABCMB.hyrex import hyrex"
7070
]
7171
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": 15,
75+
"id": "9b915a2c-c524-4a6d-a8c0-5908b5791719",
76+
"metadata": {},
77+
"outputs": [],
78+
"source": [
79+
"from pytests import accuracy_test"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"id": "74c70669-5a37-4c9b-98e4-74c4ab562b60",
85+
"metadata": {},
86+
"source": [
87+
"## accuracy_test.test_accuracy_checker()"
88+
]
89+
},
7290
{
7391
"cell_type": "markdown",
7492
"id": "9be5e9c8-6f25-4f5e-9f15-bf9b3b0b81d9",
@@ -79,10 +97,43 @@
7997
},
8098
{
8199
"cell_type": "code",
82-
"execution_count": 49,
100+
"execution_count": 22,
83101
"id": "ee2e203f-8066-4223-a354-1d7c0050856c",
84102
"metadata": {},
85-
"outputs": [],
103+
"outputs": [
104+
{
105+
"data": {
106+
"text/plain": [
107+
"{'A_s': 2.12424e-09,\n",
108+
" 'Delta_z_reion': 0.5,\n",
109+
" 'Delta_z_reion_He': 0.5,\n",
110+
" 'H0': Array(2.19141544e-18, dtype=float64),\n",
111+
" 'N_nu_massive': 1,\n",
112+
" 'N_nu_massless': Array(2.00200977, dtype=float64),\n",
113+
" 'Neff': Array(3.04399998, dtype=float64),\n",
114+
" 'R_b': Array(0.1475945, dtype=float64),\n",
115+
" 'R_nu': Array(0.40874594, dtype=float64),\n",
116+
" 'TCMB0': 0.000234865418,\n",
117+
" 'T_nu_massive': 0.71611,\n",
118+
" 'T_nu_massless': Array(0.71636856, dtype=float64, weak_type=True),\n",
119+
" 'YHe': 0.245,\n",
120+
" 'h': 0.6762,\n",
121+
" 'm_nu_massive': Array(0.06, dtype=float64, weak_type=True),\n",
122+
" 'n_s': 0.9709,\n",
123+
" 'omega_Lambda': Array(0.30475991, dtype=float64),\n",
124+
" 'omega_b': 0.0225,\n",
125+
" 'omega_cdm': 0.1293,\n",
126+
" 'omega_m': Array(0.15244471, dtype=float64),\n",
127+
" 'omega_r': Array(4.18259418e-05, dtype=float64),\n",
128+
" 'z_reion': 11.0,\n",
129+
" 'z_reion_He': 3.5}"
130+
]
131+
},
132+
"execution_count": 22,
133+
"metadata": {},
134+
"output_type": "execute_result"
135+
}
136+
],
86137
"source": [
87138
"params = {\n",
88139
" 'h': 0.6762,\n",
@@ -94,9 +145,9 @@
94145
" 'YHe': 0.245,\n",
95146
" 'TCMB0': 2.34865418e-4,\n",
96147
" #'T_nu_massless' : 0.71636,\n",
97-
" #'N_nu_massless' : 2,\n",
148+
" 'N_nu_massless' : 2,\n",
98149
" 'N_nu_massive': 1,\n",
99-
" #'T_nu_massive': 0.71611,\n",
150+
" 'T_nu_massive': 0.71611,\n",
100151
" #'m_nu_massive': 0.06,\n",
101152
" \"z_reion\": 11.,\n",
102153
" \"Delta_z_reion\": 0.5,\n",
@@ -125,9 +176,30 @@
125176
"\n",
126177
"#model = main.Model(user_species=user_species, input_specs=specs, return_PTBG=True, bbn_type=\"linX\")\n",
127178
"model = main.Model(user_species=user_species, input_specs=specs, return_PTBG=True)\n",
128-
"#params = eqx.filter_jit(model.add_derived_parameters)(params)\n",
179+
"params = eqx.filter_jit(model.add_derived_parameters)(params)\n",
129180
"#params = model.add_derived_parameters(params)\n",
130-
"#params"
181+
"params"
182+
]
183+
},
184+
{
185+
"cell_type": "code",
186+
"execution_count": 66,
187+
"id": "b834848e-af29-480e-89db-f22e75d2b284",
188+
"metadata": {},
189+
"outputs": [
190+
{
191+
"data": {
192+
"text/plain": [
193+
"Array(0.00611772, dtype=float64)"
194+
]
195+
},
196+
"execution_count": 66,
197+
"metadata": {},
198+
"output_type": "execute_result"
199+
}
200+
],
201+
"source": [
202+
"params[\"N_nu_massless\"] * params[\"T_nu_massless\"]**4 / (4./11.)**(4/3)"
131203
]
132204
},
133205
{

pytests/accuracy_test.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_accuracy_checker(h = 0.6762):
2727
# Setup
2828

2929
params = {
30-
'h': 0.6762,
30+
'h': h,
3131
'omega_cdm': 0.1193,
3232
'omega_b': 0.0225,
3333
'A_s': 2.12424e-9,
@@ -62,7 +62,7 @@ def test_accuracy_checker(h = 0.6762):
6262
user_species=user_species,
6363
input_specs=specs
6464
)
65-
params = model.add_derived_parameters(params)
65+
full_params = model.add_derived_parameters(params)
6666

6767
# CLASS
6868
CLASS_params = {
@@ -71,14 +71,14 @@ def test_accuracy_checker(h = 0.6762):
7171
"l_max_scalars" : ellmax,
7272
"P_k_max_1/Mpc" : specs["output_k_max"],
7373
"lensing" : "yes" if specs["lensing"] else "no",
74-
"H0": params["h"]*100,
75-
"omega_b": params["omega_b"],
76-
"omega_cdm": params["omega_cdm"],
77-
"A_s" : params["A_s"],
78-
"n_s" : params["n_s"],
79-
"N_ur": params["Neff"],
80-
"YHe": params["YHe"],
81-
"N_ncdm": params["N_nu_massive"],
74+
"H0": full_params["h"]*100,
75+
"omega_b": full_params["omega_b"],
76+
"omega_cdm": full_params["omega_cdm"],
77+
"A_s" : full_params["A_s"],
78+
"n_s" : full_params["n_s"],
79+
"N_ur": full_params["Neff"],
80+
"YHe": full_params["YHe"],
81+
"N_ncdm": full_params["N_nu_massive"],
8282
#"reio_parametrization" : "reio_none",
8383
"reio_parametrization" : "reio_camb",
8484
"z_reio" : 11,
@@ -98,8 +98,8 @@ def test_accuracy_checker(h = 0.6762):
9898

9999
CLASS_Model = Class()
100100
CLASS_Model.set(CLASS_params)
101-
if params["N_nu_massive"] > 0:
102-
CLASS_Model.set({"m_ncdm": params["m_nu_massive"], "T_ncdm": params["T_nu_massive"]})
101+
if full_params["N_nu_massive"] > 0:
102+
CLASS_Model.set({"m_ncdm": full_params["m_nu_massive"], "T_ncdm": full_params["T_nu_massive"]})
103103

104104
CLASS_Model.compute()
105105
if specs["lensing"]:

0 commit comments

Comments
 (0)