Skip to content

Commit c645e11

Browse files
committed
Raise error for hessians as we cant test
1 parent 59a751e commit c645e11

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

ext/DynamicExpressionsOptimExt.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,20 @@ function Optim.optimize(
100100
end
101101
constant_nodes = filter(t -> t.degree == 0 && t.constant, tree)
102102
x0 = T[t.val::T for t in constant_nodes]
103-
base_res = if g! === nothing
104-
@assert h! === nothing
105-
Optim.optimize(wrap_func(f, tree, constant_nodes), x0, args...; kwargs...)
106-
elseif h! === nothing
107-
Optim.optimize(
108-
wrap_func(f, tree, constant_nodes),
109-
wrap_func(g!, tree, constant_nodes),
110-
x0,
111-
args...;
112-
kwargs...,
103+
if !isnothing(h!)
104+
throw(
105+
ArgumentError(
106+
"Optim.optimize does not yet support Hessians on `AbstractExpressionNode`. " *
107+
"Please raise an issue at github.com/SymbolicML/DynamicExpressions.jl.",
108+
),
113109
)
110+
end
111+
base_res = if isnothing(g!)
112+
Optim.optimize(wrap_func(f, tree, constant_nodes), x0, args...; kwargs...)
114113
else
115114
Optim.optimize(
116115
wrap_func(f, tree, constant_nodes),
117116
wrap_func(g!, tree, constant_nodes),
118-
wrap_func(h!, tree, constant_nodes),
119117
x0,
120118
args...;
121119
kwargs...,

test/test_optim.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ end
4646
res = optimize(f, g!, tree, BFGS())
4747
@test did_i_run[]
4848
@test isapprox(get_constants(res.minimizer), get_constants(target_tree); atol=0.01)
49+
50+
@testset "Hessians not implemented" begin
51+
@test_throws ArgumentError optimize(f, g!, t -> t, tree, BFGS())
52+
VERSION >= v"1.9" && @test_throws(
53+
"Optim.optimize does not yet support Hessians on `AbstractExpressionNode`",
54+
optimize(f, g!, t -> t, tree, BFGS())
55+
)
56+
end
4957
end
5058

5159
# Now, try combined

0 commit comments

Comments
 (0)