classy-szfast 0.0.9__py3-none-any.whl → 0.0.11__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.
@@ -8,59 +8,69 @@ import numpy as np
8
8
  import time
9
9
 
10
10
  class classy_sz(classy):
11
- use_class_sz_fast_mode = 0 # this is passed in the yaml file
11
+
12
+ use_class_sz_fast_mode = 1 # this is passed in the yaml file
12
13
  use_class_sz_no_cosmo_mode = 0 # this is passed in the yaml file
13
- lensing_lkl = None
14
- # skip_background_and_thermo = True
15
- # ell_factor = False # True for pyactlite and bplike, False for clik
14
+ lensing_lkl = 'ACT'
15
+
16
+ baos = None
16
17
 
17
18
  def initialize(self):
18
19
  """Importing CLASS from the correct path, if given, and if not, globally."""
20
+
19
21
  self.classy_module = self.is_installed()
20
22
  if not self.classy_module:
21
23
  raise NotInstalledError(
22
24
  self.log, "Could not find CLASS_SZ. Check error message above.")
25
+
23
26
  from classy_sz import Class, CosmoSevereError, CosmoComputationError
27
+
24
28
  global CosmoComputationError, CosmoSevereError
29
+
25
30
  self.classy = Class()
26
31
  super(classy,self).initialize()
32
+
33
+
27
34
  # Add general CLASS stuff
28
35
  self.extra_args["output"] = self.extra_args.get("output", "")
36
+
29
37
  if "sBBN file" in self.extra_args:
30
38
  self.extra_args["sBBN file"] = (
31
39
  self.extra_args["sBBN file"].format(classy=self.path))
40
+
32
41
  # Derived parameters that may not have been requested, but will be necessary later
33
42
  self.derived_extra = []
34
43
  self.log.info("Initialized!")
35
44
 
45
+
46
+ ## rename some parameters to avoid conflices
47
+ classy_sz_renames = {
48
+
49
+ 'omega_m':'Omega_m',
50
+ 'Omegam':'Omega_m',
51
+ 'Omega_m':'Omega_m'
52
+ }
53
+ self.renames.update(classy_sz_renames)
54
+
55
+
36
56
  if self.use_class_sz_no_cosmo_mode == 1:
57
+
37
58
  self.log.info("Initializing cosmology part!")
59
+
38
60
  initial_parameters = self.extra_args.copy()
39
- # print("initial_parameters:",initial_parameters)
61
+
40
62
 
41
63
  self.classy.set(initial_parameters)
42
- self.classy.compute_class_szfast()
64
+ self.classy.compute_class_szfast(likelihood_mode=True)
43
65
  self.log.info("cosmology part initialized!")
44
66
 
45
67
 
46
- # print(self.lensing_lkl)
47
- # exit(0)
48
-
49
- # # class_sz default params for lkl
50
- # self.extra_args["output"] = 'tSZ_1h'
51
- # self.extra_args["multipoles_sz"] = 'P15'
52
- # self.extra_args['nlSZ'] = 18
53
68
 
54
69
 
55
- # # here modify if you want to bypass stuff in the class computation
56
- # def calculate(self, state, want_derived=True, **params_values_dict):
57
- # print("Bypassing class_sz")
58
-
70
+ def must_provide(self, **requirements):
59
71
 
60
72
 
61
73
 
62
- def must_provide(self, **requirements):
63
-
64
74
  if "Cl_sz" in requirements:
65
75
  # make sure cobaya still runs as it does for standard classy
66
76
  requirements.pop("Cl_sz")
@@ -246,25 +256,25 @@ class classy_sz(classy):
246
256
  args=[])
247
257
  super().must_provide(**requirements)
248
258
 
259
+
249
260
  # get the required new observable
250
261
  def get_Cl(self, ell_factor=False, units="FIRASmuK2"):
262
+
251
263
  if self.use_class_sz_fast_mode:
264
+
252
265
  return self.get_Clfast(ell_factor=ell_factor)
266
+
253
267
  else:
268
+
254
269
  return self._get_Cl(ell_factor=ell_factor, units=units, lensed=True)
255
270
 
256
271
  def get_Clfast(self,ell_factor = False):
257
- # print('ell_factor:',self.ell_factor)
258
- # exit(0)
272
+
259
273
  cls = {}
260
274
  cls = deepcopy(self._current_state["Cl"])
261
- # ell_factor = self.ell_factor
262
- # print(cls)
263
- # exit(0)
264
- # print('in get clfast:',ell_factor)
265
- # print(cls)
275
+
266
276
  lcp = np.asarray(cls['ell'])
267
- # print(self.lensing_lkl)
277
+
268
278
  if ell_factor==True:
269
279
  cls['tt'] *= (2.7255e6)**2.*(lcp*(lcp+1.))/2./np.pi
270
280
  cls['te'] *= (2.7255e6)**2.*(lcp*(lcp+1.))/2./np.pi
@@ -274,17 +284,18 @@ class classy_sz(classy):
274
284
  cls['tt'] *= (2.7255e6)**2.
275
285
  cls['te'] *= (2.7255e6)**2.
276
286
  cls['ee'] *= (2.7255e6)**2.
277
- # print(cls['tt'][1230])
278
- # print(cls['te'][1230])
279
- # print(cls['ee'][1230])
280
- # exit(0)
287
+
281
288
  if self.lensing_lkl == "SOLikeT":
282
289
  cls['pp'] *= (lcp*(lcp+1.))**2./4.
290
+
283
291
  elif self.lensing_lkl == "ACT":
284
- cls['pp'] *= 1.#(lcp*(lcp+1.))**2./4.
292
+ cls['pp'] *= 1.
293
+
285
294
  else: # here for the planck lensing lkl, using lfactor option gives:
286
295
  cls['pp'] *= (lcp*(lcp+1.))**2.*1./2./np.pi
296
+
287
297
  return cls
298
+
288
299
  # get the required new observable
289
300
  def get_Cl_sz(self):
290
301
  cls = {}
@@ -362,8 +373,9 @@ class classy_sz(classy):
362
373
 
363
374
  # get the required new observable
364
375
  def get_sz_unbinned_cluster_counts(self):
376
+
365
377
  cls = deepcopy(self._current_state["sz_unbinned_cluster_counts"])
366
- # print(cls)
378
+
367
379
  return cls['loglike'],cls['ntot'],cls['rates']
368
380
 
369
381
 
@@ -380,37 +392,53 @@ class classy_sz(classy):
380
392
 
381
393
  # IMPORTANT: this method is imported from cobaya and modified to accomodate the emulators
382
394
  def calculate(self, state, want_derived=True, **params_values_dict):
383
- # Set parameters
395
+
396
+
384
397
  params_values = params_values_dict.copy()
385
- # print('\n\n')
386
- # print('>>> class_sz.py: class/class_sz using params:',params_values)
398
+ # if baos are requested we need to update the relevant flags
399
+ if self.baos:
400
+ params_values.update({'skip_chi':0,'skip_hubble':0})
401
+
387
402
  if 'N_ncdm' in self.extra_args.keys():
403
+
388
404
  if self.extra_args['N_ncdm'] == 3:
405
+
389
406
  str_mncdm = str(params_values['m_ncdm'])
390
407
  params_values['m_ncdm'] = str_mncdm+','+str_mncdm+','+str_mncdm
391
- # print('>>> class_sz.py: class/class_sz using params:',params_values)
392
- # exit(0)
408
+
393
409
  try:
410
+
394
411
  params_values['ln10^{10}A_s'] = params_values.pop("logA")
412
+
395
413
  self.set(params_values)
414
+
396
415
  except KeyError:
416
+
397
417
  self.set(params_values)
418
+
398
419
  # Compute!
399
420
  try:
400
421
  if self.use_class_sz_fast_mode == 1:
401
- # start = time.perf_counter()
422
+
423
+
402
424
  if self.use_class_sz_no_cosmo_mode == 1:
403
- # print(params_values)
425
+
426
+ start_time = time.time()
404
427
  self.classy.compute_class_sz(params_values)
428
+ end_time = time.time()
429
+ # self.log.info("Execution time of class_sz: {:.5f} seconds".format(end_time - start_time))
430
+
405
431
  else:
406
- self.classy.compute_class_szfast()
407
- # end = time.perf_counter()
408
- # print('classy_szfast took:',end-start)
409
- # self.classy.compute_class_szfast()
410
- # elif self.use_class_sz_no_cosmo_mode == 1:
411
- # self.classy.compute_class_sz(params_values)
432
+
433
+ start_time = time.time()
434
+ self.classy.compute_class_szfast(likelihood_mode=True)
435
+ end_time = time.time()
436
+ # self.log.info("Execution time of class_szfast: {:.5f} seconds".format(end_time - start_time))
437
+ # print('pars in classy',self.classy.pars)
412
438
  else:
439
+
413
440
  self.classy.compute()
441
+
414
442
  # "Valid" failure of CLASS: parameters too extreme -> log and report
415
443
  except self.classy_module.CosmoComputationError as e:
416
444
  if self.stop_at_error:
@@ -492,81 +520,15 @@ class classy_sz(classy):
492
520
  if collector.post:
493
521
  state[product] = collector.post(*state[product])
494
522
  # Prepare derived parameters
523
+
495
524
  d, d_extra = self._get_derived_all(derived_requested=want_derived)
525
+
496
526
  if want_derived:
527
+
497
528
  state["derived"] = {p: d.get(p) for p in self.output_params}
498
- # Prepare necessary extra derived parameters
529
+
530
+
499
531
  state["derived_extra"] = deepcopy(d_extra)
500
- # exit(0)
501
-
502
-
503
- # # get the required new observable
504
- # def get_Cl(self,ell_factor=True,units="FIRASmuK2"):
505
- # ell_factor=self.ell_factor
506
- # # if self.tsz.use_class_sz_fast_mode == 1:
507
- # cls = {}
508
- # cls['ell'] = np.arange(20000)
509
- # # print(cls['ell'])
510
- # cls['tt'] = np.zeros(20000)
511
- # cls['te'] = np.zeros(20000)
512
- # cls['ee'] = np.zeros(20000)
513
- # cls['pp'] = np.zeros(20000)
514
- # # if self.tt_spectra is not None:
515
- # nl = len(self.classy.class_szfast.cp_predicted_tt_spectrum)
516
- # # print('nl:',nl)
517
- # cls['tt'][2:nl+2] = (2.7255e6)**2.*self.classy.class_szfast.cp_predicted_tt_spectrum
518
- # if ell_factor==False:
519
- # lcp = np.asarray(cls['ell'][2:nl+2])
520
- # cls['tt'][2:nl+2] *= 1./(lcp*(lcp+1.)/2./np.pi)
521
- #
522
- # # if self.te_spectra is not None:
523
- # cls['te'][2:nl+2] = (2.7255e6)**2.*self.classy.class_szfast.cp_predicted_te_spectrum
524
- # if ell_factor==False:
525
- # lcp = np.asarray(cls['ell'][2:nl+2])
526
- # cls['te'][2:nl+2] *= 1./(lcp*(lcp+1.)/2./np.pi)
527
- # # if self.ee_spectra is not None:
528
- # cls['ee'][2:nl+2] = (2.7255e6)**2.*self.classy.class_szfast.cp_predicted_ee_spectrum
529
- # if ell_factor==False:
530
- # lcp = np.asarray(cls['ell'][2:nl+2])
531
- # cls['ee'][2:nl+2] *= 1./(lcp*(lcp+1.)/2./np.pi)
532
- # # if self.pp_spectra is not None:
533
- # # nl = len(self.pp_spectra[0])
534
- # if self.lensing_lkl == "SOLikeT":
535
- # cls['pp'][2:nl+2] = self.classy.class_szfast.cp_predicted_pp_spectrum/4. ## this is clkk... works for so lensinglite lkl
536
- # else:
537
- # # here for the planck lensing lkl, using lfactor option gives:
538
- # lcp = np.asarray(cls['ell'][2:nl+2])
539
- # cls['pp'][2:nl+2] = self.classy.class_szfast.cp_predicted_pp_spectrum/(lcp*(lcp+1.))**2.
540
- # cls['pp'][2:nl+2] *= (lcp*(lcp+1.))**2./2./np.pi
541
- # return cls
542
-
543
- # def check_ranges(self, z, k):
544
- # return 1
545
-
546
- # IMPORTANT: copied from cobaya and changed.
547
- def get_param(self, p):
548
- translated = self.translate_param(p)
549
- for pool in ["params", "derived", "derived_extra"]:
550
- value = (self.current_state[pool] or {}).get(translated, None)
551
- if p == 'omegam':
552
- print('getting omegam in get_param')
553
- # print(translated)
554
- # print(self.classy.Omega_m())
555
- # exit(0)
556
- return self.classy.Omega_m()
557
- if value is not None:
558
- return value
559
-
560
- raise LoggedError(self.log, "Parameter not known: '%s'", p)
561
- ### ORIGINAL FUNCTION:
562
- # def get_param(self, p):
563
- # translated = self.translate_param(p)
564
- # for pool in ["params", "derived", "derived_extra"]:
565
- # value = (self.current_state[pool] or {}).get(translated, None)
566
- # if value is not None:
567
- # return value
568
- #
569
- # raise LoggedError(self.log, "Parameter not known: '%s'", p)
570
532
 
571
533
 
572
534
 
@@ -10,6 +10,7 @@ from mcfit import TophatVar
10
10
  from scipy.interpolate import CubicSpline
11
11
  import pickle
12
12
 
13
+
13
14
  H_units_conv_factor = {"1/Mpc": 1, "km/s/Mpc": Const.c_km_s}
14
15
 
15
16
 
@@ -33,16 +34,15 @@ def set_verbosity(verbosity):
33
34
 
34
35
 
35
36
 
36
- def update_params_with_defaults(params_values, self):
37
+ def update_params_with_defaults(params_values, default_values):
37
38
  """
38
39
  Update params_values with default values if they don't already exist.
39
40
 
40
41
  Args:
41
42
  params_values (dict): Dictionary containing parameter values.
42
- self (object): The object containing emulator_dict and cosmo_model attributes.
43
+ default_values (dict): Dictionary containing default parameter values.
43
44
  """
44
- # Retrieve default values
45
- default_values = self.emulator_dict[self.cosmo_model]['default']
45
+
46
46
 
47
47
  # Update params_values with default values if key does not exist
48
48
  for key, value in default_values.items():
@@ -52,6 +52,7 @@ def update_params_with_defaults(params_values, self):
52
52
 
53
53
  class Class_szfast(object):
54
54
  def __init__(self,
55
+ params_settings = {},
55
56
  #lowring=False, some options if needed
56
57
  **kwargs):
57
58
  # some parameters
@@ -59,7 +60,11 @@ class Class_szfast(object):
59
60
  # self.lowring = lowring
60
61
 
61
62
 
62
- set_verbosity(kwargs["classy_sz_verbose"])
63
+ self.A_s_fast = 0
64
+ self.logA_fast = 0
65
+
66
+
67
+ set_verbosity(params_settings["classy_sz_verbose"])
63
68
  self.logger = logging.getLogger(__name__)
64
69
 
65
70
 
@@ -95,6 +100,7 @@ class Class_szfast(object):
95
100
  self.cp_ls = np.arange(2,self.cp_lmax+1)
96
101
 
97
102
 
103
+
98
104
 
99
105
  cosmo_model_dict = {0: 'lcdm',
100
106
  1: 'mnu',
@@ -106,7 +112,7 @@ class Class_szfast(object):
106
112
  }
107
113
 
108
114
 
109
- if cosmo_model_dict[kwargs['cosmo_model']] == 'ede-v2':
115
+ if cosmo_model_dict[params_settings['cosmo_model']] == 'ede-v2':
110
116
 
111
117
  self.cp_ndspl_k = 1
112
118
  self.cp_nk = 1000
@@ -128,16 +134,16 @@ class Class_szfast(object):
128
134
 
129
135
 
130
136
 
131
- if (cosmo_model_dict[kwargs['cosmo_model']] == 'ede-v2'):
137
+ if (cosmo_model_dict[params_settings['cosmo_model']] == 'ede-v2'):
132
138
 
133
139
  self.cszfast_pk_grid_zmax = 20.
134
140
  self.cszfast_pk_grid_kmin = 5e-4
135
141
  self.cszfast_pk_grid_kmax = 10.
136
142
  self.cp_kmax = self.cszfast_pk_grid_kmax
137
143
  self.cp_kmin = self.cszfast_pk_grid_kmin
138
- self.logger.info(f">>> using kmin = {self.cp_kmin}")
139
- self.logger.info(f">>> using kmax = {self.cp_kmax}")
140
- self.logger.info(f">>> using zmax = {self.cszfast_pk_grid_zmax}")
144
+ # self.logger.info(f">>> using kmin = {self.cp_kmin}")
145
+ # self.logger.info(f">>> using kmax = {self.cp_kmax}")
146
+ # self.logger.info(f">>> using zmax = {self.cszfast_pk_grid_zmax}")
141
147
 
142
148
  else:
143
149
 
@@ -146,9 +152,9 @@ class Class_szfast(object):
146
152
  self.cszfast_pk_grid_kmax = 50.
147
153
  self.cp_kmax = self.cszfast_pk_grid_kmax
148
154
  self.cp_kmin = self.cszfast_pk_grid_kmin
149
- self.logger.info(f">>> using kmin = {self.cp_kmin}")
150
- self.logger.info(f">>> using kmax = {self.cp_kmax}")
151
- self.logger.info(f">>> using zmax = {self.cszfast_pk_grid_zmax}")
155
+ # self.logger.info(f">>> using kmin = {self.cp_kmin}")
156
+ # self.logger.info(f">>> using kmax = {self.cp_kmax}")
157
+ # self.logger.info(f">>> using zmax = {self.cszfast_pk_grid_zmax}")
152
158
 
153
159
  self.cszfast_pk_grid_z = np.linspace(0.,self.cszfast_pk_grid_zmax,self.cszfast_pk_grid_nz)
154
160
  self.cszfast_pk_grid_ln1pz = np.log(1.+self.cszfast_pk_grid_z)
@@ -160,12 +166,14 @@ class Class_szfast(object):
160
166
 
161
167
  self.cszfast_pk_grid_nk = len(np.geomspace(self.cp_kmin,self.cp_kmax,self.cp_nk)[::self.cp_ndspl_k]) # has to be same as ndimSZ, and the same as dimension of cosmopower pk emulators
162
168
 
163
- for k,v in kwargs.items():
169
+ for k,v in params_settings.items():
164
170
 
165
171
  if k == 'ndim_redshifts':
172
+
166
173
  self.cszfast_pk_grid_nz = v
167
174
  self.cszfast_pk_grid_z = np.linspace(0.,self.cszfast_pk_grid_zmax,self.cszfast_pk_grid_nz)
168
175
  self.cszfast_pk_grid_ln1pz = np.log(1.+self.cszfast_pk_grid_z)
176
+
169
177
  self.cszfast_pk_grid_pknl_flat = np.zeros(self.cszfast_pk_grid_nz*self.cszfast_pk_grid_nk)
170
178
  self.cszfast_pk_grid_pkl_flat = np.zeros(self.cszfast_pk_grid_nz*self.cszfast_pk_grid_nk)
171
179
 
@@ -176,11 +184,11 @@ class Class_szfast(object):
176
184
  if k == 'use_Amod':
177
185
 
178
186
  self.use_Amod = v
179
- self.Amod = kwargs['Amod']
187
+ self.Amod = params_settings['Amod']
180
188
 
181
189
 
182
190
 
183
- if cosmo_model_dict[kwargs['cosmo_model']] == 'ede-v2':
191
+ if cosmo_model_dict[params_settings['cosmo_model']] == 'ede-v2':
184
192
 
185
193
  self.pk_power_fac = self.cszfast_pk_grid_k**-3
186
194
 
@@ -194,14 +202,6 @@ class Class_szfast(object):
194
202
  self.cp_z_interp = np.linspace(0.,20.,5000)
195
203
 
196
204
  self.csz_base = None
197
- # self.csz_base.compute()
198
-
199
-
200
- # z_arr = np.linspace(0.,zmax,nz) # z-array of redshift data [21oct22] oct 26 22: nz = 1000, zmax = 20
201
- #
202
- # nk = self.cp_nk
203
- # ndspl = self.cp_ndspl_k
204
- # k_arr = np.geomspace(self.cp_kmin,self.cp_kmax,nk)[::ndspl] # oct 26 22 : (1e-4,50.,5000), jan 10: ndspl
205
205
 
206
206
 
207
207
  self.cszfast_zgrid_zmin = 0.
@@ -225,16 +225,15 @@ class Class_szfast(object):
225
225
  self.cszfast_gas_pressure_xgrid = np.geomspace(self.cszfast_gas_pressure_xgrid_xmin,
226
226
  self.cszfast_gas_pressure_xgrid_xmax,
227
227
  self.cszfast_gas_pressure_xgrid_nx)
228
-
228
+
229
229
  self.params_for_emulators = {}
230
230
 
231
231
  def find_As(self,params_cp):
232
- # params_cp = self.params_cp
233
- t0 = time.time()
234
232
 
235
233
  sigma_8_asked = params_cp["sigma8"]
236
- update_params_with_defaults(params_cp, self)
237
- # print(params_cp)
234
+
235
+ update_params_with_defaults(params_cp, self.emulator_dict[self.cosmo_model]['default'])
236
+
238
237
  def to_root(ln10_10_As_goal):
239
238
  params_cp["ln10^{10}A_s"] = ln10_10_As_goal[0]
240
239
  params_dict = {}
@@ -247,14 +246,18 @@ class Class_szfast(object):
247
246
  x0=3.046,
248
247
  #tol = 1e-10,
249
248
  method="hybr")
250
- params_cp['ln10^{10}A_s'] = lnA_s.x[0]# .x[0]
249
+
250
+ params_cp['ln10^{10}A_s'] = lnA_s.x[0]
251
+
251
252
  params_cp.pop('sigma8')
252
- # print("T total in find As",time.time()-t0)#self.t_total)
253
- # print(params_cp)
253
+
254
254
  return 1
255
255
 
256
256
 
257
257
  def get_H0_from_thetas(self,params_values):
258
+
259
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
260
+
258
261
  # print(params_values)
259
262
  theta_s_asked = params_values['100*theta_s']
260
263
  def fzero(H0_goal):
@@ -262,7 +265,7 @@ class Class_szfast(object):
262
265
  params_dict = {}
263
266
  for k,v in params_values.items():
264
267
  params_dict[k]=[v]
265
- # print(params_dict)
268
+
266
269
  predicted_der_params = self.cp_der_nn[self.cosmo_model].ten_to_predictions_np(params_dict)
267
270
  return predicted_der_params[0][0]-theta_s_asked
268
271
  sol = optimize.root(fzero,
@@ -319,9 +322,10 @@ class Class_szfast(object):
319
322
  want_pp=1,
320
323
  **params_values_dict):
321
324
 
325
+
322
326
  params_values = params_values_dict.copy()
323
- update_params_with_defaults(params_values, self)
324
327
 
328
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
325
329
 
326
330
  params_dict = {}
327
331
 
@@ -404,7 +408,7 @@ class Class_szfast(object):
404
408
 
405
409
 
406
410
  params_values = params_values_dict.copy()
407
- update_params_with_defaults(params_values, self)
411
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
408
412
 
409
413
 
410
414
  params_dict = {}
@@ -455,57 +459,50 @@ class Class_szfast(object):
455
459
 
456
460
 
457
461
  def calculate_sigma(self,
458
- # cosmo_model = self.cosmo_model,
459
- # z_asked = None,
460
- # r_asked = None,
462
+
461
463
  **params_values_dict):
464
+
462
465
  params_values = params_values_dict.copy()
466
+
463
467
  k = self.cszfast_pk_grid_k
464
- # self.cszfast_pk_grid_z
465
- # print(self.cszfast_pk_grid_pk,np.shape(self.cszfast_pk_grid_pk))
468
+
466
469
  P = self.cszfast_pk_grid_pk
470
+
467
471
  var = P.copy()
472
+
468
473
  dvar = P.copy()
474
+
469
475
  for iz,zp in enumerate(self.cszfast_pk_grid_z):
476
+
470
477
  R, var[:,iz] = TophatVar(k, lowring=True)(P[:,iz], extrap=True)
471
- # dvar[:,iz] = np.gradient(var[:,iz], np.log(R))
472
- # if params_values_dict['sigma_derivative'] == 1: ## need more points here !!
473
- # rds,dvar[:,iz] = TophatVar(k,lowring=True,deriv=1)(P[:,iz]*k,extrap=True)
474
- # else:
475
- # dvar[:,iz] = np.gradient(var[:,iz], R)
476
478
 
477
479
  dvar[:,iz] = np.gradient(var[:,iz], R)
478
- # from inigo: R_vec,self.dvar = TophatVar(k,lowring=True,deriv=1)(P[:,iz]*k,extrap=True)
479
- # from inigo: self.dsigma_vec = self.dvar/(2.*self.sigma_vec)
480
- # print('R:',R,np.shape(R))
481
- # varR = CubicSpline(R, var[:,iz])
482
- # print(zp,np.sqrt(varR(8)))
483
- # print(params_values)
484
- # print('in sigma:',params_values)
485
- # h = params_values['H0']/100.
486
- # var = var.T
487
- # dvar = dvar.T
480
+
481
+ # print(k)
482
+ # print(R)
483
+ # print(k*R)
484
+ # exit(0)
485
+
488
486
 
489
487
  self.cszfast_pk_grid_lnr = np.log(R)
490
488
  self.cszfast_pk_grid_sigma2 = var
489
+
491
490
  self.cszfast_pk_grid_sigma2_flat = var.flatten()
492
491
  self.cszfast_pk_grid_lnsigma2_flat = 0.5*np.log(var.flatten())
493
- # self.cszfast_pk_grid_lnsigma2_flat = self.cszfast_pk_grid_lnsigma2_flat.T
492
+
494
493
  self.cszfast_pk_grid_dsigma2 = dvar
495
494
  self.cszfast_pk_grid_dsigma2_flat = dvar.flatten()
496
- # if z_asked != None and r_asked != None:
497
- # print(z_asked[0],r_asked[0])
498
- # return z_asked, r_asked
499
- # else:
500
- # return 0
495
+
501
496
  return 0
502
497
 
503
498
 
504
499
  def calculate_sigma8_and_der(self,
505
500
  # cosmo_model = self.cosmo_model,
506
501
  **params_values_dict):
502
+
507
503
  params_values = params_values_dict.copy()
508
- update_params_with_defaults(params_values, self)
504
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
505
+
509
506
  # print('in pkl:',params_values)
510
507
 
511
508
  params_dict = {}
@@ -560,7 +557,7 @@ class Class_szfast(object):
560
557
 
561
558
 
562
559
  params_values = params_values_dict.copy()
563
- update_params_with_defaults(params_values, self)
560
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
564
561
 
565
562
 
566
563
  params_dict = {}
@@ -613,7 +610,7 @@ class Class_szfast(object):
613
610
 
614
611
  params_values = self.params_for_emulators
615
612
 
616
- update_params_with_defaults(params_values, self)
613
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
617
614
 
618
615
 
619
616
  params_dict = {}
@@ -629,7 +626,7 @@ class Class_szfast(object):
629
626
 
630
627
  z_asked = z_asked
631
628
  params_dict_pp = params_dict.copy()
632
- update_params_with_defaults(params_dict_pp, self)
629
+ update_params_with_defaults(params_dict_pp, self.emulator_dict[self.cosmo_model]['default'])
633
630
 
634
631
  params_dict_pp['z_pk_save_nonclass'] = [z_asked]
635
632
  predicted_pk_spectrum_z.append(self.cp_pkl_nn[self.cosmo_model].predictions_np(params_dict_pp)[0])
@@ -661,7 +658,7 @@ class Class_szfast(object):
661
658
 
662
659
  params_values = self.params_for_emulators
663
660
 
664
- update_params_with_defaults(params_values, self)
661
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
665
662
 
666
663
 
667
664
  params_dict = {}
@@ -677,7 +674,7 @@ class Class_szfast(object):
677
674
 
678
675
  z_asked = z_asked
679
676
  params_dict_pp = params_dict.copy()
680
- update_params_with_defaults(params_dict_pp, self)
677
+ update_params_with_defaults(params_dict_pp, self.emulator_dict[self.cosmo_model]['default'])
681
678
 
682
679
  params_dict_pp['z_pk_save_nonclass'] = [z_asked]
683
680
  predicted_pk_spectrum_z.append(self.cp_pknl_nn[self.cosmo_model].predictions_np(params_dict_pp)[0])
@@ -694,10 +691,12 @@ class Class_szfast(object):
694
691
 
695
692
 
696
693
  def calculate_hubble(self,
697
- # cosmo_model = self.cosmo_model,
698
- **params_values_dict):
694
+ **params_values_dict):
695
+
699
696
  params_values = params_values_dict.copy()
700
697
 
698
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
699
+
701
700
  params_dict = {}
702
701
  for k,v in zip(params_values.keys(),params_values.values()):
703
702
  params_dict[k]=[v]
@@ -706,11 +705,8 @@ class Class_szfast(object):
706
705
  if isinstance(params_dict['m_ncdm'][0],str):
707
706
  params_dict['m_ncdm'] = [float(params_dict['m_ncdm'][0].split(',')[0])]
708
707
 
709
-
710
-
711
708
  self.cp_predicted_hubble = self.cp_h_nn[self.cosmo_model].ten_to_predictions_np(params_dict)[0]
712
- # print(self.cp_predicted_hubble)
713
- # z_interp =
709
+
714
710
  self.hz_interp = scipy.interpolate.interp1d(
715
711
  self.cp_z_interp,
716
712
  self.cp_predicted_hubble,
@@ -722,36 +718,33 @@ class Class_szfast(object):
722
718
  assume_sorted=False)
723
719
 
724
720
  def calculate_chi(self,
725
- # cosmo_model = self.cosmo_model,
726
721
  **params_values_dict):
727
- # def test_integrand_func(x, alpha, beta, i, j, k, l):
728
- # return x * alpha * beta + i * j * k
729
- #
730
- #
731
- # grid = np.random.random((5000, 2))
732
- #
733
- # res, err = pyquad.quad_grid(test_integrand_func, 0, 1, grid, (1.0, 1.0, 1.0, 1.0))
734
- #
735
- # print(res,err)
736
- # def integrand_chi(z,alpha, beta, i, j, k, l):
737
- # z = z-1.
738
- # return 1./self.get_Hubble(z)
739
- # zmax = 1.
740
- # grid = np.random.random((10000000, 2))
741
- # chiz,err = pyquad.quad_grid(integrand_chi, 1., 1.+zmax, grid, (1.0, 1.0, 1.0, 1.0))
742
- # print(chiz)
722
+
743
723
  params_values = params_values_dict.copy()
744
724
 
725
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
726
+
745
727
  params_dict = {}
728
+
746
729
  for k,v in zip(params_values.keys(),params_values.values()):
730
+
747
731
  params_dict[k]=[v]
748
732
 
749
733
  if 'm_ncdm' in params_dict.keys():
750
734
  if isinstance(params_dict['m_ncdm'][0],str):
751
735
  params_dict['m_ncdm'] = [float(params_dict['m_ncdm'][0].split(',')[0])]
752
736
 
737
+ # deal with different scaling of DA in different model from emulator training
738
+ if self.cosmo_model == 'ede-v2':
739
+
740
+ self.cp_predicted_da = self.cp_da_nn[self.cosmo_model].ten_to_predictions_np(params_dict)[0]
741
+ self.cp_predicted_da = np.insert(self.cp_predicted_da, 0, 0)
742
+
743
+ else:
744
+
745
+ self.cp_predicted_da = self.cp_da_nn[self.cosmo_model].predictions_np(params_dict)[0]
746
+
753
747
 
754
- self.cp_predicted_da = self.cp_da_nn[self.cosmo_model].predictions_np(params_dict)[0]
755
748
  self.chi_interp = scipy.interpolate.interp1d(
756
749
  self.cp_z_interp,
757
750
  self.cp_predicted_da*(1.+self.cp_z_interp),
@@ -763,6 +756,7 @@ class Class_szfast(object):
763
756
  assume_sorted=False)
764
757
 
765
758
  def get_cmb_cls(self,ell_factor=True,Tcmb_uk = Tcmb_uk):
759
+
766
760
  cls = {}
767
761
  cls['ell'] = np.arange(self.cszfast_ldim)
768
762
  cls['tt'] = np.zeros(self.cszfast_ldim)
@@ -774,13 +768,6 @@ class Class_szfast(object):
774
768
  cls['te'][2:self.cp_lmax+1] = (Tcmb_uk)**2.*self.cp_predicted_te_spectrum.copy()
775
769
  cls['ee'][2:self.cp_lmax+1] = (Tcmb_uk)**2.*self.cp_predicted_ee_spectrum.copy()
776
770
  cls['pp'][2:self.cp_lmax+1] = self.cp_predicted_pp_spectrum.copy()/4. ## this is clkk... works for so lensinglite lkl
777
- # cls['bb'][2:self.cp_lmax+1] = self.cp_predicted_pp_spectrum.copy()/4. ## this is clkk... works for so lensinglite lkl
778
- # print('doing gets')
779
- # For planck likelihood:
780
- # lcp = np.asarray(cls['ell'][2:nl+2])
781
- # cls['pp'][2:nl+2] = self.pp_spectra[0].copy()/(lcp*(lcp+1.))**2.
782
- # cls['pp'][2:nl+2] *= (lcp*(lcp+1.))**2./2./np.pi
783
-
784
771
 
785
772
 
786
773
  if ell_factor==False:
classy_szfast/config.py CHANGED
@@ -1,6 +1,10 @@
1
1
  import os
2
2
 
3
+ import get_cosmopower_emus
4
+
5
+
3
6
  def get_cosmopower_path():
7
+ get_cosmopower_emus.set()
4
8
  return os.getenv('PATH_TO_COSMOPOWER_ORGANIZATION')
5
9
 
6
10
  path_to_cosmopower_organization = get_cosmopower_path()
@@ -60,7 +60,9 @@ emulator_dict['lcdm']['HZ'] = 'HZ_v1'
60
60
  emulator_dict['lcdm']['S8Z'] = 'S8Z_v1'
61
61
  emulator_dict['lcdm']['default'] = {}
62
62
  emulator_dict['lcdm']['default']['tau_reio'] = 0.054
63
-
63
+ emulator_dict['lcdm']['default']['N_ur'] = 2.0328
64
+ emulator_dict['lcdm']['default']['N_ncdm'] = 1
65
+ emulator_dict['lcdm']['default']['m_ncdm'] = 0.06
64
66
 
65
67
  emulator_dict['mnu']['TT'] = 'TT_mnu_v1'
66
68
  emulator_dict['mnu']['TE'] = 'TE_mnu_v1'
@@ -74,7 +76,9 @@ emulator_dict['mnu']['HZ'] = 'HZ_mnu_v1'
74
76
  emulator_dict['mnu']['S8Z'] = 'S8Z_mnu_v1'
75
77
  emulator_dict['mnu']['default'] = {}
76
78
  emulator_dict['mnu']['default']['tau_reio'] = 0.054
77
-
79
+ emulator_dict['mnu']['default']['N_ur'] = 2.0328
80
+ emulator_dict['mnu']['default']['N_ncdm'] = 1
81
+ emulator_dict['mnu']['default']['m_ncdm'] = 0.06
78
82
 
79
83
  emulator_dict['neff']['TT'] = 'TT_neff_v1'
80
84
  emulator_dict['neff']['TE'] = 'TE_neff_v1'
@@ -88,7 +92,9 @@ emulator_dict['neff']['HZ'] = 'HZ_neff_v1'
88
92
  emulator_dict['neff']['S8Z'] = 'S8Z_neff_v1'
89
93
  emulator_dict['neff']['default'] = {}
90
94
  emulator_dict['neff']['default']['tau_reio'] = 0.054
91
-
95
+ emulator_dict['neff']['default']['N_ur'] = 2.0328
96
+ emulator_dict['neff']['default']['N_ncdm'] = 1
97
+ emulator_dict['neff']['default']['m_ncdm'] = 0.06
92
98
 
93
99
 
94
100
  emulator_dict['wcdm']['TT'] = 'TT_w_v1'
@@ -103,7 +109,9 @@ emulator_dict['wcdm']['HZ'] = 'HZ_w_v1'
103
109
  emulator_dict['wcdm']['S8Z'] = 'S8Z_w_v1'
104
110
  emulator_dict['wcdm']['default'] = {}
105
111
  emulator_dict['wcdm']['default']['tau_reio'] = 0.054
106
-
112
+ emulator_dict['wcdm']['default']['N_ur'] = 2.0328
113
+ emulator_dict['wcdm']['default']['N_ncdm'] = 1
114
+ emulator_dict['wcdm']['default']['m_ncdm'] = 0.06
107
115
 
108
116
  emulator_dict['ede']['TT'] = 'TT_v1'
109
117
  emulator_dict['ede']['TE'] = 'TE_v1'
@@ -124,8 +132,6 @@ emulator_dict['ede']['default']['r'] = 0.
124
132
  emulator_dict['ede']['default']['N_ur'] = 0.00641
125
133
  emulator_dict['ede']['default']['N_ncdm'] = 3
126
134
  emulator_dict['ede']['default']['m_ncdm'] = 0.02
127
- emulator_dict['ede']['default'] = {}
128
- emulator_dict['ede']['default']['tau_reio'] = 0.054
129
135
 
130
136
 
131
137
  emulator_dict['mnu-3states']['TT'] = 'TT_v1'
@@ -140,7 +146,9 @@ emulator_dict['mnu-3states']['HZ'] = 'HZ_v1'
140
146
  emulator_dict['mnu-3states']['S8Z'] = 'S8Z_v1'
141
147
  emulator_dict['mnu-3states']['default'] = {}
142
148
  emulator_dict['mnu-3states']['default']['tau_reio'] = 0.054
143
-
149
+ emulator_dict['mnu-3states']['default']['N_ur'] = 0.00641
150
+ emulator_dict['mnu-3states']['default']['N_ncdm'] = 3
151
+ emulator_dict['mnu-3states']['default']['m_ncdm'] = 0.02
144
152
 
145
153
  emulator_dict['ede-v2']['TT'] = 'TT_v2'
146
154
  emulator_dict['ede-v2']['TE'] = 'TE_v2'
@@ -156,6 +164,10 @@ emulator_dict['ede-v2']['S8Z'] = 'S8Z_v2'
156
164
  emulator_dict['ede-v2']['default'] = {}
157
165
  emulator_dict['ede-v2']['default']['fEDE'] = 0.001
158
166
  emulator_dict['ede-v2']['default']['tau_reio'] = 0.054
167
+ emulator_dict['ede-v2']['default']['H0'] = 67.66
168
+ emulator_dict['ede-v2']['default']['ln10^{10}A_s'] = 3.047
169
+ emulator_dict['ede-v2']['default']['omega_b'] = 0.02242
170
+ emulator_dict['ede-v2']['default']['omega_cdm'] = 0.11933
159
171
  emulator_dict['ede-v2']['default']['log10z_c'] = 3.562 # e.g. from https://github.com/mwt5345/class_ede/blob/master/class/notebooks-ede/2-CMB-Comparison.ipynb
160
172
  emulator_dict['ede-v2']['default']['thetai_scf'] = 2.83 # e.g. from https://github.com/mwt5345/class_ede/blob/master/class/notebooks-ede/2-CMB-Comparison.ipynb
161
173
  emulator_dict['ede-v2']['default']['r'] = 0.
@@ -17,4 +17,4 @@ def custom1_b(z,classy_sz,*params):
17
17
  # else:
18
18
  # w = 3./2.*(H0/h)**2/Rho_crit_0*(chi/(1.+z))**-1.*(chi_star-chi)/chi_star #
19
19
 
20
- return 2.# + 2*z
20
+ return 4.# + 2*z
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: classy_szfast
3
- Version: 0.0.9
3
+ Version: 0.0.11
4
4
  Summary: The accelerator of the class_sz code from https://github.com/CLASS-SZ
5
5
  Home-page: https://github.com/CLASS-SZ/classy_szfast
6
6
  Download-URL: https://github.com/CLASS-SZ/classy_szfast
@@ -16,4 +16,5 @@ Requires-Dist: tensorflow ==2.13.0
16
16
  Requires-Dist: tensorflow-probability ==0.21.0
17
17
  Requires-Dist: cosmopower
18
18
  Requires-Dist: mcfit
19
+ Requires-Dist: get-cosmopower-emus
19
20
 
@@ -0,0 +1,17 @@
1
+ classy_szfast/__init__.py,sha256=E2thrL0Z9oXFfdzwcsu-xbOytudLFTlRlPqVFGlPPPg,279
2
+ classy_szfast/classy_sz.py,sha256=QmbwrSXInQLMvCDqsr7KPmtaU0KOiOt1Rb-cTKuulZw,22240
3
+ classy_szfast/classy_szfast.py,sha256=TBmm98jDakvLRbrDiI6m_youZXOONyhXAV2MyU41gFc,33729
4
+ classy_szfast/config.py,sha256=4CvejtLcFOQR30bJ8tlEeBHhu3Rr7LakeLO6dbFgPSU,210
5
+ classy_szfast/cosmopower.py,sha256=u9iLdt51Qss5KwOQ637lHDBWsUz0H2u-53VUMyP5foY,10435
6
+ classy_szfast/cosmosis_classy_szfast_interface.py,sha256=zAnxvFtn73a5yS7jgs59zpWFEYKCIQyraYPs5hQ4Le8,11483
7
+ classy_szfast/pks_and_sigmas.py,sha256=drtuujE1HhlrYY1hY92DyY5lXlYS1uE15MSuVI4uo6k,6625
8
+ classy_szfast/suppress_warnings.py,sha256=6wIBml2Sj9DyRGZlZWhuA9hqvpxqrNyYjuz6BPK_a6E,202
9
+ classy_szfast/utils.py,sha256=ZZxujm1yBM0KIeVVLOuoNqUVkXIZt817QDi7U_Fz_IM,1462
10
+ classy_szfast/custom_bias/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ classy_szfast/custom_bias/custom_bias.py,sha256=aR2t5RTIwv7P0m2bsEU0Eq6BTkj4pG10AebH6QpG4qM,486
12
+ classy_szfast/custom_profiles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ classy_szfast/custom_profiles/custom_profiles.py,sha256=4LZwb2XoqwCyWNmW2s24Z7AJdmgVdaRG7yYaBYe-d9Q,1188
14
+ classy_szfast-0.0.11.dist-info/METADATA,sha256=q7a06RaiRRY8j-mjhJGEVeQUoZx-l-JJ1IpDnjL_UGw,749
15
+ classy_szfast-0.0.11.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
16
+ classy_szfast-0.0.11.dist-info/top_level.txt,sha256=hRgqpilUck4lx2KkaWI2y9aCDKqF6pFfGHfNaoPFxv0,14
17
+ classy_szfast-0.0.11.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (71.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,17 +0,0 @@
1
- classy_szfast/__init__.py,sha256=E2thrL0Z9oXFfdzwcsu-xbOytudLFTlRlPqVFGlPPPg,279
2
- classy_szfast/classy_sz.py,sha256=mp6tbYzeoi27ciShV2N8xGCR9vIrhm1ISgRHjDGEh-E,25829
3
- classy_szfast/classy_szfast.py,sha256=WogzPos9dGlacklyAOjb58CS4Qbdip8BZyuj0RcGLtA,35452
4
- classy_szfast/config.py,sha256=OJXwK9gTufJgmOxXUax3XJ6QJ1yF0pJARJBCG-odZQU,151
5
- classy_szfast/cosmopower.py,sha256=poSQ6zRHJBPedZ-nO3BWjsxXLyd8FSh9aTCx6B-VoqQ,9553
6
- classy_szfast/cosmosis_classy_szfast_interface.py,sha256=zAnxvFtn73a5yS7jgs59zpWFEYKCIQyraYPs5hQ4Le8,11483
7
- classy_szfast/pks_and_sigmas.py,sha256=drtuujE1HhlrYY1hY92DyY5lXlYS1uE15MSuVI4uo6k,6625
8
- classy_szfast/suppress_warnings.py,sha256=6wIBml2Sj9DyRGZlZWhuA9hqvpxqrNyYjuz6BPK_a6E,202
9
- classy_szfast/utils.py,sha256=ZZxujm1yBM0KIeVVLOuoNqUVkXIZt817QDi7U_Fz_IM,1462
10
- classy_szfast/custom_bias/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
- classy_szfast/custom_bias/custom_bias.py,sha256=53RbMAawCurKuI44nqk6fTTkQbbuJDcZpK0YhNQS3j8,486
12
- classy_szfast/custom_profiles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- classy_szfast/custom_profiles/custom_profiles.py,sha256=4LZwb2XoqwCyWNmW2s24Z7AJdmgVdaRG7yYaBYe-d9Q,1188
14
- classy_szfast-0.0.9.dist-info/METADATA,sha256=-hPJoxQ6DfJok-Uz8W_RS-77DQ32doSDnDl5_z_-vV4,713
15
- classy_szfast-0.0.9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
16
- classy_szfast-0.0.9.dist-info/top_level.txt,sha256=hRgqpilUck4lx2KkaWI2y9aCDKqF6pFfGHfNaoPFxv0,14
17
- classy_szfast-0.0.9.dist-info/RECORD,,