classy-szfast 0.0.25.post4__py3-none-any.whl → 0.0.25.post5__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.
@@ -1,4 +1,5 @@
1
1
  from .utils import *
2
+ from .utils import Const
2
3
  from .config import *
3
4
  import numpy as np
4
5
  from .emulators_meta_data import emulator_dict, dofftlog_alphas, cp_l_max_scalars, cosmo_model_list
@@ -123,11 +124,16 @@ class Class_szfast(object):
123
124
  self.pi = jnp.pi
124
125
  self.transpose = jnp.transpose
125
126
  self.asarray = jnp.asarray
127
+ self.log = jnp.log
128
+ self.pow = jnp.power
129
+
130
+ self.sigma_B = 2. * self.pow(self.pi,5) * self.pow(Const._k_B_,4) / 15. / self.pow(Const._h_P_,3) / self.pow(Const._c_,2)
126
131
 
127
132
  self.linspace = jnp.linspace
128
133
  self.geomspace = jnp.geomspace
129
134
  self.arange = jnp.arange
130
135
  self.zeros = jnp.zeros
136
+ self.gradient = jnp.gradient
131
137
 
132
138
 
133
139
  else:
@@ -137,13 +143,18 @@ class Class_szfast(object):
137
143
 
138
144
  self.pi = np.pi
139
145
  self.transpose = np.transpose
146
+ self.pow = np.power
147
+
148
+ self.sigma_B = 2. * self.pow(self.pi,5) * self.pow(Const._k_B_,4) / 15. / self.pow(Const._h_P_,3) / self.pow(Const._c_,2)
149
+
140
150
 
141
151
  self.linspace = np.linspace
142
152
  self.geomspace = np.geomspace
143
153
  self.arange = np.arange
144
154
  self.zeros = np.zeros
145
155
  self.asarray = np.asarray
146
-
156
+ self.log = np.log
157
+ self.gradient = np.gradient
147
158
 
148
159
 
149
160
  self.cp_ls = self.arange(2,self.cp_lmax+1)
@@ -183,12 +194,12 @@ class Class_szfast(object):
183
194
 
184
195
 
185
196
  self.cszfast_pk_grid_z = self.linspace(0.,self.cszfast_pk_grid_zmax,self.cszfast_pk_grid_nz)
186
- self.cszfast_pk_grid_ln1pz = np.log(1.+self.cszfast_pk_grid_z)
197
+ self.cszfast_pk_grid_ln1pz = self.log(1.+self.cszfast_pk_grid_z)
187
198
 
188
199
 
189
200
  self.cszfast_pk_grid_k = self.geomspace(self.cp_kmin,self.cp_kmax,self.cp_nk)[::self.cp_ndspl_k]
190
201
 
191
- self.cszfast_pk_grid_lnk = np.log(self.cszfast_pk_grid_k)
202
+ self.cszfast_pk_grid_lnk = self.log(self.cszfast_pk_grid_k)
192
203
 
193
204
  self.cszfast_pk_grid_nk = len(self.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
194
205
 
@@ -198,7 +209,7 @@ class Class_szfast(object):
198
209
 
199
210
  self.cszfast_pk_grid_nz = v
200
211
  self.cszfast_pk_grid_z = self.linspace(0.,self.cszfast_pk_grid_zmax,self.cszfast_pk_grid_nz)
201
- self.cszfast_pk_grid_ln1pz = np.log(1.+self.cszfast_pk_grid_z)
212
+ self.cszfast_pk_grid_ln1pz = self.log(1.+self.cszfast_pk_grid_z)
202
213
 
203
214
  self.cszfast_pk_grid_pknl_flat = self.zeros(self.cszfast_pk_grid_nz*self.cszfast_pk_grid_nk)
204
215
  self.cszfast_pk_grid_pkl_flat = self.zeros(self.cszfast_pk_grid_nz*self.cszfast_pk_grid_nk)
@@ -254,6 +265,28 @@ class Class_szfast(object):
254
265
 
255
266
  self.params_for_emulators = {}
256
267
 
268
+
269
+ def get_all_relevant_params(self,params_values_dict=None):
270
+ if params_values_dict:
271
+ params_values = params_values_dict.copy()
272
+ else:
273
+ params_values = self.params_for_emulators
274
+ update_params_with_defaults(params_values, self.emulator_dict[self.cosmo_model]['default'])
275
+ params_values['h'] = params_values['H0']/100.
276
+ params_values['Omega_b'] = params_values['omega_b']/params_values['h']**2.
277
+ params_values['Omega_cdm'] = params_values['omega_cdm']/params_values['h']**2.
278
+ params_values['Omega0_g'] = (4.*self.sigma_B/Const._c_*pow(params_values['T_cmb'],4.)) / (3.*Const._c_*Const._c_*1.e10*params_values['h']*params_values['h']/Const._Mpc_over_m_/Const._Mpc_over_m_/8./self.pi/Const._G_)
279
+ params_values['Omega0_ur'] = params_values['N_ur']*7./8.*self.pow(4./11.,4./3.)*params_values['Omega0_g']
280
+ params_values['Omega0_ncdm'] = params_values['deg_ncdm']*params_values['m_ncdm']/(93.14*params_values['h']*params_values['h']) ## valid only in standard cases, default T_ncdm etc
281
+ params_values['Omega_Lambda'] = 1. - params_values['Omega0_g'] - params_values['Omega_b'] - params_values['Omega_cdm'] - params_values['Omega0_ncdm'] - params_values['Omega0_ur']
282
+ params_values['Omega0_m'] = params_values['Omega_cdm'] + params_values['Omega_b'] + params_values['Omega0_ncdm']
283
+ params_values['Omega0_r'] = params_values['Omega0_ur']+params_values['Omega0_g']
284
+ params_values['Omega0_m_nonu'] = params_values['Omega0_m'] - params_values['Omega0_ncdm']
285
+ params_values['Omega0_cb'] = params_values['Omega0_m_nonu']
286
+ return params_values
287
+
288
+
289
+
257
290
  def find_As(self,params_cp):
258
291
 
259
292
  sigma_8_asked = params_cp["sigma8"]
@@ -494,7 +527,7 @@ class Class_szfast(object):
494
527
  if self.jax_mode:
495
528
  self.pkl_interp = None
496
529
  else:
497
- self.pkl_interp = PowerSpectrumInterpolator(z_arr,k_arr,np.log(pk_re).T,logP=True)
530
+ self.pkl_interp = PowerSpectrumInterpolator(z_arr,k_arr,self.log(pk_re).T,logP=True)
498
531
 
499
532
  self.cszfast_pk_grid_pk = pk_re
500
533
  self.cszfast_pk_grid_pkl_flat = pk_re.flatten()
@@ -502,9 +535,7 @@ class Class_szfast(object):
502
535
  return pk_re, k_arr, z_arr
503
536
 
504
537
 
505
- def calculate_sigma(self,
506
-
507
- **params_values_dict):
538
+ def calculate_sigma(self,**params_values_dict):
508
539
 
509
540
  params_values = params_values_dict.copy()
510
541
 
@@ -520,7 +551,7 @@ class Class_szfast(object):
520
551
 
521
552
  R, var[:,iz] = TophatVar(k, lowring=True)(P[:,iz], extrap=True)
522
553
 
523
- dvar[:,iz] = np.gradient(var[:,iz], R)
554
+ dvar[:,iz] = self.gradient(var[:,iz], R)
524
555
 
525
556
  # print(k)
526
557
  # print(R)
@@ -528,11 +559,11 @@ class Class_szfast(object):
528
559
  # exit(0)
529
560
 
530
561
 
531
- self.cszfast_pk_grid_lnr = np.log(R)
562
+ self.cszfast_pk_grid_lnr = self.log(R)
532
563
  self.cszfast_pk_grid_sigma2 = var
533
564
 
534
565
  self.cszfast_pk_grid_sigma2_flat = var.flatten()
535
- self.cszfast_pk_grid_lnsigma2_flat = 0.5*np.log(var.flatten())
566
+ self.cszfast_pk_grid_lnsigma2_flat = 0.5*self.log(var.flatten())
536
567
 
537
568
  self.cszfast_pk_grid_dsigma2 = dvar
538
569
  self.cszfast_pk_grid_dsigma2_flat = dvar.flatten()
@@ -629,7 +660,7 @@ class Class_szfast(object):
629
660
  pk_re = self.transpose(pk_re)
630
661
 
631
662
 
632
- self.pknl_interp = PowerSpectrumInterpolator(z_arr,k_arr,np.log(pk_re).T,logP=True)
663
+ self.pknl_interp = PowerSpectrumInterpolator(z_arr,k_arr,self.log(pk_re).T,logP=True)
633
664
 
634
665
 
635
666
  self.cszfast_pk_grid_pknl = pk_re
@@ -638,6 +669,8 @@ class Class_szfast(object):
638
669
  return pk_re, k_arr, z_arr
639
670
 
640
671
 
672
+
673
+
641
674
  def calculate_pkl_at_z(self,
642
675
  z_asked,
643
676
  params_values_dict=None):
@@ -860,9 +893,9 @@ class Class_szfast(object):
860
893
  def get_pknl_at_k_and_z(self,k_asked,z_asked):
861
894
  # def get_pkl_at_k_and_z(self,k_asked,z_asked,method = 'cloughtocher'):
862
895
  # if method == 'linear':
863
- # pk = self.pkl_linearnd_interp(z_asked,np.log(k_asked))
896
+ # pk = self.pkl_linearnd_interp(z_asked,self.log(k_asked))
864
897
  # elif method == 'cloughtocher':
865
- # pk = self.pkl_cloughtocher_interp(z_asked,np.log(k_asked))
898
+ # pk = self.pkl_cloughtocher_interp(z_asked,self.log(k_asked))
866
899
  # return np.exp(pk)
867
900
  return self.pknl_interp.P(z_asked,k_asked)
868
901
 
@@ -870,18 +903,18 @@ class Class_szfast(object):
870
903
  # def get_pkl_at_k_and_z(self,k_asked,z_asked,method = 'cloughtocher'):
871
904
  def get_pkl_at_k_and_z(self,k_asked,z_asked):
872
905
  # if method == 'linear':
873
- # pk = self.pknl_linearnd_interp(z_asked,np.log(k_asked))
906
+ # pk = self.pknl_linearnd_interp(z_asked,self.log(k_asked))
874
907
  # elif method == 'cloughtocher':
875
- # pk = self.pknl_cloughtocher_interp(z_asked,np.log(k_asked))
908
+ # pk = self.pknl_cloughtocher_interp(z_asked,self.log(k_asked))
876
909
  # return np.exp(pk)
877
910
  return self.pkl_interp.P(z_asked,k_asked)
878
911
 
879
912
  # function used to overwrite the classy function in fast mode.
880
913
  def get_sigma_at_r_and_z(self,r_asked,z_asked):
881
914
  # if method == 'linear':
882
- # pk = self.pknl_linearnd_interp(z_asked,np.log(k_asked))
915
+ # pk = self.pknl_linearnd_interp(z_asked,self.log(k_asked))
883
916
  # elif method == 'cloughtocher':
884
- # pk = self.pknl_cloughtocher_interp(z_asked,np.log(k_asked))
917
+ # pk = self.pknl_cloughtocher_interp(z_asked,self.log(k_asked))
885
918
  # return np.exp(pk)
886
919
  k = self.cszfast_pk_grid_k
887
920
  P_at_z = self.get_pkl_at_k_and_z(k,z_asked)
@@ -87,6 +87,8 @@ emulator_dict['lcdm']['default']['n_s'] = 0.9665
87
87
  emulator_dict['lcdm']['default']['N_ur'] = 2.0328
88
88
  emulator_dict['lcdm']['default']['N_ncdm'] = 1
89
89
  emulator_dict['lcdm']['default']['m_ncdm'] = 0.06
90
+ emulator_dict['lcdm']['default']['deg_ncdm'] = 1
91
+ emulator_dict['lcdm']['default']['T_cmb'] = 2.7255
90
92
 
91
93
  emulator_dict['mnu']['TT'] = 'TT_mnu_v1'
92
94
  emulator_dict['mnu']['TE'] = 'TE_mnu_v1'
@@ -107,7 +109,9 @@ emulator_dict['mnu']['default']['omega_cdm'] = 0.11933
107
109
  emulator_dict['mnu']['default']['n_s'] = 0.9665
108
110
  emulator_dict['mnu']['default']['N_ur'] = 2.0328
109
111
  emulator_dict['mnu']['default']['N_ncdm'] = 1
112
+ emulator_dict['mnu']['default']['deg_ncdm'] = 1
110
113
  emulator_dict['mnu']['default']['m_ncdm'] = 0.06
114
+ emulator_dict['mnu']['default']['T_cmb'] = 2.7255
111
115
 
112
116
  emulator_dict['neff']['TT'] = 'TT_neff_v1'
113
117
  emulator_dict['neff']['TE'] = 'TE_neff_v1'
@@ -128,8 +132,9 @@ emulator_dict['neff']['default']['omega_cdm'] = 0.11933
128
132
  emulator_dict['neff']['default']['n_s'] = 0.9665
129
133
  emulator_dict['neff']['default']['N_ur'] = 2.0328 # this is the default value in class v2 to get Neff = 3.046
130
134
  emulator_dict['neff']['default']['N_ncdm'] = 1
135
+ emulator_dict['neff']['default']['deg_ncdm'] = 1
131
136
  emulator_dict['neff']['default']['m_ncdm'] = 0.06
132
-
137
+ emulator_dict['neff']['default']['T_cmb'] = 2.7255
133
138
 
134
139
  emulator_dict['wcdm']['TT'] = 'TT_w_v1'
135
140
  emulator_dict['wcdm']['TE'] = 'TE_w_v1'
@@ -151,6 +156,9 @@ emulator_dict['wcdm']['default']['n_s'] = 0.9665
151
156
  emulator_dict['wcdm']['default']['N_ur'] = 2.0328 # this is the default value in class v2 to get Neff = 3.046
152
157
  emulator_dict['wcdm']['default']['N_ncdm'] = 1
153
158
  emulator_dict['wcdm']['default']['m_ncdm'] = 0.06
159
+ emulator_dict['wcdm']['default']['deg_ncdm'] = 1
160
+ emulator_dict['wcdm']['default']['T_cmb'] = 2.7255
161
+
154
162
 
155
163
  emulator_dict['ede']['TT'] = 'TT_v1'
156
164
  emulator_dict['ede']['TE'] = 'TE_v1'
@@ -174,9 +182,10 @@ emulator_dict['ede']['default']['log10z_c'] = 3.562 # e.g. from https://github.c
174
182
  emulator_dict['ede']['default']['thetai_scf'] = 2.83 # e.g. from https://github.com/mwt5345/class_ede/blob/master/class/notebooks-ede/2-CMB-Comparison.ipynb
175
183
  emulator_dict['ede']['default']['r'] = 0.
176
184
  emulator_dict['ede']['default']['N_ur'] = 0.00641 # this is the default value in class v2 to get Neff = 3.046
177
- emulator_dict['ede']['default']['N_ncdm'] = 3
185
+ emulator_dict['ede']['default']['N_ncdm'] = 1 ### use equivalence with deg_ncdm = 3
186
+ emulator_dict['ede']['default']['deg_ncdm'] = 3 ### use equivalence with deg_ncdm = 3 for faster computation
178
187
  emulator_dict['ede']['default']['m_ncdm'] = 0.02
179
-
188
+ emulator_dict['ede']['default']['T_cmb'] = 2.7255
180
189
 
181
190
  emulator_dict['mnu-3states']['TT'] = 'TT_v1'
182
191
  emulator_dict['mnu-3states']['TE'] = 'TE_v1'
@@ -196,8 +205,10 @@ emulator_dict['mnu-3states']['default']['omega_b'] = 0.02242
196
205
  emulator_dict['mnu-3states']['default']['omega_cdm'] = 0.11933
197
206
  emulator_dict['mnu-3states']['default']['n_s'] = 0.9665
198
207
  emulator_dict['mnu-3states']['default']['N_ur'] = 0.00641 # this is the default value in class v2 to get Neff = 3.046
199
- emulator_dict['mnu-3states']['default']['N_ncdm'] = 3
208
+ emulator_dict['mnu-3states']['default']['N_ncdm'] = 1 ### use equivalence with deg_ncdm = 3
209
+ emulator_dict['mnu-3states']['default']['deg_ncdm'] = 3 ### use equivalence with deg_ncdm = 3 for faster computation
200
210
  emulator_dict['mnu-3states']['default']['m_ncdm'] = 0.02
211
+ emulator_dict['mnu-3states']['default']['T_cmb'] = 2.7255
201
212
 
202
213
  emulator_dict['ede-v2']['TT'] = 'TT_v2'
203
214
  emulator_dict['ede-v2']['TE'] = 'TE_v2'
@@ -222,9 +233,10 @@ emulator_dict['ede-v2']['default']['log10z_c'] = 3.562 # e.g. from https://githu
222
233
  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
223
234
  emulator_dict['ede-v2']['default']['r'] = 0.
224
235
  emulator_dict['ede-v2']['default']['N_ur'] = 0.00441 # this is the default value in class v3 to get Neff = 3.044
225
- emulator_dict['ede-v2']['default']['N_ncdm'] = 3
236
+ emulator_dict['ede-v2']['default']['N_ncdm'] = 1 ### use equivalence with deg_ncdm = 3
237
+ emulator_dict['ede-v2']['default']['deg_ncdm'] = 3 ### use equivalence with deg_ncdm = 3 for faster computation
226
238
  emulator_dict['ede-v2']['default']['m_ncdm'] = 0.02
227
-
239
+ emulator_dict['ede-v2']['default']['T_cmb'] = 2.7255
228
240
 
229
241
 
230
242
 
classy_szfast/utils.py CHANGED
@@ -60,3 +60,13 @@ class Const:
60
60
  c_km_s = 299792.458 # speed of light
61
61
  h_J_s = 6.626070040e-34 # Planck's constant
62
62
  kB_J_K = 1.38064852e-23 # Boltzmann constant
63
+
64
+ _c_ = 2.99792458e8 # c in m/s
65
+ _Mpc_over_m_ = 3.085677581282e22 # conversion factor from meters to megaparsecs
66
+ _Gyr_over_Mpc_ = 3.06601394e2 # conversion factor from megaparsecs to gigayears
67
+ _G_ = 6.67428e-11 # Newton constant in m^3/Kg/s^2
68
+ _eV_ = 1.602176487e-19 # 1 eV expressed in J
69
+
70
+ # parameters entering in Stefan-Boltzmann constant sigma_B
71
+ _k_B_ = 1.3806504e-23
72
+ _h_P_ = 6.62606896e-34
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: classy_szfast
3
- Version: 0.0.25.post4
3
+ Version: 0.0.25.post5
4
4
  Summary: The accelerator of the class_sz code from https://github.com/CLASS-SZ
5
5
  Maintainer-email: Boris Bolliet <bb667@cam.ac.uk>
6
6
  License: MIT
@@ -1,20 +1,20 @@
1
1
  classy_szfast/__init__.py,sha256=E2thrL0Z9oXFfdzwcsu-xbOytudLFTlRlPqVFGlPPPg,279
2
2
  classy_szfast/classy_sz.py,sha256=QmbwrSXInQLMvCDqsr7KPmtaU0KOiOt1Rb-cTKuulZw,22240
3
- classy_szfast/classy_szfast.py,sha256=H3DPD4_ZvVJ_FCVbEzc4rW8DYQHPZCCaGQZtQ1f-7oQ,37646
3
+ classy_szfast/classy_szfast.py,sha256=Fajoc14gdED3LpY0dMFhh1A_NzRqFVCCIof5pElCA4Y,39791
4
4
  classy_szfast/config.py,sha256=cd7Z62-qnX_4FJWfUNqcyJVh-AdBiXrF8DcQGpyAUZM,274
5
5
  classy_szfast/cosmopower.py,sha256=ooYK2BDOZSo3XtGHfPtjXHxr5UW-yVngLPkb5gpvTx8,2351
6
6
  classy_szfast/cosmopower_jax.py,sha256=NvwY1a9YoizOV0zKp0SEtiHQkhWRO-seGFzO3FIzLl0,5436
7
7
  classy_szfast/cosmosis_classy_szfast_interface.py,sha256=zAnxvFtn73a5yS7jgs59zpWFEYKCIQyraYPs5hQ4Le8,11483
8
- classy_szfast/emulators_meta_data.py,sha256=faA0iQqzfC5lOj1hu7wSEZUFfhBGLJqX9-xovMfTbr0,9723
8
+ classy_szfast/emulators_meta_data.py,sha256=mXG5LQuJw9QBNE_kxXW8Kx0AUCWpbV6uRO9BaBbIfHo,10732
9
9
  classy_szfast/pks_and_sigmas.py,sha256=drtuujE1HhlrYY1hY92DyY5lXlYS1uE15MSuVI4uo6k,6625
10
10
  classy_szfast/restore_nn.py,sha256=DqA9thhTRiGBDVb9zjhqcbF2W4V0AU0vrjJFhnLboU4,21075
11
11
  classy_szfast/suppress_warnings.py,sha256=6wIBml2Sj9DyRGZlZWhuA9hqvpxqrNyYjuz6BPK_a6E,202
12
- classy_szfast/utils.py,sha256=VdaRsJK2ttHI9zkyxVhergxHPC6t99usrlycblyqcP8,1464
12
+ classy_szfast/utils.py,sha256=Et90Yo3EOjSaOTorqPmhLE3kVMF7qc2ZJHOD5NRY5vU,1916
13
13
  classy_szfast/custom_bias/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  classy_szfast/custom_bias/custom_bias.py,sha256=aR2t5RTIwv7P0m2bsEU0Eq6BTkj4pG10AebH6QpG4qM,486
15
15
  classy_szfast/custom_profiles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
16
  classy_szfast/custom_profiles/custom_profiles.py,sha256=4LZwb2XoqwCyWNmW2s24Z7AJdmgVdaRG7yYaBYe-d9Q,1188
17
- classy_szfast-0.0.25.post4.dist-info/METADATA,sha256=oNj9IJ8zELtcPCEOOi4wQzx9SfxVaMmdIl6QjyAFdkY,548
18
- classy_szfast-0.0.25.post4.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
19
- classy_szfast-0.0.25.post4.dist-info/top_level.txt,sha256=hRgqpilUck4lx2KkaWI2y9aCDKqF6pFfGHfNaoPFxv0,14
20
- classy_szfast-0.0.25.post4.dist-info/RECORD,,
17
+ classy_szfast-0.0.25.post5.dist-info/METADATA,sha256=nhGFJzuwxdDWzS3UQpZMNk736flVpLyjjRB68r-wxbY,548
18
+ classy_szfast-0.0.25.post5.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
19
+ classy_szfast-0.0.25.post5.dist-info/top_level.txt,sha256=hRgqpilUck4lx2KkaWI2y9aCDKqF6pFfGHfNaoPFxv0,14
20
+ classy_szfast-0.0.25.post5.dist-info/RECORD,,