Skip to content

Commit 116af08

Browse files
RomeoVChrisRackauckas
authored andcommitted
Add OncePerProcess versions
still segfault... [skip ci]
1 parent 7209a12 commit 116af08

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

test/trim/main_once_per_process.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module MyModule
2+
include("./optimization_once_per_process.jl")
3+
end
4+
5+
function (@main)(argv::Vector{String})::Cint
6+
λ = parse(Float64, argv[1])
7+
sol = MyModule.TestModuleTrimmable.minimize(λ)
8+
println(Core.stdout, sum(sol.u))
9+
return 0
10+
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
module TestModuleTrimmable
2+
using NonlinearSolveFirstOrder
3+
using DiffEqBase
4+
using ADTypes: AutoForwardDiff
5+
using ForwardDiff
6+
using LinearAlgebra
7+
using StaticArrays
8+
using LinearSolve
9+
import SciMLBase
10+
const LS = LinearSolve
11+
12+
function f(u, p)
13+
L, U = cholesky(p.Σ)
14+
rhs = (u .* u .- p.λ)
15+
# there are some issues currently with LinearSolve and triangular matrices,
16+
# so we just make `L` dense here.
17+
linprob = LinearProblem(Matrix(L), rhs)
18+
alg = LS.GenericLUFactorization()
19+
sol = LinearSolve.solve(linprob, alg)
20+
return sol.u
21+
end
22+
23+
struct MyParams{T, M}
24+
λ::T
25+
Σ::M
26+
end
27+
28+
const cache = OncePerProcess() do
29+
autodiff = AutoForwardDiff(; chunksize = 1)
30+
alg = TrustRegion(; autodiff, linsolve = LS.CholeskyFactorization())
31+
prob = NonlinearLeastSquaresProblem{false}(
32+
f,
33+
rand(2),
34+
MyParams(rand(), hermitianpart(rand(2, 2) + 2I))
35+
)
36+
init(prob, alg)
37+
end
38+
39+
function minimize(x)
40+
ps = MyParams(x, hermitianpart(rand(2, 2) + 2I))
41+
reinit!(cache(), rand(2); p = ps)
42+
solve!(cache())
43+
return cache
44+
end
45+
end

0 commit comments

Comments
 (0)