From 390341f3ee3b6894aa0600710aef8901011590a8 Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Wed, 6 Mar 2024 10:58:56 -0500 Subject: [PATCH] Fix tests --- src/default.jl | 6 ++---- src/utils.jl | 1 + test/misc/polyalg_tests.jl | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/default.jl b/src/default.jl index d7f00edb9..cdcfb6825 100644 --- a/src/default.jl +++ b/src/default.jl @@ -142,13 +142,12 @@ end resids = map(x -> Symbol("$(x)_resid"), cache_syms) for (sym, resid) in zip(cache_syms, resids) - push!(calls, :($(resid) = get_fu($(sym)))) + push!(calls, :($(resid) = @isdefined($(sym)) ? get_fu($(sym)) : nothing)) end push!(calls, quote fus = tuple($(Tuple(resids)...)) minfu, idx = __findmin(cache.internalnorm, fus) - idx += cache.alg.start_index - 1 stats = __compile_stats(cache.caches[idx]) u = get_u(cache.caches[idx]) retcode = cache.caches[idx].retcode @@ -225,13 +224,12 @@ for (probType, pType) in ((:NonlinearProblem, :NLS), (:NonlinearLeastSquaresProb resids = map(x -> Symbol("$(x)_resid"), sol_syms) for (sym, resid) in zip(sol_syms, resids) - push!(calls, :($(resid) = $(sym).resid)) + push!(calls, :($(resid) = @isdefined($(sym)) ? $(sym).resid : nothing)) end push!(calls, quote resids = tuple($(Tuple(resids)...)) minfu, idx = __findmin(DEFAULT_NORM, resids) - idx += alg.start_index - 1 end) for i in 1:N diff --git a/src/utils.jl b/src/utils.jl index aec66bdd4..259ff945a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -99,6 +99,7 @@ function __findmin_caches(f, caches) end function __findmin(f, x) return findmin(x) do xᵢ + xᵢ === nothing && return Inf fx = f(xᵢ) return isnan(fx) ? Inf : fx end diff --git a/test/misc/polyalg_tests.jl b/test/misc/polyalg_tests.jl index 7b7fe6880..c5f1a8eb3 100644 --- a/test/misc/polyalg_tests.jl +++ b/test/misc/polyalg_tests.jl @@ -84,10 +84,8 @@ end Broyden(; autodiff = AutoFiniteDiff()), LimitedMemoryBroyden())) # Uses the `__solve` function - solver = solve(probN; abstol = 1e-9) - @test SciMLBase.successful_retcode(solver) + @test_throws MethodError solve(probN; abstol = 1e-9) @test_throws MethodError solve(probN, RobustMultiNewton(); abstol = 1e-9) - @test SciMLBase.successful_retcode(solver) solver = solve(probN, RobustMultiNewton(; autodiff = AutoFiniteDiff()); abstol = 1e-9) @test SciMLBase.successful_retcode(solver) solver = solve(