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

custom linear solve function #112

Merged
merged 26 commits into from
Apr 7, 2022
Merged

custom linear solve function #112

merged 26 commits into from
Apr 7, 2022

Conversation

vpuri3
Copy link
Member

@vpuri3 vpuri3 commented Apr 1, 2022

fixes #110

would be good to have

@vpuri3
Copy link
Member Author

vpuri3 commented Apr 1, 2022

suggestion from Daniel Wennberg on DiffEq-bridged from Julia Slack

if applicable(ldiv!, A, b)
    [ldiv! code]
else
    [no-ldiv! code]
end

@vpuri3
Copy link
Member Author

vpuri3 commented Apr 1, 2022

julia> using LinearSolve, LinearAlgebra;prob=LinearProblem(Diagonal(rand(4)),rand(4);u0=rand(4)); alg=FunctionCall(ldiv!, (:u, :A, :b)); cache=SciMLBase.init(prob, alg); solve(cache)
u: 4-element Vector{Float64}:
 0.07077439381665458
 1.22568741027046
 1.2092496048689403
 1.3612307917964956

alg works. now need to figure out default triage

@ChrisRackauckas
Copy link
Member

For the diagonal case, it would probably be best just keep the standard format via using factorize

julia> A = Diagonal(rand(2))
2×2 Diagonal{Float64, Vector{Float64}}:
 0.241201   
          0.0374477

julia> factorize(A)
2×2 Diagonal{Float64, Vector{Float64}}:
 0.241201   
          0.0374477

which should be the current default?

src/default.jl Outdated
if A isa DiffEqArrayOperator
A = A.A
end

if applicable(ldiv!, A, u)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this check static?

@vpuri3
Copy link
Member Author

vpuri3 commented Apr 3, 2022

i don't understand what's causing type instability so ive pushed a few options to src/function_call.jl. LMK what their comparative performance advantages are. Ive added the use cases in test/basictests.jl. the ability to define custom inverse functions for custom types or standard types would be cool to have.

ive also reverted all changes to default.jl so we can figure ^ out first


##

""" apply ldiv!(A, u) """
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be type stable, correct @ChrisRackauckas ?

@ChrisRackauckas
Copy link
Member

The more sane way of doing this is to just impose a function syntax. For example, impose that it's always (u,A,b), but don't force that a function uses all of them. You probably want to take a conservatively large set of possible arguments for that.

@vpuri3
Copy link
Member Author

vpuri3 commented Apr 6, 2022

CI

@vpuri3 vpuri3 closed this Apr 6, 2022
@vpuri3 vpuri3 reopened this Apr 6, 2022
@vpuri3 vpuri3 changed the title [WIP] use ldiv! if available use ldiv! if available Apr 6, 2022
@vpuri3 vpuri3 changed the title use ldiv! if available custom linear solve function Apr 6, 2022
@vpuri3
Copy link
Member Author

vpuri3 commented Apr 6, 2022

weird tests didn't run. closing/opening again

@vpuri3 vpuri3 closed this Apr 6, 2022
@vpuri3 vpuri3 reopened this Apr 6, 2022
@vpuri3
Copy link
Member Author

vpuri3 commented Apr 6, 2022

@ChrisRackauckas can you take a look, and run CI? tests aren't running for me

@ChrisRackauckas
Copy link
Member

Needs documentation.

@ChrisRackauckas
Copy link
Member

Otherwise I think this looks good to go.

@ChrisRackauckas
Copy link
Member

Rebase this onto master.

@codecov
Copy link

codecov bot commented Apr 6, 2022

Codecov Report

Merging #112 (b692761) into main (1186046) will increase coverage by 1.05%.
The diff coverage is 88.88%.

@@            Coverage Diff             @@
##             main     #112      +/-   ##
==========================================
+ Coverage   58.15%   59.20%   +1.05%     
==========================================
  Files          10       11       +1     
  Lines         595      603       +8     
==========================================
+ Hits          346      357      +11     
+ Misses        249      246       -3     
Impacted Files Coverage Δ
src/LinearSolve.jl 20.00% <0.00%> (-5.00%) ⬇️
src/common.jl 73.91% <100.00%> (+8.69%) ⬆️
src/solve_function.jl 100.00% <100.00%> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@vpuri3
Copy link
Member Author

vpuri3 commented Apr 6, 2022

rebased, tests passing

@vpuri3
Copy link
Member Author

vpuri3 commented Apr 6, 2022

merge, @ChrisRackauckas ?

@ChrisRackauckas
Copy link
Member

Needs docs.

@coveralls
Copy link

coveralls commented Apr 6, 2022

Pull Request Test Coverage Report for Build 2105740759

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 8 of 9 (88.89%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+59.6%) to 59.635%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/LinearSolve.jl 0 1 0.0%
Totals Coverage Status
Change from base Build 2104845930: 59.6%
Covered Lines: 359
Relevant Lines: 602

💛 - Coveralls

@vpuri3
Copy link
Member Author

vpuri3 commented Apr 7, 2022

docs added

end

Base.@kwdef struct LinearSolveFunction{F} <: AbstractSolveFunction
solve_func::F = DEFAULT_LINEAR_SOLVE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there should be a default here. If they use LinearSolveFunction, they are explicitly opting out of using the default, so it would be unsafe to just make it fallback. Instead, it should error and say hey, didn't you wish to provide a function here?

test/basictests.jl Outdated Show resolved Hide resolved
@ChrisRackauckas ChrisRackauckas merged commit c960f8f into SciML:main Apr 7, 2022
@vpuri3 vpuri3 deleted the vp-ldiv branch April 7, 2022 12:02
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

Successfully merging this pull request may close these issues.

default branching to factorization on Diagonal type
3 participants