Skip to content

Commit 6583408

Browse files
authored
Merge pull request #79 from CosmologicalEmulators/develop
Develop
2 parents d6bb89f + f51ef37 commit 6583408

6 files changed

Lines changed: 59 additions & 36 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
with:
4747
directories: src,ext
4848
- uses: codecov/codecov-action@v5
49-
env:
50-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5149
with:
52-
file: lcov.info
50+
files: lcov.info
51+
token: ${{ secrets.CODECOV_TOKEN }}
52+
fail_ci_if_error: false

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "AbstractCosmologicalEmulators"
22
uuid = "c83c1981-e5c4-4837-9eb8-c9b1572acfc6"
3-
version = "0.9.2"
3+
version = "0.9.3"
44
authors = ["Marco Bonici <bonici.marco@gmail.com>"]
55

66
[deps]
@@ -60,9 +60,10 @@ Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
6060
NPZ = "15e1cf62-19b3-5cfa-8e77-841668bca605"
6161
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
6262
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
63+
SciMLSensitivity = "1ed8b502-d754-442c-8d5d-10ac956f44a1"
6364
SimpleChains = "de6bee2f-e2f4-4ec7-b6ed-219cc6f6e9e5"
6465
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
6566
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
6667

6768
[targets]
68-
test = ["ADTypes", "DataInterpolations", "DifferentiationInterface", "FastChebInterp", "FastGaussQuadrature", "FiniteDifferences", "ForwardDiff", "Integrals", "JSON", "LinearAlgebra", "Lux", "Mooncake", "NPZ", "OrdinaryDiffEqTsit5", "Random", "SimpleChains", "Test", "Zygote"]
69+
test = ["ADTypes", "DataInterpolations", "DifferentiationInterface", "FastChebInterp", "FastGaussQuadrature", "FiniteDifferences", "ForwardDiff", "Integrals", "JSON", "LinearAlgebra", "Lux", "Mooncake", "NPZ", "OrdinaryDiffEqTsit5", "Random", "SciMLSensitivity", "SimpleChains", "Test", "Zygote"]

ext/BackgroundCosmologyExt/background.jl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,30 @@ function _Ωma(a, cosmo::w0waCDMCosmology)
116116
return _Ωma(a, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0)
117117
end
118118

119-
function r̃_z(z::Number, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0)
120-
z_array, weigths_array = _transformed_weights(FastGaussQuadrature.gausslegendre, 9, 0, z)
119+
function r̃_z(z::Number, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0, order=9)
120+
z_array, weigths_array = _transformed_weights(FastGaussQuadrature.gausslegendre, order, 0, z)
121121
integrand_array = 1.0 ./ E_a(_a_z(z_array), Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0)
122122
return dot(weigths_array, integrand_array)
123123
end
124124

125-
function r̃_z(z::AbstractArray, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0)
126-
return [r̃_z(zi, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0) for zi in z]
125+
function r̃_z(z::AbstractArray, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0, order=9)
126+
return [r̃_z(zi, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0, order=order) for zi in z]
127127
end
128128

129-
function r̃_z(z, cosmo::w0waCDMCosmology)
129+
function r̃_z(z, cosmo::w0waCDMCosmology; order=9)
130130
Ωcb0 = (cosmo.ωb + cosmo.ωc) / cosmo.h^2
131131
Ωk0 = cosmo.ωk / cosmo.h^2
132-
return r̃_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0)
132+
return r̃_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0, order=order)
133133
end
134134

135-
function r_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0)
136-
return c_0 * r̃_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0) / (100 * h)
135+
function r_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0, order=9)
136+
return c_0 * r̃_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0, order=order) / (100 * h)
137137
end
138138

139-
function r_z(z, cosmo::w0waCDMCosmology)
139+
function r_z(z, cosmo::w0waCDMCosmology; order=9)
140140
Ωcb0 = (cosmo.ωb + cosmo.ωc) / cosmo.h^2
141141
Ωk0 = cosmo.ωk / cosmo.h^2
142-
return r_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0)
142+
return r_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0, order=order)
143143
end
144144

145145
function S_of_K::Number, r)
@@ -154,54 +154,54 @@ function S_of_K(Ω::Number, r)
154154
end
155155
end
156156

157-
function d̃M_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0)
158-
return S_of_K(Ωk0, r̃_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0))
157+
function d̃M_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0, order=9)
158+
return S_of_K(Ωk0, r̃_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0, order=order))
159159
end
160160

161-
function d̃M_z(z, cosmo::w0waCDMCosmology)
161+
function d̃M_z(z, cosmo::w0waCDMCosmology; order=9)
162162
Ωcb0 = (cosmo.ωb + cosmo.ωc) / cosmo.h^2
163163
Ωk0 = cosmo.ωk / cosmo.h^2
164-
return d̃M_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0)
164+
return d̃M_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0, order=order)
165165
end
166166

167-
function dM_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0)
168-
return c_0 * d̃M_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0) / (100 * h)
167+
function dM_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0, order=9)
168+
return c_0 * d̃M_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0, order=order) / (100 * h)
169169
end
170170

171-
function dM_z(z, cosmo::w0waCDMCosmology)
171+
function dM_z(z, cosmo::w0waCDMCosmology; order=9)
172172
Ωcb0 = (cosmo.ωb + cosmo.ωc) / cosmo.h^2
173173
Ωk0 = cosmo.ωk / cosmo.h^2
174-
return dM_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0)
174+
return dM_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0, order=order)
175175
end
176176

177-
function d̃A_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0)
178-
return d̃M_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0) ./ (1 .+ z)
177+
function d̃A_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0, order=9)
178+
return d̃M_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0, order=order) ./ (1 .+ z)
179179
end
180180

181-
function d̃A_z(z, cosmo::w0waCDMCosmology)
181+
function d̃A_z(z, cosmo::w0waCDMCosmology; order=9)
182182
Ωcb0 = (cosmo.ωb + cosmo.ωc) / cosmo.h^2
183183
Ωk0 = cosmo.ωk / cosmo.h^2
184-
return d̃A_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0)
184+
return d̃A_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0, order=order)
185185
end
186186

187-
function dA_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0)
188-
return dM_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0) ./ (1 .+ z)
187+
function dA_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0, order=9)
188+
return dM_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0, order=order) ./ (1 .+ z)
189189
end
190190

191-
function dA_z(z, cosmo::w0waCDMCosmology)
191+
function dA_z(z, cosmo::w0waCDMCosmology; order=9)
192192
Ωcb0 = (cosmo.ωb + cosmo.ωc) / cosmo.h^2
193193
Ωk0 = cosmo.ωk / cosmo.h^2
194-
return dA_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0)
194+
return dA_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0, order=order)
195195
end
196196

197-
function dL_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0)
198-
return dM_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0) .* (1 .+ z)
197+
function dL_z(z, Ωcb0, h; mν=0.0, w0=-1.0, wa=0.0, Ωk0=0.0, order=9)
198+
return dM_z(z, Ωcb0, h; mν=mν, w0=w0, wa=wa, Ωk0=Ωk0, order=order) .* (1 .+ z)
199199
end
200200

201-
function dL_z(z, cosmo::w0waCDMCosmology)
201+
function dL_z(z, cosmo::w0waCDMCosmology; order=9)
202202
Ωcb0 = (cosmo.ωb + cosmo.ωc) / cosmo.h^2
203203
Ωk0 = cosmo.ωk / cosmo.h^2
204-
return dL_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0)
204+
return dL_z(z, Ωcb0, cosmo.h; mν=cosmo.mν, w0=cosmo.w0, wa=cosmo.wa, Ωk0=Ωk0, order=order)
205205
end
206206

207207
function _growth!(du, u, p, loga)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ using DataInterpolations
1515
using LinearAlgebra
1616
using FastGaussQuadrature
1717
using FiniteDifferences
18+
using SciMLSensitivity
1819
using AbstractCosmologicalEmulators
1920

2021
@testset "AbstractEmulators test" begin

test/test_background.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ if !isnothing(ext)
335335
@test isapprox(dL_z(2.0, Ωcb0_class, h_class; mν=mν_class, w0=w0_class, wa=wa_class), 17445.761528257153, rtol=1e-4)
336336
@test isapprox(dA_z(2.0, Ωcb0_class, h_class; mν=mν_class, w0=w0_class, wa=wa_class), 1938.4179475841324, rtol=1e-4)
337337
end
338+
339+
@testset "z =1200.0" begin
340+
@test isapprox(r_z(1200.0, Ωcb0_class, h_class; mν=mν_class, w0=w0_class, wa=wa_class, order=120), 14405.271466533255, rtol=2e-3)
341+
@test isapprox(dL_z(1200.0, Ωcb0_class, h_class; mν=mν_class, w0=w0_class, wa=wa_class, order=120), 17300731.03130642, rtol=2e-3)
342+
@test isapprox(dA_z(1200.0, Ωcb0_class, h_class; mν=mν_class, w0=w0_class, wa=wa_class, order=120), 11.9943975574798, rtol=2e-3)
343+
end
338344
end
339345

340346
@testset "CLASS comparison tests - cosmology 2" begin
@@ -375,6 +381,12 @@ if !isnothing(ext)
375381
@test isapprox(dL_z(2.0, Ωcb0_class2, h_class2; mν=mν_class2, w0=w0_class2, wa=wa_class2), 15764.581310383495, rtol=1e-4)
376382
@test isapprox(dA_z(2.0, Ωcb0_class2, h_class2; mν=mν_class2, w0=w0_class2, wa=wa_class2), 1751.6201455981693, rtol=1e-4)
377383
end
384+
385+
@testset "z = 1200.0" begin
386+
@test isapprox(r_z(1200.0, Ωcb0_class2, h_class2; mν=mν_class2, w0=w0_class2, wa=wa_class2, order=120), 12906.201419127055, rtol=2e-3)
387+
@test isapprox(dL_z(1200.0, Ωcb0_class2, h_class2; mν=mν_class2, w0=w0_class2, wa=wa_class2, order=120), 15500347.904371575, rtol=2e-3)
388+
@test isapprox(dA_z(1200.0, Ωcb0_class2, h_class2; mν=mν_class2, w0=w0_class2, wa=wa_class2, order=120), 10.746212672045832, rtol=2e-3)
389+
end
378390
end
379391

380392
@testset "CLASS comparison tests - cosmology 3" begin
@@ -416,6 +428,13 @@ if !isnothing(ext)
416428
@test isapprox(dL_z(2.0, Ωcb0_class3, h_class3; mν=mν_class3, w0=w0_class3, wa=wa_class3, Ωk0=Ωk0_class3), 11240.362895970827594, rtol=1e-4)
417429
@test isapprox(dA_z(2.0, Ωcb0_class3, h_class3; mν=mν_class3, w0=w0_class3, wa=wa_class3, Ωk0=Ωk0_class3), 1248.929210663426375, rtol=1e-4)
418430
end
431+
432+
# z = 2.0 values
433+
@testset "z = 1200.0" begin
434+
@test isapprox(r_z(1200.0, Ωcb0_class3, h_class3; mν=mν_class3, w0=w0_class3, wa=wa_class3, Ωk0=Ωk0_class3, order=120), 10695.833449050964, rtol=2e-3)
435+
@test isapprox(dL_z(1200.0, Ωcb0_class3, h_class3; mν=mν_class3, w0=w0_class3, wa=wa_class3, Ωk0=Ωk0_class3, order=120), 15749661.605665019, rtol=2e-3)
436+
@test isapprox(dA_z(1200.0, Ωcb0_class3, h_class3; mν=mν_class3, w0=w0_class3, wa=wa_class3, Ωk0=Ωk0_class3, order=120), 10.919058989604848, rtol=2e-3)
437+
end
419438
end
420439

421440
@testset "Missing coverage tests" begin

test/test_lux_emulator_autodiff.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ using Mooncake
2525
n_output = 10
2626

2727
# Create a Lux neural network
28+
# We use a closure for tanh to avoid internal mapping to tanh_fast
29+
# which can cause issues with Mooncake in some environments
2830
lux_model = Chain(
29-
Dense(n_input => 8, tanh),
31+
Dense(n_input => 8, x -> tanh(x)),
3032
Dense(8 => n_output)
3133
)
3234

0 commit comments

Comments
 (0)