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

Setup with LinearSolve.jl #24

Open
ChrisRackauckas opened this issue Dec 19, 2021 · 1 comment
Open

Setup with LinearSolve.jl #24

ChrisRackauckas opened this issue Dec 19, 2021 · 1 comment

Comments

@ChrisRackauckas
Copy link

I'm trying to get more libraries using the LinearSolve.jl interface

http://linearsolve.sciml.ai/dev/

It's pretty complete now. The suggested form is that you use the caching interface so that it can store factorizations and iterative solver inits (http://linearsolve.sciml.ai/dev/tutorials/caching_interface/). The suggested algorithm form is to just have the user pass the type, like Newton(; linsolve=KLU()) which would then switch over to using SuiteSparse.KLU and accelerate sparse matrix factorizations for unstructured cases over UMFPACK. http://linearsolve.sciml.ai/dev/solvers/solvers/#SuiteSparse.jl

@longemen3000
Copy link
Contributor

longemen3000 commented Mar 4, 2022

one way to do this is to delay the constructor of the linsolve struct until inside the solve function, something like:

struct LinearSolveCache{T}
  linsolve::T
end

function (cache::LinearSolveCache)(d, B, g)
  LinearSolve.set_a(cache.linsolve.cache,B)
  LinearSolve.set_b(cache.linsolve.cache,g)
  solve(cache.linsolve)
  d .= cache.linsolve.u
end

#does it work with static arrays?
function (cache::LinearSolveCache)(B, g)
  prob = LinearProblem(B,g)
  solve(prob,cache.linsolve)
  prob.u
end

init_linsolve(linsolve::T,A,b) where T <: Function = linsolve
init_linsolve(linsolve:::LinearSolve.SciMLLinearSolveAlgorithm) = LinearSolveCache(init(LinearProblem(A,b),linsolve))

and then add those inits in the newton solver for NeqProblem and OptimizationProblem (the last one seems harder, but it could be added to the objvars result?
what do you think @pkofod ?

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