-
Notifications
You must be signed in to change notification settings - Fork 20
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
Initial infrastructure for Krylov-based linear solvers #56
Conversation
Codecov Report
@@ Coverage Diff @@
## master #56 +/- ##
==========================================
- Coverage 89.72% 89.67% -0.05%
==========================================
Files 30 31 +1
Lines 2073 2122 +49
==========================================
+ Hits 1860 1903 +43
- Misses 213 219 +6
Continue to review full report at Codecov.
|
v1 = zeros(Tv, n) | ||
v2 = zeros(Tv, m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should move v1
and v2
in KrylovPDSolver
structure and allocate them only once.
D = Diagonal(d) | ||
|
||
# Set-up right-hand side | ||
ξ_ = ξp .+ kkt.A * (D * ξd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use v1
and v2
here to avoid 2 new allocations at each solve!
pass:
mul!(v1, D, ξd)
mul!(v2, kkt.A, v1)
v2 .+= ξp
dy .= _dy | ||
|
||
# Recover dx | ||
dx .= D * (kkt.A' * dy - ξd) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could reuse v1
and v2
:
mul!(v1, kkt.A', dy)
v1 .-= ξd
mul!(v2, D, v1)
src/KKTSolver/krylov.jl
Outdated
d = one(Float64) ./ (kkt.θ .+ kkt.regP) | ||
D = Diagonal(d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to form d
and D
explicitly. If you want to keep it because it's more user-friendly, I recommend to preallocate a vector d
inside the KrylovPDSolver
structure and reuse the memory.
src/KKTSolver/krylov.jl
Outdated
d = one(Float64) ./ (kkt.θ .+ kkt.regP) | ||
D = Diagonal(d) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v3 = zeros(Tv, n)
opD = LinearOperator(Tv, n, n, true, true, v -> v3 .= v ./ (kkt.θ .+ kkt.regP))
I don't want to optimize the code too much for now. |
I'm happy with the current state. @amontoison I will introduce Jacobi preconditioners in a forthcoming PR. |
Let's merge thIs PR. 👍 |
One last issue: unified syntax for the resolution of SQD systems. For functions like K = [-(Θ⁻¹ + Rp) Aᵀ; A Rd] # obviously this would be a linear operator
Δ, stats = minres(K, ξ) # solve 2x2 system
# Recover search directions
dx .= Δ[1:n]
dy .= Δ[n+1:m] while for _dx, _dy, stats = trimr(A, ξp, ξd) # solve 2x2 system
# Recover search directions
dx .= _dx
dy .= _dy We could have an internal flag for So, I suggest to have a |
I prefer the second solution with a |
cc @amontoison
This PR introduces some infrastructure for Krylov-based linear solvers.
There are no Krylov-specific algorithmic modifications to the IPM at this point.
TODO:
Decide on how to best implement preconditioners[left for future PR]Currently, a Krylov solver can be selected as follows:
the syntax also allows for passing a callback: