Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add autoscaling for trust region #425

Open
m-bossart opened this issue May 14, 2024 · 4 comments
Open

Add autoscaling for trust region #425

m-bossart opened this issue May 14, 2024 · 4 comments

Comments

@m-bossart
Copy link
Contributor

Add autoscaling option for trust region (and possibly other) methods.

@m-bossart
Copy link
Contributor Author

@avik-pal Can you point me to where this should be implemented. I'm trying to transition from NLsolve.jl to NonlinearSolve.jl but for some larger cases NLsolve.jl converges and NonlinearSolve.jl does not (for TrustRegion and Raphson algorithms). The lack of scaling is the most obvious difference to me.

@avik-pal
Copy link
Member

I haven't looked too much into how NLsolve does autoscaling. But it should probably go in

@inline (cache::JacobianCache)(u = cache.u) = cache(cache.J, u, cache.p)
@inline function (cache::JacobianCache)(::Nothing)
J = cache.J
J isa JacobianOperator && return StatefulJacobianOperator(J, cache.u, cache.p)
return J
end
function (cache::JacobianCache)(J::JacobianOperator, u, p = cache.p)
return StatefulJacobianOperator(J, u, p)
end
function (cache::JacobianCache)(::Number, u, p = cache.p) # Scalar
cache.stats.njacs += 1
J = last(__value_derivative(cache.autodiff, cache.uf, u))
return J
end
# Compute the Jacobian
function (cache::JacobianCache{iip})(
J::Union{AbstractMatrix, Nothing}, u, p = cache.p) where {iip}
cache.stats.njacs += 1
if iip
if has_jac(cache.f)
cache.f.jac(J, u, p)
else
sparse_jacobian!(J, cache.autodiff, cache.jac_cache, cache.uf, cache.fu, u)
end
J_ = J
else
J_ = if has_jac(cache.f)
cache.f.jac(u, p)
elseif __can_setindex(typeof(J))
sparse_jacobian!(J, cache.autodiff, cache.jac_cache, cache.uf, u)
J
else
sparse_jacobian(cache.autodiff, cache.jac_cache, cache.uf, u)
end
end
return J_
end

@m-bossart
Copy link
Contributor Author

Thanks. I will try to look into it

@avik-pal
Copy link
Member

avik-pal commented Nov 1, 2024

@m-bossart do you have a test case for this? Just so that when we implement it we can add it as a test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants