Skip to content

Commit

Permalink
Changed and fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanaelbosch committed Nov 9, 2023
1 parent cc3f3b2 commit 024f7b1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
20 changes: 12 additions & 8 deletions ext/DiffEqDevToolsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ function chi2(gaussian_estimate, actual_value)
return chi2_pinv
end

DiffEqDevTools.appxtrue(sol::ProbNumDiffEq.ProbODESolution, ref::TestSolution; kwargs...) =
__appxtrue(sol, ref; kwargs...)
DiffEqDevTools.appxtrue(
sol::ProbNumDiffEq.ProbODESolution,
ref::SciMLBase.AbstractODESolution;
kwargs...,
) = __appxtrue(sol, ref; kwargs...)
function DiffEqDevTools.appxtrue(sol::ProbNumDiffEq.ProbODESolution, ref::TestSolution; kwargs...)
ref.dense = sol.dense
out = DiffEqDevTools.appxtrue(mean(sol), ref; kwargs...)
out = _add_prob_errors!(out, sol, ref.interp)
return out
end

function __appxtrue(sol, ref; kwargs...)
function DiffEqDevTools.appxtrue(sol::ProbNumDiffEq.ProbODESolution, ref::SciMLBase.AbstractODESolution; kwargs...)
out = DiffEqDevTools.appxtrue(mean(sol), ref; dense_errors=sol.dense, kwargs...)
out = _add_prob_errors!(out, sol, ref)
return out
end

function _add_prob_errors!(out, sol, ref)
out.errors[:chi2_final] = chi2(sol.pu[end], ref.u[end])[1]
if :l2 in keys(out.errors)
out.errors[:chi2_steps] = mean(chi2.(sol.pu, ref.(sol.t)))
Expand Down
48 changes: 25 additions & 23 deletions test/diffeqdevtools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,37 @@ using DiffEqDevTools
using Plots

import ODEProblemLibrary: prob_ode_fitzhughnagumo
const prob = prob_ode_fitzhughnagumo
prob = prob_ode_fitzhughnagumo

const appxsol = solve(prob, Vern7(), abstol=1 / 10^14, reltol=1 / 10^14)
const test_sol = TestSolution(appxsol)
const appxsol_nondense =
ref = solve(prob, Vern7(), abstol=1 / 10^14, reltol=1 / 10^14)
test_sol = TestSolution(ref)
appxsol_nondense =
solve(prob, Vern7(), abstol=1 / 10^14, reltol=1 / 10^14, dense=false)
const test_sol_nondense = TestSolution(appxsol_nondense)
test_sol_nondense = TestSolution(appxsol_nondense)

@testset "appxtrue" begin
appxsol = appxtrue(solve(prob, EK1()), test_sol)
@test appxsol.errors isa Dict
@test :final in keys(appxsol.errors)
@test :l2 in keys(appxsol.errors)
@test :L2 in keys(appxsol.errors)
@test :l∞ in keys(appxsol.errors)
@test :L∞ in keys(appxsol.errors)
@testset "$S" for (S, _sol) in (("TestSolution", test_sol), ("ODESolution", ref))
appxsol = appxtrue(solve(prob, EK1()), _sol)
@test appxsol.errors isa Dict
@test :final in keys(appxsol.errors)
@test :l2 in keys(appxsol.errors)
@test :L2 in keys(appxsol.errors)
@test :l∞ in keys(appxsol.errors)
@test :L∞ in keys(appxsol.errors)

sol = solve(prob, EK1(smooth=false), dense=false)
appxsol = appxtrue(sol, test_sol)
@test appxsol.errors isa Dict
@test :final in keys(appxsol.errors)
@test :l2 in keys(appxsol.errors)
@test :l∞ in keys(appxsol.errors)
sol = solve(prob, EK1(smooth=false), dense=false)
appxsol = appxtrue(sol, _sol)
@test appxsol.errors isa Dict
@test :final in keys(appxsol.errors)
@test :l2 in keys(appxsol.errors)
@test :l∞ in keys(appxsol.errors)

appxsol = appxtrue(sol, test_sol_nondense)
@test appxsol.errors isa Dict
@test :final in keys(appxsol.errors)
@test :l2 in keys(appxsol.errors)
@test :l∞ in keys(appxsol.errors)
appxsol = appxtrue(sol, test_sol_nondense)
@test appxsol.errors isa Dict
@test :final in keys(appxsol.errors)
@test :l2 in keys(appxsol.errors)
@test :l∞ in keys(appxsol.errors)
end
end

@testset "WorkPrecision" begin
Expand Down

0 comments on commit 024f7b1

Please sign in to comment.