Skip to content

Commit

Permalink
fix: :misc testing
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 23, 2024
1 parent 6dbc95e commit 1a29122
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/NonlinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ include("algorithms/levenberg_marquardt.jl")
include("algorithms/trust_region.jl")
include("algorithms/extension_algs.jl")

include("internal/forward_diff.jl") # we need to define after the algorithms

include("utils.jl")
include("default.jl")

include("internal/forward_diff.jl") # we need to define after the algorithms

# @setup_workload begin
# nlfuncs = ((NonlinearFunction{false}((u, p) -> u .* u .- p), 0.1),
# (NonlinearFunction{true}((du, u, p) -> du .= u .* u .- p), [0.1]))
Expand Down
6 changes: 4 additions & 2 deletions src/internal/forward_diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ for algType in (
Nothing, AbstractNonlinearSolveAlgorithm, GeneralizedDFSane,
GeneralizedFirstOrderAlgorithm, ApproximateJacobianSolveAlgorithm,
LeastSquaresOptimJL, FastLevenbergMarquardtJL, CMINPACK, NLsolveJL, NLSolversJL,
SpeedMappingJL, FixedPointAccelerationJL, SIAMFANLEquationsJL
SpeedMappingJL, FixedPointAccelerationJL, SIAMFANLEquationsJL,
NonlinearSolvePolyAlgorithm{:NLLS, <:Any}, NonlinearSolvePolyAlgorithm{:NLS, <:Any}
)
@eval function SciMLBase.__solve(
prob::DualNonlinearProblem, alg::$(algType), args...; kwargs...)
Expand Down Expand Up @@ -47,7 +48,8 @@ for algType in (
SimpleNonlinearSolve.AbstractSimpleNonlinearSolveAlgorithm,
GeneralizedFirstOrderAlgorithm, ApproximateJacobianSolveAlgorithm,
LeastSquaresOptimJL, FastLevenbergMarquardtJL, CMINPACK, NLsolveJL, NLSolversJL,
SpeedMappingJL, FixedPointAccelerationJL, SIAMFANLEquationsJL
SpeedMappingJL, FixedPointAccelerationJL, SIAMFANLEquationsJL,
NonlinearSolvePolyAlgorithm{:NLLS, <:Any}, NonlinearSolvePolyAlgorithm{:NLS, <:Any}
)
@eval function SciMLBase.__init(
prob::DualNonlinearProblem, alg::$(algType), args...; kwargs...)
Expand Down
6 changes: 4 additions & 2 deletions src/internal/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ function __construct_extension_f(prob::AbstractNonlinearProblem; alias_u0::Bool
end

function __construct_extension_jac(prob, alg, u0, fu; can_handle_oop::Val = False,
can_handle_scalar::Val = False, kwargs...)
can_handle_scalar::Val = False, autodiff = nothing, kwargs...)
autodiff = select_jacobian_autodiff(prob, autodiff)

Jₚ = JacobianCache(
prob, alg, prob.f, fu, u0, prob.p; stats = empty_nlstats(), kwargs...)
prob, alg, prob.f, fu, u0, prob.p; stats = empty_nlstats(), autodiff, kwargs...)

𝓙 = (can_handle_scalar === False && prob.u0 isa Number) ? @closure(u->[Jₚ(u[1])]) : Jₚ

Expand Down
15 changes: 5 additions & 10 deletions src/internal/linear_solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ function (cache::LinearSolverCache)(;
if linres.retcode === ReturnCode.Failure
structured_mat = ArrayInterface.isstructured(cache.lincache.A)
is_gpuarray = ArrayInterface.device(cache.lincache.A) isa ArrayInterface.GPU
if !(cache.linsolve isa QRFactorization{ColumnNorm}) &&
!is_gpuarray &&
if !(cache.linsolve isa QRFactorization{ColumnNorm}) && !is_gpuarray &&
!structured_mat
if verbose
@warn "Potential Rank Deficient Matrix Detected. Attempting to solve using \
Expand All @@ -177,15 +176,11 @@ function (cache::LinearSolverCache)(;
return LinearSolveResult(; u = linres.u)
elseif !(cache.linsolve isa QRFactorization{ColumnNorm})
if verbose
if structured_mat
if structured_mat || is_gpuarray
mat_desc = structured_mat ? "Structured" : "GPU"
@warn "Potential Rank Deficient Matrix Detected. But Matrix is \
Structured. Currently, we don't attempt to solve Rank Deficient \
Structured Matrices. Please open an issue at \
https://github.com/SciML/NonlinearSolve.jl"
elseif is_gpuarray
@warn "Potential Rank Deficient Matrix Detected. But Matrix is on GPU. \
Currently, we don't attempt to solve Rank Deficient GPU \
Matrices. Please open an issue at \
$(mat_desc). Currently, we don't attempt to solve Rank Deficient \
$(mat_desc) Matrices. Please open an issue at \
https://github.com/SciML/NonlinearSolve.jl"
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/misc/aliasing_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

# If aliasing is not handled properly this will diverge
sol = solve(prob; abstol = 1e-6, alias_u0 = true,
termination_condition = AbsNormTerminationMode())
termination_condition = AbsNormTerminationMode(Base.Fix1(maximum, abs)))

@test sol.u === prob.u0
@test SciMLBase.successful_retcode(sol.retcode)

prob = remake(prob; u0 = copy(u0))

cache = init(prob; abstol = 1e-6, alias_u0 = true,
termination_condition = AbsNormTerminationMode())
termination_condition = AbsNormTerminationMode(Base.Fix1(maximum, abs)))
sol = solve!(cache)

@test sol.u === prob.u0
Expand Down

0 comments on commit 1a29122

Please sign in to comment.