PyCosmo 2.1.0__tar.gz → 2.1.1__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 (103) hide show
  1. {PyCosmo-2.1.0/src/PyCosmo.egg-info → PyCosmo-2.1.1}/PKG-INFO +1 -1
  2. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/pyproject.toml +4 -3
  3. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/setup.cfg +12 -6
  4. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/setup.py +2 -4
  5. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/Background.py +15 -10
  6. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/BoltzmannSolver/LinearPerturbationBoltzmann.py +142 -32
  7. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/BoltzmannSolver/LsodaSolver.py +14 -19
  8. PyCosmo-2.1.1/src/PyCosmo/BoltzmannSolver/ScipySolver.py +355 -0
  9. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/Cosmo.py +68 -16
  10. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/CosmologyCore.py +5 -0
  11. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/CosmologyCore_massivenu_rsa.py +19 -15
  12. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/CosmologyCore_massivenu_wcdm_rsa.py +4 -1
  13. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/CosmologyCore_rsa.py +4 -2
  14. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/CosmologyCore_wcdm_rsa.py +4 -2
  15. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/LinearPerturbationApprox.py +1 -1
  16. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/NonLinearPerturbationHaloFit.py +35 -40
  17. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/NonLinearPerturbationMead.py +30 -30
  18. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/Obs.py +13 -4
  19. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/PerturbationBase.py +2 -2
  20. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/PerturbationTable.py +0 -2
  21. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/Projection.py +9 -9
  22. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/default_lcdm.ini +1 -0
  23. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/default_lcdm_rsa.ini +1 -0
  24. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/default_mnulcdm.ini +1 -0
  25. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/default_mnulcdm_rsa.ini +1 -0
  26. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/default_mnuwcdm.ini +1 -0
  27. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/default_mnuwcdm_rsa.ini +1 -0
  28. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/default_wcdm.ini +1 -0
  29. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/default_wcdm_rsa.ini +1 -0
  30. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/load_parameters_ini.py +12 -7
  31. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/core_file_handling.py +6 -0
  32. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/halo_integral.c +1836 -1639
  33. {PyCosmo-2.1.0 → PyCosmo-2.1.1/src/PyCosmo.egg-info}/PKG-INFO +1 -1
  34. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo.egg-info/SOURCES.txt +20 -2
  35. PyCosmo-2.1.1/src/PyCosmo.egg-info/entry_points.txt +2 -0
  36. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo.egg-info/requires.txt +7 -5
  37. PyCosmo-2.1.1/tests/test_background.py +410 -0
  38. PyCosmo-2.1.1/tests/test_boltzmann_solver.py +841 -0
  39. PyCosmo-2.1.1/tests/test_class.py +200 -0
  40. PyCosmo-2.1.1/tests/test_core_files_imports.py +57 -0
  41. PyCosmo-2.1.1/tests/test_cosmo.py +48 -0
  42. PyCosmo-2.1.1/tests/test_cython_extensions.py +49 -0
  43. PyCosmo-2.1.1/tests/test_ini_handling.py +45 -0
  44. PyCosmo-2.1.1/tests/test_linear_perturbation_approx.py +259 -0
  45. PyCosmo-2.1.1/tests/test_massive_neutrinos.py +176 -0
  46. PyCosmo-2.1.1/tests/test_nonlinear_perturbation_halofit.py +132 -0
  47. PyCosmo-2.1.1/tests/test_nonlinear_perturbation_mead.py +218 -0
  48. PyCosmo-2.1.1/tests/test_obs.py +781 -0
  49. PyCosmo-2.1.1/tests/test_perturbation_table.py +84 -0
  50. PyCosmo-2.1.1/tests/test_pickling.py +25 -0
  51. PyCosmo-2.1.1/tests/test_pycosmo.py +112 -0
  52. PyCosmo-2.1.1/tests/test_recombination.py +19 -0
  53. PyCosmo-2.1.1/tests/test_scipy_solver.py +93 -0
  54. PyCosmo-2.1.1/tests/test_util.py +40 -0
  55. PyCosmo-2.1.0/src/PyCosmo/BoltzmannSolver/ScipySolver.py +0 -132
  56. PyCosmo-2.1.0/src/PyCosmo/Obs_old.py +0 -888
  57. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/AUTHORS.rst +0 -0
  58. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/LICENSE +0 -0
  59. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/README.rst +0 -0
  60. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/BoltzmannSolver/Fields.py +0 -0
  61. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/BoltzmannSolver/__init__.py +0 -0
  62. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/CosmologyCore_massivenu.py +0 -0
  63. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/CosmologyCore_massivenu_wcdm.py +0 -0
  64. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/CosmologyCore_wcdm.py +0 -0
  65. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/LinearPerturbationBase.py +0 -0
  66. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/LinearPerturbationTable.py +0 -0
  67. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/NonLinearPerturbationTable.py +0 -0
  68. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/TheoryPredTables.py +0 -0
  69. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/_Cosmics.py +0 -0
  70. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/_Recombination.py +0 -0
  71. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/_RecombinationClass.py +0 -0
  72. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/_RecombinationCosmics.py +0 -0
  73. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/_Tables.py +0 -0
  74. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/_Util.py +0 -0
  75. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/__init__.py +0 -0
  76. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/_scipy_utils.py +0 -0
  77. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/build.py +0 -0
  78. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/config/__init__.py +0 -0
  79. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/__init__.py +0 -0
  80. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/const.c +0 -0
  81. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/constf.c +0 -0
  82. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/halo_integral.pyx +0 -0
  83. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/logf.c +0 -0
  84. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/main.c +0 -0
  85. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/mconf.h +0 -0
  86. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/mtherr.c +0 -0
  87. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/polevl.c +0 -0
  88. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/polevlf.c +0 -0
  89. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/protos.h +0 -0
  90. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/sici.c +0 -0
  91. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/sici.h +0 -0
  92. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/sici32.c +0 -0
  93. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/sicif.c +0 -0
  94. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/cython/sinf.c +0 -0
  95. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/disable_multithreading.py +0 -0
  96. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/ini_handling.py +0 -0
  97. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/model_config.py +0 -0
  98. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/optimize_nq.py +0 -0
  99. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/patches.py +0 -0
  100. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo/predefined_k_grids.py +0 -0
  101. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo.egg-info/dependency_links.txt +0 -0
  102. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo.egg-info/not-zip-safe +0 -0
  103. {PyCosmo-2.1.0 → PyCosmo-2.1.1}/src/PyCosmo.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyCosmo
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: A multi-purpose cosmology calculation tool
5
5
  Author: Uwe Schmitt et al
6
6
  Author-email: uwe.schmitt@id.ethz.ch
@@ -28,7 +28,8 @@ filterwarnings = ["ignore:invalid"]
28
28
  legacy_tox_ini = '''
29
29
  [tox]
30
30
  isolated_build = true
31
- envlist = py38,py39,py10
31
+ envlist = py39,py310,py311
32
+ package = sdist
32
33
  setenv =
33
34
  PIP_EXTRA_INDEX_URL=https://cosmo-pypi.phys.ethz.ch/simple
34
35
  HTTP_PROXY=http://proxy.ethz.ch:3128
@@ -37,8 +38,8 @@ setenv =
37
38
  [testenv]
38
39
  skip_install = false
39
40
  passenv = *
41
+ allowlist_externals = pytest
40
42
  extras = dev
41
- allowlist_exernals = pytest
42
43
  commands =
43
- pytest -x -v -ra --color=yes --runslow
44
+ pytest --runslow -v -ra tests
44
45
  '''
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = PyCosmo
3
- version = 2.1.0
3
+ version = 2.1.1
4
4
  license = GPLv3
5
5
  description = A multi-purpose cosmology calculation tool
6
6
  long_description = file: README.rst
@@ -26,13 +26,13 @@ project_urls =
26
26
  [options]
27
27
  install_requires =
28
28
  numpy
29
- scipy>=0.14
30
29
  recfast4py>=0.2.3
31
30
  dill
32
31
  matplotlib
33
- numba
34
- sympy2c>=2
32
+ numba>=0.57.0rc1
33
+ sympy2c>=2.2.2
35
34
  numexpr
35
+ scipy
36
36
  packages = find:
37
37
  package_dir =
38
38
  =src
@@ -49,19 +49,25 @@ where = src
49
49
  *.h
50
50
  config/*.ini
51
51
 
52
+ [options.entry_points]
53
+ console_scripts =
54
+ recompile = PyCosmo:Cosmo.recompile_from_cli
55
+
52
56
  [options.extras_require]
53
57
  dev =
58
+ Cython
54
59
  twine
55
- pytest
60
+ pytest<7.2.0
56
61
  pytest-cov
57
62
  pytest-regtest
58
63
  tox
59
64
  flake8
60
- black @ git+https://github.com/psf/black # binary wheels are broken on some machines
65
+ black
61
66
  isort
62
67
  sphinx
63
68
  sphinx-pynpoint-theme
64
69
  myst-parser
70
+ memray
65
71
  docs =
66
72
  sphinx
67
73
  sphinx-pynpoint-theme
@@ -1,9 +1,7 @@
1
1
  #!/usr/bin/env python
2
-
3
- from setuptools import Extension, setup
4
- from Cython.Build import cythonize
5
-
6
2
  import numpy
3
+ from Cython.Build import cythonize
4
+ from setuptools import Extension, setup
7
5
 
8
6
  files = [
9
7
  "const.c",
@@ -27,8 +27,7 @@ def _call(wrapper, function, a=None):
27
27
  elif isinstance(a, list):
28
28
  a = np.array(a)
29
29
  assert isinstance(a, np.ndarray)
30
- a = a.astype(float)
31
- return getattr(wrapper, function)(a)
30
+ return getattr(wrapper, function)(a.astype(float))
32
31
 
33
32
 
34
33
  class Background(object):
@@ -80,12 +79,11 @@ class Background(object):
80
79
  _hubble = H
81
80
 
82
81
  def _H2_H02_a(self, a=1.0):
83
- return (
84
- self._H2_H02_Omegar_a(a=a)
85
- + self._H2_H02_Omegam_a(a=a)
86
- + self._H2_H02_Omegak_a(a=a)
87
- + self._H2_H02_Omegal_a(a=a)
88
- )
82
+ result = self._H2_H02_Omegar_a(a=a)
83
+ result += self._H2_H02_Omegam_a(a=a)
84
+ result += self._H2_H02_Omegak_a(a=a)
85
+ result += self._H2_H02_Omegal_a(a=a)
86
+ return result
89
87
 
90
88
  def _H2_H02_Omegar_a(self, a=1.0):
91
89
  return self._params.omega_r / a**4
@@ -294,7 +292,12 @@ class Background(object):
294
292
  """
295
293
  a = np.atleast_1d(a)
296
294
  return np.array(
297
- [integrate.quadrature(self._tau_intgd, np.log(aa), 0.0)[0] for aa in a]
295
+ [
296
+ integrate.quadrature(
297
+ self._tau_intgd, np.log(aa), 0.0, rtol=1e-6, maxiter=100
298
+ )[0]
299
+ for aa in a
300
+ ]
298
301
  )
299
302
 
300
303
  def _tau_intgd(self, lna):
@@ -435,7 +438,9 @@ class Background(object):
435
438
  input: a - scale factor [1]
436
439
  output: [1]
437
440
  """
438
- return self._H2_H02_Omegal_a(a=a) / self._H2_H02_a(a=a)
441
+ result = self._H2_H02_Omegal_a(a=a)
442
+ result /= self._H2_H02_a(a=a)
443
+ return result
439
444
 
440
445
  def _omega_nu_m_a(self, a=1.0):
441
446
  """
@@ -16,7 +16,9 @@
16
16
 
17
17
  import itertools
18
18
  import warnings
19
+ from datetime import datetime
19
20
  from functools import lru_cache
21
+ from multiprocessing import current_process
20
22
 
21
23
  import numpy as np
22
24
 
@@ -24,9 +26,8 @@ from ..LinearPerturbationBase import LinearPerturbationBase
24
26
  from .Fields import Fields
25
27
  from .LsodaSolver import LsodaSolver
26
28
 
27
-
28
29
  # use decorator to print messages only once per model:
29
- @lru_cache(maxsize=1)
30
+ @lru_cache(maxsize=1) # noqa: E302
30
31
  def print_new_traces(cache_file):
31
32
  print()
32
33
  print("new traces detected! you might want to run")
@@ -34,6 +35,39 @@ def print_new_traces(cache_file):
34
35
  print()
35
36
 
36
37
 
38
+ proc_name = current_process().name
39
+
40
+
41
+ def trace_call(frame, event, arg):
42
+ if proc_name.endswith("-2"):
43
+ return trace_call
44
+ if event in ("line",):
45
+ return trace_call
46
+ fname = frame.f_code.co_filename
47
+ if any(
48
+ n in fname
49
+ for n in (
50
+ "pprint",
51
+ "dill",
52
+ "pickle",
53
+ "numba",
54
+ "logging",
55
+ "ini_handling",
56
+ "llvmlite",
57
+ "traceback",
58
+ "weakref",
59
+ )
60
+ ):
61
+ return trace_call
62
+ print(datetime.now(), end=" ")
63
+ fr = frame
64
+ print(proc_name, f"{event:8s}", end="")
65
+ while (fr := fr.f_back) is not None:
66
+ print(" ", end="")
67
+ print(fname, frame.f_code.co_name, frame.f_lineno, flush=True)
68
+ return trace_call
69
+
70
+
37
71
  class LinearPerturbationBoltzmann(LinearPerturbationBase):
38
72
  """
39
73
  Class for computing linear perturbations by solving the Einstein-Boltzmann ODE
@@ -57,6 +91,7 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
57
91
  self._params.boltzmann_atol,
58
92
  self._params.boltzmann_max_bdf_order,
59
93
  self._params.boltzmann_max_iter,
94
+ self._params.boltzmann_h0,
60
95
  self._cosmo,
61
96
  self._params.fast_solver,
62
97
  )
@@ -152,17 +187,17 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
152
187
  # using equation in section 2.4 of notes
153
188
  norm = (
154
189
  2.0
155
- * np.pi ** 2
156
- * self._params.pk_norm ** 2
190
+ * np.pi**2
191
+ * self._params.pk_norm**2
157
192
  * (self._params.c / self._params.H0) ** (3.0 + self._params.n)
158
193
  )
159
194
 
160
195
  if diag_only:
161
- pk = norm * growth ** 2 * k ** self._params.n * T_k ** 2
196
+ pk = norm * growth**2 * k**self._params.n * T_k**2
162
197
  else:
163
198
  # pk = norm * np.outer(growth.T ** 2, k ** self._params.n * T_k ** 2).T
164
199
  pk = (
165
- norm * growth ** 2 * (k ** self._params.n * T_k ** 2).reshape(-1, 1)
200
+ norm * growth**2 * (k**self._params.n * T_k**2).reshape(-1, 1)
166
201
  )
167
202
 
168
203
  if (self._params.pk_norm_type == "A_s") or (
@@ -178,7 +213,7 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
178
213
  def _a_s_powerspec(self, a, k, diag_only):
179
214
  norm = (
180
215
  2.0
181
- * np.pi ** 2
216
+ * np.pi**2
182
217
  * self._params.As_norm
183
218
  / self._params.k_pivot ** (self._params.n - 1)
184
219
  )
@@ -191,26 +226,76 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
191
226
  if self._cosmo._pool is None:
192
227
  if diag_only:
193
228
  for ai, ki in zip(a, kk):
194
- src_m.append(src_m_column_j((self, ai, ki)))
229
+ src_m.append(
230
+ src_m_column_j(
231
+ (
232
+ self._compute_fields_,
233
+ self._solver.solve,
234
+ self._cosmo._cache_file,
235
+ self._params,
236
+ self._background.H(ai),
237
+ self._wrapper,
238
+ ai,
239
+ ki,
240
+ )
241
+ )
242
+ )
195
243
  else:
196
244
  for ki in kk:
197
- src_m.append(src_m_column_j((self, a, ki)))
245
+ src_m.append(
246
+ src_m_column_j(
247
+ (
248
+ self._compute_fields_,
249
+ self._solver.solve,
250
+ self._cosmo._cache_file,
251
+ self._params,
252
+ self._background.H(a),
253
+ self._wrapper,
254
+ a,
255
+ ki,
256
+ )
257
+ )
258
+ )
198
259
  else:
199
260
  kk = np.array(kk)
200
261
  perm = np.argsort(kk)
201
262
  kk = kk[perm]
202
263
  src_m = [None] * len(kk)
203
264
  if diag_only:
204
- args = [(self, ai, ki) for ai, ki in zip(a, kk)]
265
+ args = [
266
+ (
267
+ self._compute_fields_,
268
+ self._solver.solve,
269
+ self._cosmo._cache_file,
270
+ self._params,
271
+ self._background.H(ai),
272
+ self._wrapper,
273
+ ai,
274
+ ki,
275
+ )
276
+ for ai, ki in zip(a, kk)
277
+ ]
205
278
  else:
206
- args = [(self, a, ki) for ki in kk]
279
+ args = [
280
+ (
281
+ self._compute_fields_,
282
+ self._solver.solve,
283
+ self._cosmo._cache_file,
284
+ self._params,
285
+ self._background.H(a),
286
+ self._wrapper,
287
+ a,
288
+ ki,
289
+ )
290
+ for ki in kk
291
+ ]
207
292
 
208
293
  src_m_cols = list(self._cosmo._pool.map(src_m_column_j, args))
209
294
  for i, pi in enumerate(perm):
210
295
  src_m[pi] = src_m_cols[i]
211
296
 
212
297
  src_m = np.vstack(src_m).T
213
- return norm * src_m.T ** 2 * k[:, None] ** (self._params.n - 4.0)
298
+ return norm * src_m.T**2 * k[:, None] ** (self._params.n - 4.0)
214
299
 
215
300
  def powerspec_cb_a_k(self, a=1.0, k=0.1, diag_only=False):
216
301
  """
@@ -239,7 +324,7 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
239
324
 
240
325
  norm = (
241
326
  2.0
242
- * np.pi ** 2
327
+ * np.pi**2
243
328
  * self._params.pk_norm
244
329
  / self._params.k_pivot ** (self._params.n - 1)
245
330
  )
@@ -257,10 +342,10 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
257
342
  theta_m_tot = self._params.omega_dm * theta + self._params.omega_b * theta_b
258
343
 
259
344
  tk[:, j] = (
260
- delta_m_tot + (3 * a * H / onek ** 2) * theta_m_tot
345
+ delta_m_tot + (3 * a * H / onek**2) * theta_m_tot
261
346
  ) / self._params.omega_m
262
347
 
263
- pk = norm * tk.T ** 2 * k[:, None] ** (self._params.n - 4.0)
348
+ pk = norm * tk.T**2 * k[:, None] ** (self._params.n - 4.0)
264
349
 
265
350
  if diag_only:
266
351
  return np.diag(pk)
@@ -419,9 +504,32 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
419
504
  enable_fast_solver=True,
420
505
  enable_sparse_lu_solver=True,
421
506
  ):
507
+ return LinearPerturbationBoltzmann._compute_fields_(
508
+ self._solver.solve,
509
+ k,
510
+ grid,
511
+ sec_factor,
512
+ keep_lna0,
513
+ initial_conditions,
514
+ enable_fast_solver,
515
+ enable_sparse_lu_solver,
516
+ self._cosmo._cache_file,
517
+ )
422
518
 
519
+ @staticmethod
520
+ def _compute_fields_(
521
+ solve,
522
+ k,
523
+ grid,
524
+ sec_factor=3,
525
+ keep_lna0=False,
526
+ initial_conditions=None,
527
+ enable_fast_solver=True,
528
+ enable_sparse_lu_solver=True,
529
+ cache_file=None,
530
+ ):
423
531
  grid = np.atleast_1d(grid)
424
- grid, solver_result, meta = self._solver.solve(
532
+ grid, solver_result, meta = solve(
425
533
  k,
426
534
  grid,
427
535
  sec_factor,
@@ -434,7 +542,7 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
434
542
  if (isinstance(new_traces, dict) and new_traces) or (
435
543
  isinstance(new_traces, list) and any(new_traces)
436
544
  ):
437
- print_new_traces(self._cosmo._cache_file)
545
+ print_new_traces(cache_file)
438
546
  return grid, solver_result, meta, keep_lna0
439
547
 
440
548
  def P_R_k(self, k):
@@ -458,10 +566,12 @@ class LinearPerturbationBoltzmann(LinearPerturbationBase):
458
566
  return norm * k ** (self._params.n - 1)
459
567
 
460
568
 
461
- def src_m_column_j(arg):
462
- self, a, onek = arg
569
+ def src_m_column_j(args):
570
+ compute_fields_, solve, cache_file, _params, H_, _wrapper, a, onek = args
463
571
  a = np.atleast_1d(a)
464
- grid, y, meta, keep_lna0 = self._compute_fields(onek, grid=np.log(a))
572
+ grid, y, meta, keep_lna0 = compute_fields_(
573
+ solve, onek, grid=np.log(a), cache_file=cache_file
574
+ )
465
575
 
466
576
  n_grid = len(grid)
467
577
  a = a[-n_grid:]
@@ -469,34 +579,34 @@ def src_m_column_j(arg):
469
579
  theta = y[:, 2] * onek
470
580
  delta_b = y[:, 3]
471
581
  theta_b = y[:, 4] * onek
472
- H = self._background.H(a) / (self._params.H0 * self._params.rh)
582
+ H = H_ / (_params.H0 * _params.rh)
473
583
  omega_nu_m = 0.0
474
584
  P_nu_m = 0.0
475
- omega_m_tot = self._params.omega_m
476
- omega_plus_p_m_tot = self._params.omega_m
585
+ omega_m_tot = _params.omega_m
586
+ omega_plus_p_m_tot = _params.omega_m
477
587
  # include massive neutrinos in the total matter term
478
588
  src_col = np.zeros((n_grid,))
479
- if self._params.N_massive_nu != 0:
480
- omega_nu_m = self._wrapper.omega_nu_m_ufunc(a)
481
- P_nu_m = self._wrapper.P_nu_m_ufunc(a)
589
+ if _params.N_massive_nu != 0:
590
+ omega_nu_m = _wrapper.omega_nu_m_ufunc(a)
591
+ P_nu_m = _wrapper.P_nu_m_ufunc(a)
482
592
  omega_m_tot += omega_nu_m / a
483
593
  omega_plus_p_m_tot += (omega_nu_m + P_nu_m) / a
484
- delta_nu_m = self._wrapper.delta_nu_m_ufunc(a, y[1:])
485
- theta_nu_m = onek * self._wrapper.u_nu_m_ufunc(a, y[1:])
594
+ delta_nu_m = _wrapper.delta_nu_m_ufunc(a, y[1:])
595
+ theta_nu_m = onek * _wrapper.u_nu_m_ufunc(a, y[1:])
486
596
  src_col += (
487
597
  delta_nu_m * omega_nu_m / a / omega_m_tot
488
- + (3 * a * H / onek ** 2)
598
+ + (3 * a * H / onek**2)
489
599
  * theta_nu_m
490
600
  * (omega_nu_m + P_nu_m)
491
601
  / a
492
602
  / omega_plus_p_m_tot
493
603
  )
494
604
 
495
- delta_m_tot = self._params.omega_dm * delta + self._params.omega_b * delta_b
496
- theta_m_tot = self._params.omega_dm * theta + self._params.omega_b * theta_b
605
+ delta_m_tot = _params.omega_dm * delta + _params.omega_b * delta_b
606
+ theta_m_tot = _params.omega_dm * theta + _params.omega_b * theta_b
497
607
 
498
608
  src_col += (
499
609
  delta_m_tot / omega_m_tot
500
- + (3 * a * H / onek ** 2) * theta_m_tot / omega_plus_p_m_tot
610
+ + (3 * a * H / onek**2) * theta_m_tot / omega_plus_p_m_tot
501
611
  )
502
612
  return src_col
@@ -33,6 +33,7 @@ class LsodaSolver:
33
33
  atol,
34
34
  max_bdf_order,
35
35
  max_iter,
36
+ h0,
36
37
  cosmology,
37
38
  fast_solver,
38
39
  **extra_args_for_solver,
@@ -42,15 +43,16 @@ class LsodaSolver:
42
43
  self.atol = atol
43
44
  self.max_bdf_order = max_bdf_order
44
45
  self.max_iter = max_iter
46
+ self.h0 = h0
45
47
  self.extra_args_for_solver = extra_args_for_solver
46
48
 
47
49
  self.params = cosmology.params
48
- self.cosmology = cosmology
49
- self.background = cosmology.background
50
- self.fast_solver = fast_solver
51
-
50
+ # self.background = cosmology.background
52
51
  self.wrapper = cosmology._wrapper
53
52
 
53
+ assert fast_solver, "slow solver not supported anymore"
54
+ self.fast_solver = fast_solver
55
+
54
56
  def initial_conditions(self, k):
55
57
  self.wrapper.set_globals(k=k)
56
58
 
@@ -59,8 +61,8 @@ class LsodaSolver:
59
61
  )
60
62
  if initial_conditions is None:
61
63
  raise ValueError(
62
- "initial conditions '{}' not implemented.".format(
63
- self.params.initial_conditions
64
+ "{}: initial conditions '{}' not implemented.".format(
65
+ self.wrapper, self.params.initial_conditions
64
66
  )
65
67
  )
66
68
 
@@ -108,27 +110,20 @@ class LsodaSolver:
108
110
  grid = grid[grid > lna0]
109
111
  grid = np.concatenate(([lna0], grid))
110
112
 
111
- atol = self.atol
112
- rtol = self.rtol
113
- max_order = self.max_bdf_order
114
- max_iter = self.max_iter
115
-
116
- if self.fast_solver:
117
- solver = getattr(self.wrapper, "solve_fast_" + self.SOLVER_ID)
118
- else:
119
- solver = getattr(self.wrapper, "solve_" + self.SOLVER_ID)
113
+ solver = getattr(self.wrapper, "solve_fast_" + self.SOLVER_ID)
120
114
 
121
115
  with warnings.catch_warnings():
122
116
  warnings.simplefilter("ignore")
123
117
  y, meta = solver(
124
118
  y_0,
125
119
  grid,
126
- rtol,
127
- atol,
128
- max_order=max_order,
129
- max_iter=max_iter,
120
+ self.rtol,
121
+ self.atol,
122
+ max_order=self.max_bdf_order,
123
+ max_iter=self.max_iter,
130
124
  enable_fast_solver=enable_fast_solver,
131
125
  enable_sparse_lu_solver=enable_sparse_lu_solver,
126
+ h0=self.h0,
132
127
  )
133
128
  if meta["istate"] <= 0:
134
129
  raise RuntimeError(f"solving ode failed for k = {k}, meta={meta}")