Skip to content

Commit bd68b9d

Browse files
committed
Put trimmable code into package
See TrimTest.jl comment for rationale.
1 parent 8c45ab3 commit bd68b9d

File tree

5 files changed

+29
-17
lines changed

5 files changed

+29
-17
lines changed

test/trim/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
name = "TrimTest"
2+
uuid = "7e54ada7-ece5-4046-aa01-512d530850d8"
3+
14
[deps]
25
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
36
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"

test/trim/clean_optimization.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ using LinearAlgebra
55
using StaticArrays
66
using LinearSolve
77
const LS = LinearSolve
8-
using SciMLBase: successful_retcode
9-
using JET
108

119
function f(u, p)
1210
L, U = cholesky(p.Σ)
@@ -32,6 +30,3 @@ function minimize(x)
3230
sol = solve(prob, alg)
3331
return sol
3432
end
35-
36-
@test successful_retcode(minimize(1.0).retcode)
37-
@test_opt minimize(1.0)

test/trim/main.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
using TrimTest
22

33
function (@main)(argv::Vector{String})::Cint
4-
λ = try
5-
parse(Float64, argv[2])
6-
catch
7-
parse(Float64, argv[1])
8-
end
4+
λ = parse(Float64, argv[2])
95
sol = TrimTest.minimize(λ)
106
println(Core.stdout, sum(sol.u))
117
return 0

test/trim/src/TrimTest.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
module TrimTest
2+
#=
3+
Currently, trimming only works if the target code is in a package. I.e., trying to trim
4+
```julia
5+
include("trimmable_optimization.jl")
6+
function (@main)(argv::Vector{String})::Cint
7+
minimize(1.0)
8+
return 0
9+
end
10+
```
11+
or even
12+
```julia
13+
mod MyMod
14+
include("trimmable_optimization.jl")
15+
end
16+
function (@main)(argv::Vector{String})::Cint
17+
MyMod.minimize(1.0)
18+
return 0
19+
end
20+
```
21+
segfaults `juliac`. Looking at the segfault stacktrace it seems the culprit is
22+
`const cache = init(...)`. Either way, we circumvent the segfault by putting
23+
this below code into a package definition.
24+
=#
225
include("../trimmable_optimization.jl")
326
end

test/trim/trimmable_optimization.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using NonlinearSolveFirstOrder
2-
using ADTypes: AutoForwardDiff
32
using DiffEqBase
3+
using ADTypes: AutoForwardDiff
44
using ForwardDiff
55
using LinearAlgebra
66
using StaticArrays
77
using LinearSolve
8+
import SciMLBase
89
const LS = LinearSolve
9-
using SciMLBase: successful_retcode
10-
using JET
1110

1211
function f(u, p)
1312
L, U = cholesky(p.Σ)
@@ -24,7 +23,6 @@ struct MyParams{T, M}
2423
λ::T
2524
Σ::M
2625
end
27-
DiffEqBase.anyeltypedual(::MyParams) = Any
2826

2927
const autodiff = AutoForwardDiff(; chunksize = 1)
3028
const alg = TrustRegion(; autodiff, linsolve = LS.CholeskyFactorization())
@@ -37,6 +35,3 @@ function minimize(x)
3735
solve!(cache)
3836
return cache
3937
end
40-
41-
@test successful_retcode(minimize(1.0).retcode)
42-
@test_opt minimize(1.0)

0 commit comments

Comments
 (0)