Skip to content

Commit

Permalink
autodiff test for Mch
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisrkckl committed May 22, 2023
1 parent 4deca65 commit 51be2e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulAstro = "6112ee07-acf9-5e0f-b108-d242c714bf9f"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2 changes: 1 addition & 1 deletion src/paramutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Mpc_to_s = uconvert(u"s", u"Mpc" / c_0).val
const year_to_s = 365.25 * 24 * 3600

function mass_from_log10_mass(log10_M::Float64, eta::Float64)::Mass
M::Float64 = 0.0^log10_M * Msun_to_s
M::Float64 = 10.0^log10_M * Msun_to_s
return Mass(M, eta)
end

Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using LinearAlgebra
using UnPack
using NumericalIntegration
using Statistics
using Zygote


e_from_τ_from_e(ecc::Float64)::Float64 = e_from_τ(τ_from_e(Eccentricity(ecc))).e
Expand Down Expand Up @@ -911,4 +912,15 @@ e_from_τ_from_e(ecc::Float64)::Float64 = e_from_τ(τ_from_e(Eccentricity(ecc))
@test m1.m m2.m atol = 1e-6
end

@testset "autodiff" begin
m = 1000.0
η = 0.2

@testset "parameters and conversions" begin
chirp_mass = (m, η) -> Mass(m, η).Mch
Mch = chirp_mass(m, η)
∂Mch_∂m, ∂Mch_∂η = gradient(chirp_mass, m, η)
@test ∂Mch_∂m Mch / m && ∂Mch_∂η (3/5)*Mch/η
end
end
end

0 comments on commit 51be2e3

Please sign in to comment.