Skip to content

Commit a699425

Browse files
authored
Update PartitionedVectors.jl for Krylov.jl v0.10 (#55)
1 parent b7bb373 commit a699425

File tree

9 files changed

+36
-42
lines changed

9 files changed

+36
-42
lines changed

.cirrus.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
freebsd_instance:
2-
image: freebsd-13-0-release-amd64
2+
image: freebsd-14-2-release-amd64
33
task:
44
name: FreeBSD
55
env:
66
matrix:
7-
- JULIA_VERSION: 1.6
87
- JULIA_VERSION: 1
9-
- JULIA_VERSION: nightly
10-
allow_failures: $JULIA_VERSION == 'nightly'
118
install_script:
129
- sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)"
1310
build_script:

.github/workflows/Documentation.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ jobs:
1010
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v4
1414
- uses: julia-actions/setup-julia@latest
1515
with:
16-
version: '1.7'
16+
version: '1'
1717
- name: Install dependencies
1818
run: julia --project=docs -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
1919
- name: Build and deploy

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
version: ['1.6']
17-
os: [ubuntu-latest, macOS-latest, windows-latest]
16+
version: ['lts', '1']
17+
os: [ubuntu-latest, macos-latest, windows-latest]
1818
arch: [x64]
1919
allow_failure: [false]
2020
include:
21-
- version: 'nightly'
21+
- version: 'pre'
2222
os: ubuntu-latest
2323
arch: x64
2424
allow_failure: true
25-
- version: 'nightly'
25+
- version: 'pre'
2626
os: macOS-latest
2727
arch: x64
2828
allow_failure: true
29-
- version: 'nightly'
29+
- version: 'pre'
3030
os: windows-latest
3131
arch: x64
3232
allow_failure: true
3333
steps:
34-
- uses: actions/checkout@v2
35-
- uses: julia-actions/setup-julia@v1
34+
- uses: actions/checkout@v4
35+
- uses: julia-actions/setup-julia@v2
3636
with:
3737
version: ${{ matrix.version }}
3838
arch: ${{ matrix.arch }}
39-
- uses: actions/cache@v1
39+
- uses: actions/cache@v4
4040
env:
4141
cache-name: cache-artifacts
4242
with:
@@ -49,6 +49,6 @@ jobs:
4949
- uses: julia-actions/julia-buildpkg@v1
5050
- uses: julia-actions/julia-runtest@v1
5151
- uses: julia-actions/julia-processcoverage@v1
52-
- uses: codecov/codecov-action@v1
52+
- uses: codecov/codecov-action@v4
5353
with:
5454
file: lcov.info

Project.toml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125"
1010
PartitionedStructures = "a6683cb1-4e99-4d03-b5b5-b79ed0acabcf"
1111

1212
[compat]
13-
Krylov = "0.9.8"
13+
Krylov = "0.10.3"
1414
LinearOperators = "2.4.0"
1515
PartitionedStructures = "0.1.4, 0.1.5"
16-
julia = "^1.6.0"
16+
julia = "1.10"
1717

1818
[extras]
19-
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
20-
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
21-
LinearOperators = "5c8ed15e-5a4c-59e4-a42b-c7e8811fb125"
22-
PartitionedStructures = "a6683cb1-4e99-4d03-b5b5-b79ed0acabcf"
2319
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
2420
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2521

2622
[targets]
27-
test = ["Test", "LinearAlgebra", "StatsBase", "Krylov", "LinearOperators"]
23+
test = ["StatsBase", "Test"]

docs/Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ PartitionedStructures = "a6683cb1-4e99-4d03-b5b5-b79ed0acabcf"
66
PartitionedVectors = "9d5e22db-ddc8-46c9-8309-91b035e7f733"
77

88
[compat]
9-
Documenter = "~0.27"
10-
Krylov = "0.9.8"
9+
Documenter = "1"
10+
Krylov = "0.10.3"
1111
LinearOperators = "2.4.0"
1212
PartitionedStructures = "0.1.4, 0.1.5"
13-
julia = "^1.6.0"
13+
julia = "1.10"

docs/make.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ makedocs(
44
modules = [PartitionedVectors],
55
doctest = true,
66
# linkcheck = true,
7-
strict = true,
87
format = Documenter.HTML(
98
assets = ["assets/style.css"],
109
ansicolor = true,

docs/src/tutorial.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
A `PartitionedVector <: DenseVector <: AbstractVector` wraps a [`PartitionedStructures`](https://github.com/JuliaSmoothOptimizers/PartitionedStructures.jl)`.Elemental_pv`, to make [JuliaSmoothOptimizers](https://github.com/JuliaSmoothOptimizers) modules able to exploit the partially separable structure.
44
For now, `PartitionedVector` is the keystone to define [PartiallySeparableNLPModel](https://github.com/JuliaSmoothOptimizers/PartiallySeparableNLPModels.jl)s, and then to consequently:
55
- replace `Vector` in [JSOSolvers.jl](https://github.com/JuliaSmoothOptimizers/JSOSolvers.jl);
6-
- replace `Vector` in [KrylovSolvers.jl](https://github.com/JuliaSmoothOptimizers/Krylov.jl);
6+
- replace `Vector` in [Krylov.jl](https://github.com/JuliaSmoothOptimizers/Krylov.jl);
77
- make `LinearOperator`s relying only on `PartitionedVector`s viable;
88
- fit the NLPModels interface (ex: `NLPModels.obj(nlp::PartiallySeparableNLPModel, x::PartitionedVector)` see PartiallySeparableNLPModels.jl for more details).
99

@@ -131,10 +131,10 @@ lo = LinearOperators.LinearOperator(epm)
131131
lo * pv
132132
```
133133
Note: `Matrix(lo)` will produce an error, since the default implementation assumes a complete `Vector`-like behaviour.
134-
- dedicated `CGSolver` from Krylov.jl to solve a partitioned linear system (from a partitioned `LinearOperator`).
134+
- dedicated `CgWorkspace` from Krylov.jl to solve a partitioned linear system (from a partitioned `LinearOperator`).
135135
```@example PV
136136
using Krylov # 0.9.0
137-
solver = Krylov.CgSolver(pv)
137+
solver = Krylov.CgWorkspace(pv)
138138
139139
pv_gradient = similar(pv)
140140
(N,) = size(pv)
@@ -143,5 +143,5 @@ for i = 1:N
143143
pv_gradient[i] = rand(nie)
144144
end
145145
146-
Krylov.solve!(solver, lo, -pv_gradient)
147-
```
146+
Krylov.krylov_solve!(solver, lo, -pv_gradient)
147+
```

src/krylov.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import LinearAlgebra: axpy!, axpby!
2-
import Krylov.CgSolver
2+
import Krylov.CgWorkspace
33
import Base.setproperty!
44

55
function axpy!(
@@ -124,30 +124,32 @@ function axpby!(
124124
return y
125125
end
126126

127-
function CgSolver(pv::PartitionedVector{T}) where {T}
127+
function CgWorkspace(pv::PartitionedVector{T}) where {T}
128128
n = length(pv)
129129
Δx = similar(pv; simulate_vector = true)
130130
Δx .= (T)(0) # by setting Δx .= 0, we ensure that at each iterate the initial point `r` is 0.
131131
x = similar(pv; simulate_vector = true)
132132
x .= (T)(0)
133133
r = similar(pv; simulate_vector = true)
134134
r .= (T)(0) # will be reset at each cg! call to 0 because of mul!(r,A,Δx)
135+
npc_dir = similar(pv; simulate_vector = true)
136+
npc_dir .= (T)(0)
135137
p = similar(pv; simulate_vector = true)
136138
p .= (T)(0)
137139
Ap = similar(pv; simulate_vector = false) # result of the partitioned matrix vector product
138140
Ap .= (T)(0)
139141
z = similar(pv; simulate_vector = true)
140142
z .= (T)(0)
141-
stats = Krylov.SimpleStats(0, false, false, T[], T[], T[], 0.0, "unknown")
142-
solver = Krylov.CgSolver{T, T, PartitionedVector{T}}(n, n, Δx, x, r, p, Ap, z, true, stats)
143+
stats = Krylov.SimpleStats(0, false, false, false, 0, T[], T[], T[], 0.0, "unknown")
144+
solver = Krylov.CgWorkspace{T, T, PartitionedVector{T}}(n, n, Δx, x, r, npc_dir, p, Ap, z, true, stats)
143145
return solver
144146
end
145147

146148
# This way, solver.warm_start stays true at all time.
147149
# It prevents the else case where r .= b at the beginning of cg!.
148150
# r is supposed to simulate a vector while b is not supposed to.
149151
function setproperty!(
150-
solver::CgSolver{T, T, PartitionedVector{T}},
152+
solver::CgWorkspace{T, T, PartitionedVector{T}},
151153
sym::Symbol,
152154
val::Bool,
153155
) where {T}

test/krylov.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ end
3737
PS.update!(epm, epv, Float32(2.0) * epv; verbose = false)
3838
lo_epm = LinearOperators.LinearOperator(epm)
3939

40-
solver = Krylov.CgSolver(pv_x)
40+
solver = Krylov.CgWorkspace(pv_x)
4141

4242
pv_gradient = PartitionedVector(element_variables; T = Float32, n)
4343
# pv_gradient .= Float32(10.) .* pv_gradient
@@ -46,20 +46,20 @@ end
4646
pv_gradient[i] = rand(Float32, nie)
4747
end
4848

49-
Krylov.solve!(solver, lo_epm, -pv_gradient)
49+
Krylov.krylov_solve!(solver, lo_epm, -pv_gradient)
5050

51-
x = Vector(solution(solver))
51+
x = Vector(Krylov.solution(solver))
5252
g = Vector(pv_gradient)
5353
A = Matrix(epm)
5454

5555
@test norm(A * x + g) <= 1e-2 * norm(g)
5656

5757
grad = Vector(pv_gradient)
5858
pm_v = LinearOperator_for_Vector(epm)
59-
solver_vector = Krylov.CgSolver(pm_v, grad)
59+
solver_vector = Krylov.CgWorkspace(pm_v, grad)
6060

61-
Krylov.solve!(solver_vector, pm_v, -grad)
62-
x_vector = solution(solver_vector)
61+
Krylov.krylov_solve!(solver_vector, pm_v, -grad)
62+
x_vector = Krylov.solution(solver_vector)
6363
check_nan = mapreduce(isnan, |, x_vector)
6464
!check_nan && @test x_vector x
6565
end

0 commit comments

Comments
 (0)