classy-szfast 0.0.9__tar.gz → 0.0.10__tar.gz

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 (29) hide show
  1. {classy_szfast-0.0.9/classy_szfast.egg-info → classy_szfast-0.0.10}/PKG-INFO +1 -1
  2. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/classy_sz.py +79 -117
  3. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/classy_szfast.py +84 -98
  4. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/cosmopower.py +19 -7
  5. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/custom_bias/custom_bias.py +1 -1
  6. {classy_szfast-0.0.9 → classy_szfast-0.0.10/classy_szfast.egg-info}/PKG-INFO +1 -1
  7. classy_szfast-0.0.10/setup.py +30 -0
  8. classy_szfast-0.0.9/setup.py +0 -59
  9. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/.gitignore +0 -0
  10. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/MANIFEST.in +0 -0
  11. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/README.md +0 -0
  12. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/__init__.py +0 -0
  13. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/config.py +0 -0
  14. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/cosmosis_classy_szfast_interface.py +0 -0
  15. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/custom_bias/__init__.py +0 -0
  16. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/custom_profiles/__init__.py +0 -0
  17. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/custom_profiles/custom_profiles.py +0 -0
  18. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/pks_and_sigmas.py +0 -0
  19. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/suppress_warnings.py +0 -0
  20. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast/utils.py +0 -0
  21. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast.egg-info/SOURCES.txt +0 -0
  22. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast.egg-info/dependency_links.txt +0 -0
  23. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast.egg-info/not-zip-safe +0 -0
  24. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast.egg-info/requires.txt +0 -0
  25. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/classy_szfast.egg-info/top_level.txt +0 -0
  26. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/pypi_upload.sh +0 -0
  27. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/pyproject.toml +0 -0
  28. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/requirements.txt +0 -0
  29. {classy_szfast-0.0.9 → classy_szfast-0.0.10}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: classy_szfast
3
- Version: 0.0.9
3
+ Version: 0.0.10
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
@@ -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
 
@@ -33,16 +33,15 @@ def set_verbosity(verbosity):
33
33
 
34
34
 
35
35
 
36
- def update_params_with_defaults(params_values, self):
36
+ def update_params_with_defaults(params_values, default_values):
37
37
  """
38
38
  Update params_values with default values if they don't already exist.
39
39
 
40
40
  Args:
41
41
  params_values (dict): Dictionary containing parameter values.
42
- self (object): The object containing emulator_dict and cosmo_model attributes.
42
+ default_values (dict): Dictionary containing default parameter values.
43
43
  """
44
- # Retrieve default values
45
- default_values = self.emulator_dict[self.cosmo_model]['default']
44
+
46
45
 
47
46
  # Update params_values with default values if key does not exist
48
47
  for key, value in default_values.items():
@@ -52,6 +51,7 @@ def update_params_with_defaults(params_values, self):
52
51
 
53
52
  class Class_szfast(object):
54
53
  def __init__(self,
54
+ params_settings = {},
55
55
  #lowring=False, some options if needed
56
56
  **kwargs):
57
57
  # some parameters
@@ -59,7 +59,11 @@ class Class_szfast(object):
59
59
  # self.lowring = lowring
60
60
 
61
61
 
62
- set_verbosity(kwargs["classy_sz_verbose"])
62
+ self.A_s_fast = 0
63
+ self.logA_fast = 0
64
+
65
+
66
+ set_verbosity(params_settings["classy_sz_verbose"])
63
67
  self.logger = logging.getLogger(__name__)
64
68
 
65
69
 
@@ -95,6 +99,7 @@ class Class_szfast(object):
95
99
  self.cp_ls = np.arange(2,self.cp_lmax+1)
96
100
 
97
101
 
102
+
98
103
 
99
104
  cosmo_model_dict = {0: 'lcdm',
100
105
  1: 'mnu',
@@ -106,7 +111,7 @@ class Class_szfast(object):
106
111
  }
107
112
 
108
113
 
109
- if cosmo_model_dict[kwargs['cosmo_model']] == 'ede-v2':
114
+ if cosmo_model_dict[params_settings['cosmo_model']] == 'ede-v2':
110
115
 
111
116
  self.cp_ndspl_k = 1
112
117
  self.cp_nk = 1000
@@ -128,16 +133,16 @@ class Class_szfast(object):
128
133
 
129
134
 
130
135
 
131
- if (cosmo_model_dict[kwargs['cosmo_model']] == 'ede-v2'):
136
+ if (cosmo_model_dict[params_settings['cosmo_model']] == 'ede-v2'):
132
137
 
133
138
  self.cszfast_pk_grid_zmax = 20.
134
139
  self.cszfast_pk_grid_kmin = 5e-4
135
140
  self.cszfast_pk_grid_kmax = 10.
136
141
  self.cp_kmax = self.cszfast_pk_grid_kmax
137
142
  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}")
143
+ # self.logger.info(f">>> using kmin = {self.cp_kmin}")
144
+ # self.logger.info(f">>> using kmax = {self.cp_kmax}")
145
+ # self.logger.info(f">>> using zmax = {self.cszfast_pk_grid_zmax}")
141
146
 
142
147
  else:
143
148
 
@@ -146,9 +151,9 @@ class Class_szfast(object):
146
151
  self.cszfast_pk_grid_kmax = 50.
147
152
  self.cp_kmax = self.cszfast_pk_grid_kmax
148
153
  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}")
154
+ # self.logger.info(f">>> using kmin = {self.cp_kmin}")
155
+ # self.logger.info(f">>> using kmax = {self.cp_kmax}")
156
+ # self.logger.info(f">>> using zmax = {self.cszfast_pk_grid_zmax}")
152
157
 
153
158
  self.cszfast_pk_grid_z = np.linspace(0.,self.cszfast_pk_grid_zmax,self.cszfast_pk_grid_nz)
154
159
  self.cszfast_pk_grid_ln1pz = np.log(1.+self.cszfast_pk_grid_z)
@@ -160,12 +165,14 @@ class Class_szfast(object):
160
165
 
161
166
  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
167
 
163
- for k,v in kwargs.items():
168
+ for k,v in params_settings.items():
164
169
 
165
170
  if k == 'ndim_redshifts':
171
+
166
172
  self.cszfast_pk_grid_nz = v
167
173
  self.cszfast_pk_grid_z = np.linspace(0.,self.cszfast_pk_grid_zmax,self.cszfast_pk_grid_nz)
168
174
  self.cszfast_pk_grid_ln1pz = np.log(1.+self.cszfast_pk_grid_z)
175
+
169
176
  self.cszfast_pk_grid_pknl_flat = np.zeros(self.cszfast_pk_grid_nz*self.cszfast_pk_grid_nk)
170
177
  self.cszfast_pk_grid_pkl_flat = np.zeros(self.cszfast_pk_grid_nz*self.cszfast_pk_grid_nk)
171
178
 
@@ -176,11 +183,11 @@ class Class_szfast(object):
176
183
  if k == 'use_Amod':
177
184
 
178
185
  self.use_Amod = v
179
- self.Amod = kwargs['Amod']
186
+ self.Amod = params_settings['Amod']
180
187
 
181
188
 
182
189
 
183
- if cosmo_model_dict[kwargs['cosmo_model']] == 'ede-v2':
190
+ if cosmo_model_dict[params_settings['cosmo_model']] == 'ede-v2':
184
191
 
185
192
  self.pk_power_fac = self.cszfast_pk_grid_k**-3
186
193
 
@@ -194,14 +201,6 @@ class Class_szfast(object):
194
201
  self.cp_z_interp = np.linspace(0.,20.,5000)
195
202
 
196
203
  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
204
 
206
205
 
207
206
  self.cszfast_zgrid_zmin = 0.
@@ -225,16 +224,15 @@ class Class_szfast(object):
225
224
  self.cszfast_gas_pressure_xgrid = np.geomspace(self.cszfast_gas_pressure_xgrid_xmin,
226
225
  self.cszfast_gas_pressure_xgrid_xmax,
227
226
  self.cszfast_gas_pressure_xgrid_nx)
228
-
227
+
229
228
  self.params_for_emulators = {}
230
229
 
231
230
  def find_As(self,params_cp):
232
- # params_cp = self.params_cp
233
- t0 = time.time()
234
231
 
235
232
  sigma_8_asked = params_cp["sigma8"]
236
- update_params_with_defaults(params_cp, self)
237
- # print(params_cp)
233
+
234
+ update_params_with_defaults(params_cp, self.emulator_dict[self.cosmo_model]['default'])
235
+
238
236
  def to_root(ln10_10_As_goal):
239
237
  params_cp["ln10^{10}A_s"] = ln10_10_As_goal[0]
240
238
  params_dict = {}
@@ -247,14 +245,18 @@ class Class_szfast(object):
247
245
  x0=3.046,
248
246
  #tol = 1e-10,
249
247
  method="hybr")
250
- params_cp['ln10^{10}A_s'] = lnA_s.x[0]# .x[0]
248
+
249
+ params_cp['ln10^{10}A_s'] = lnA_s.x[0]
250
+
251
251
  params_cp.pop('sigma8')
252
- # print("T total in find As",time.time()-t0)#self.t_total)
253
- # print(params_cp)
252
+
254
253
  return 1
255
254
 
256
255
 
257
256
  def get_H0_from_thetas(self,params_values):
257
+
258
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
259
+
258
260
  # print(params_values)
259
261
  theta_s_asked = params_values['100*theta_s']
260
262
  def fzero(H0_goal):
@@ -262,7 +264,7 @@ class Class_szfast(object):
262
264
  params_dict = {}
263
265
  for k,v in params_values.items():
264
266
  params_dict[k]=[v]
265
- # print(params_dict)
267
+
266
268
  predicted_der_params = self.cp_der_nn[self.cosmo_model].ten_to_predictions_np(params_dict)
267
269
  return predicted_der_params[0][0]-theta_s_asked
268
270
  sol = optimize.root(fzero,
@@ -319,9 +321,10 @@ class Class_szfast(object):
319
321
  want_pp=1,
320
322
  **params_values_dict):
321
323
 
324
+
322
325
  params_values = params_values_dict.copy()
323
- update_params_with_defaults(params_values, self)
324
326
 
327
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
325
328
 
326
329
  params_dict = {}
327
330
 
@@ -404,7 +407,7 @@ class Class_szfast(object):
404
407
 
405
408
 
406
409
  params_values = params_values_dict.copy()
407
- update_params_with_defaults(params_values, self)
410
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
408
411
 
409
412
 
410
413
  params_dict = {}
@@ -455,57 +458,50 @@ class Class_szfast(object):
455
458
 
456
459
 
457
460
  def calculate_sigma(self,
458
- # cosmo_model = self.cosmo_model,
459
- # z_asked = None,
460
- # r_asked = None,
461
+
461
462
  **params_values_dict):
463
+
462
464
  params_values = params_values_dict.copy()
465
+
463
466
  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))
467
+
466
468
  P = self.cszfast_pk_grid_pk
469
+
467
470
  var = P.copy()
471
+
468
472
  dvar = P.copy()
473
+
469
474
  for iz,zp in enumerate(self.cszfast_pk_grid_z):
475
+
470
476
  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
477
 
477
478
  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
479
+
480
+ # print(k)
481
+ # print(R)
482
+ # print(k*R)
483
+ # exit(0)
484
+
488
485
 
489
486
  self.cszfast_pk_grid_lnr = np.log(R)
490
487
  self.cszfast_pk_grid_sigma2 = var
488
+
491
489
  self.cszfast_pk_grid_sigma2_flat = var.flatten()
492
490
  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
491
+
494
492
  self.cszfast_pk_grid_dsigma2 = dvar
495
493
  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
494
+
501
495
  return 0
502
496
 
503
497
 
504
498
  def calculate_sigma8_and_der(self,
505
499
  # cosmo_model = self.cosmo_model,
506
500
  **params_values_dict):
501
+
507
502
  params_values = params_values_dict.copy()
508
- update_params_with_defaults(params_values, self)
503
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
504
+
509
505
  # print('in pkl:',params_values)
510
506
 
511
507
  params_dict = {}
@@ -560,7 +556,7 @@ class Class_szfast(object):
560
556
 
561
557
 
562
558
  params_values = params_values_dict.copy()
563
- update_params_with_defaults(params_values, self)
559
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
564
560
 
565
561
 
566
562
  params_dict = {}
@@ -613,7 +609,7 @@ class Class_szfast(object):
613
609
 
614
610
  params_values = self.params_for_emulators
615
611
 
616
- update_params_with_defaults(params_values, self)
612
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
617
613
 
618
614
 
619
615
  params_dict = {}
@@ -629,7 +625,7 @@ class Class_szfast(object):
629
625
 
630
626
  z_asked = z_asked
631
627
  params_dict_pp = params_dict.copy()
632
- update_params_with_defaults(params_dict_pp, self)
628
+ update_params_with_defaults(params_dict_pp, self.emulator_dict[self.cosmo_model]['default'])
633
629
 
634
630
  params_dict_pp['z_pk_save_nonclass'] = [z_asked]
635
631
  predicted_pk_spectrum_z.append(self.cp_pkl_nn[self.cosmo_model].predictions_np(params_dict_pp)[0])
@@ -661,7 +657,7 @@ class Class_szfast(object):
661
657
 
662
658
  params_values = self.params_for_emulators
663
659
 
664
- update_params_with_defaults(params_values, self)
660
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
665
661
 
666
662
 
667
663
  params_dict = {}
@@ -677,7 +673,7 @@ class Class_szfast(object):
677
673
 
678
674
  z_asked = z_asked
679
675
  params_dict_pp = params_dict.copy()
680
- update_params_with_defaults(params_dict_pp, self)
676
+ update_params_with_defaults(params_dict_pp, self.emulator_dict[self.cosmo_model]['default'])
681
677
 
682
678
  params_dict_pp['z_pk_save_nonclass'] = [z_asked]
683
679
  predicted_pk_spectrum_z.append(self.cp_pknl_nn[self.cosmo_model].predictions_np(params_dict_pp)[0])
@@ -694,10 +690,12 @@ class Class_szfast(object):
694
690
 
695
691
 
696
692
  def calculate_hubble(self,
697
- # cosmo_model = self.cosmo_model,
698
- **params_values_dict):
693
+ **params_values_dict):
694
+
699
695
  params_values = params_values_dict.copy()
700
696
 
697
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
698
+
701
699
  params_dict = {}
702
700
  for k,v in zip(params_values.keys(),params_values.values()):
703
701
  params_dict[k]=[v]
@@ -706,11 +704,8 @@ class Class_szfast(object):
706
704
  if isinstance(params_dict['m_ncdm'][0],str):
707
705
  params_dict['m_ncdm'] = [float(params_dict['m_ncdm'][0].split(',')[0])]
708
706
 
709
-
710
-
711
707
  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 =
708
+
714
709
  self.hz_interp = scipy.interpolate.interp1d(
715
710
  self.cp_z_interp,
716
711
  self.cp_predicted_hubble,
@@ -722,36 +717,33 @@ class Class_szfast(object):
722
717
  assume_sorted=False)
723
718
 
724
719
  def calculate_chi(self,
725
- # cosmo_model = self.cosmo_model,
726
720
  **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)
721
+
743
722
  params_values = params_values_dict.copy()
744
723
 
724
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
725
+
745
726
  params_dict = {}
727
+
746
728
  for k,v in zip(params_values.keys(),params_values.values()):
729
+
747
730
  params_dict[k]=[v]
748
731
 
749
732
  if 'm_ncdm' in params_dict.keys():
750
733
  if isinstance(params_dict['m_ncdm'][0],str):
751
734
  params_dict['m_ncdm'] = [float(params_dict['m_ncdm'][0].split(',')[0])]
752
735
 
736
+ # deal with different scaling of DA in different model from emulator training
737
+ if self.cosmo_model == 'ede-v2':
738
+
739
+ self.cp_predicted_da = self.cp_da_nn[self.cosmo_model].ten_to_predictions_np(params_dict)[0]
740
+ self.cp_predicted_da = np.insert(self.cp_predicted_da, 0, 0)
741
+
742
+ else:
743
+
744
+ self.cp_predicted_da = self.cp_da_nn[self.cosmo_model].predictions_np(params_dict)[0]
745
+
753
746
 
754
- self.cp_predicted_da = self.cp_da_nn[self.cosmo_model].predictions_np(params_dict)[0]
755
747
  self.chi_interp = scipy.interpolate.interp1d(
756
748
  self.cp_z_interp,
757
749
  self.cp_predicted_da*(1.+self.cp_z_interp),
@@ -763,6 +755,7 @@ class Class_szfast(object):
763
755
  assume_sorted=False)
764
756
 
765
757
  def get_cmb_cls(self,ell_factor=True,Tcmb_uk = Tcmb_uk):
758
+
766
759
  cls = {}
767
760
  cls['ell'] = np.arange(self.cszfast_ldim)
768
761
  cls['tt'] = np.zeros(self.cszfast_ldim)
@@ -774,13 +767,6 @@ class Class_szfast(object):
774
767
  cls['te'][2:self.cp_lmax+1] = (Tcmb_uk)**2.*self.cp_predicted_te_spectrum.copy()
775
768
  cls['ee'][2:self.cp_lmax+1] = (Tcmb_uk)**2.*self.cp_predicted_ee_spectrum.copy()
776
769
  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
770
 
785
771
 
786
772
  if ell_factor==False:
@@ -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.10
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
@@ -0,0 +1,30 @@
1
+ from setuptools import setup, find_packages
2
+ import os
3
+ import sys
4
+ import shutil
5
+
6
+
7
+ # Setup configuration
8
+ setup(
9
+ classifiers=[
10
+ 'Operating System :: OS Independent',
11
+ 'Intended Audience :: Developers',
12
+ 'Intended Audience :: Science/Research'
13
+ ],
14
+ name="classy_szfast",
15
+ version="0.0.10",
16
+ description="Python package for fast class_sz",
17
+ # long_description=long_description,
18
+ long_description_content_type='text/markdown',
19
+ zip_safe=False,
20
+ packages=find_packages(include=["classy_szfast"]),
21
+ package_dir={},
22
+ package_data={},
23
+ author="Boris Bolliet, Ola Kusiak",
24
+ author_email="bb667@cam.ac.uk, akk2175@columbia.edu",
25
+ url='https://github.com/CLASS-SZ/classy_szfast',
26
+ download_url='https://github.com/CLASS-SZ/classy_szfast',
27
+
28
+ install_requires=["setuptools", "wheel", "numpy>=1.19.0", "Cython>=0.29.21", "tensorflow==2.13.0", "tensorflow-probability==0.21.0", "cosmopower", "mcfit"],
29
+ )
30
+
@@ -1,59 +0,0 @@
1
- from setuptools import setup, find_packages
2
- import os
3
- import sys
4
- import shutil
5
-
6
- # # Determine the library folder and requirements path
7
- # thelibFolder = os.path.dirname(os.path.realpath(__file__))
8
- # requirementPath = os.path.join(thelibFolder, 'requirements.txt')
9
-
10
- # # Read the requirements from the requirements.txt file
11
- # install_requires = []
12
- # if os.path.isfile(requirementPath):
13
- # with open(requirementPath) as f:
14
- # print('opening requirements ', requirementPath)
15
- # install_requires = f.read().splitlines()
16
-
17
- # # Read the long description from the README.md file
18
- # def read_file(file):
19
- # with open(file) as f:
20
- # return f.read()
21
-
22
- # long_description = read_file("README.md")
23
-
24
- # # Determine whether the system is M1/M2 Mac and adjust TensorFlow dependency
25
- # tensorflow = 'tensorflow'
26
- # if 'arm' in os.uname().machine:
27
- # tensorflow = 'tensorflow-metal'
28
-
29
- # Add TensorFlow to the install_requires list
30
- # install_requires.append(tensorflow)
31
-
32
- # Setup configuration
33
- setup(
34
- classifiers=[
35
- 'Operating System :: OS Independent',
36
- 'Intended Audience :: Developers',
37
- 'Intended Audience :: Science/Research'
38
- ],
39
- name="classy_szfast",
40
- version="0.0.9",
41
- description="Python package for fast class_sz",
42
- # long_description=long_description,
43
- long_description_content_type='text/markdown',
44
- zip_safe=False,
45
- packages=find_packages(),
46
- author="Boris Bolliet, Ola Kusiak",
47
- author_email="bb667@cam.ac.uk, akk2175@columbia.edu",
48
- url='https://github.com/CLASS-SZ/classy_szfast',
49
- download_url='https://github.com/CLASS-SZ/classy_szfast',
50
- package_data={},
51
- install_requires=["setuptools", "wheel", "numpy>=1.19.0", "Cython>=0.29.21", "tensorflow==2.13.0", "tensorflow-probability==0.21.0", "cosmopower", "mcfit"],
52
- )
53
-
54
- # # Clean up build artifacts
55
- # os.chdir(os.path.dirname(os.path.abspath(__file__)))
56
- # shutil.rmtree("build", True)
57
- # shutil.rmtree("classy_szfast.egg-info", True)
58
- # shutil.rmtree("__pycache__", True)
59
- # shutil.rmtree(".pytest_cache", True)
File without changes
File without changes
File without changes