Skip to content

Commit df34507

Browse files
fix: drop Optim <1; add NLSolversBase compat + Optim v1 CI
1 parent 2dd0acc commit df34507

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

.github/workflows/CI.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ jobs:
9999
path: lcov.info
100100

101101

102+
optim_v1_smoketest:
103+
name: Optim v1 (NLSolversBase v7) - ubuntu-latest
104+
runs-on: ubuntu-latest
105+
timeout-minutes: 60
106+
steps:
107+
- uses: actions/checkout@v4
108+
- uses: julia-actions/setup-julia@v2
109+
with:
110+
version: '1'
111+
- uses: julia-actions/cache@v2
112+
- uses: julia-actions/julia-buildpkg@v1
113+
- name: Pin Optim v1 and run tests
114+
run: |
115+
julia --color=yes -e 'import Pkg; Pkg.activate("test"); Pkg.add(Pkg.PackageSpec(name="Optim", version="1")); Pkg.status(["Optim", "NLSolversBase"])'
116+
julia --color=yes --threads=auto --check-bounds=yes --depwarn=yes -e 'import Pkg; Pkg.activate("."); Pkg.test()'
117+
shell: bash
118+
119+
102120
codecov:
103121
name: Upload combined coverage to Codecov
104122
runs-on: ubuntu-latest

Project.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
1818
Bumper = "8ce10254-0962-460f-a3d8-1f77fea1446e"
1919
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
2020
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
21+
NLSolversBase = "d41bc354-129a-5804-8e4c-c37616107c6c"
2122
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
2223
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2324

2425
[extensions]
2526
DynamicExpressionsBumperExt = "Bumper"
2627
DynamicExpressionsLoopVectorizationExt = "LoopVectorization"
27-
DynamicExpressionsOptimExt = "Optim"
28+
DynamicExpressionsOptimExt = ["Optim", "NLSolversBase"]
2829
DynamicExpressionsSymbolicUtilsExt = "SymbolicUtils"
2930
DynamicExpressionsZygoteExt = "Zygote"
3031

@@ -36,7 +37,8 @@ DispatchDoctor = "0.4"
3637
Interfaces = "0.3"
3738
LoopVectorization = "0.12"
3839
MacroTools = "0.4, 0.5"
39-
Optim = "0.19, 1, 2"
40+
Optim = "1, 2"
41+
NLSolversBase = "7, 8"
4042
PrecompileTools = "1"
4143
Reexport = "1"
4244
SymbolicUtils = "0.19, ^1.0.5, 2, 3"
@@ -49,5 +51,6 @@ TOML = "1"
4951
Bumper = "8ce10254-0962-460f-a3d8-1f77fea1446e"
5052
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
5153
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
54+
NLSolversBase = "d41bc354-129a-5804-8e4c-c37616107c6c"
5255
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
5356
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

ext/DynamicExpressionsOptimExt.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ using DynamicExpressions:
99
set_scalar_constants!,
1010
get_number_type
1111

12-
import Optim: Optim, OptimizationResults, NLSolversBase
12+
import Optim: Optim, OptimizationResults
13+
import NLSolversBase
1314

1415
#! format: off
1516
"""
@@ -90,16 +91,20 @@ function wrap_func(
9091
return nothing
9192
end
9293

94+
# `NLSolversBase.InplaceObjective` is an internal type whose field layout changed
95+
# between NLSolversBase versions.
96+
#
97+
# - NLSolversBase v7 (Optim v1.x): df, fdf, fgh, hv, fghv
98+
# - NLSolversBase v8 (Optim v2.x): fdf, fgh, hvp, fghvp, fjvp
9399
const _INPLACEOBJECTIVE_SPEC_V8 = (
94100
fields=(:fdf, :fgh, :hvp, :fghvp, :fjvp),
95101
x_last=(:fdf, :fgh),
96102
xv_tail=(:hvp, :fghvp, :fjvp),
97103
)
98104
const _INPLACEOBJECTIVE_SPEC_V7 = (
99-
fields=(:df, :fdf, :fgh, :hv, :fghv), x_last=(:df, :fdf, :fgh), xv_tail=(:hv, :fghv)
100-
)
101-
const _INPLACEOBJECTIVE_SPEC_OLD = (
102-
fields=(:fdf, :fgh, :hv, :fghv), x_last=(:fdf, :fgh), xv_tail=(:hv, :fghv)
105+
fields=(:df, :fdf, :fgh, :hv, :fghv),
106+
x_last=(:df, :fdf, :fgh),
107+
xv_tail=(:hv, :fghv),
103108
)
104109

105110
@inline function _wrap_inplaceobjective_field(
@@ -144,15 +149,13 @@ function wrap_func(
144149
elseif fieldnames(NLSolversBase.InplaceObjective) == _INPLACEOBJECTIVE_SPEC_V7.fields
145150
# NLSolversBase v7 / Optim v1
146151
return _wrap_inplaceobjective(f, tree, refs, _INPLACEOBJECTIVE_SPEC_V7)
147-
elseif fieldnames(NLSolversBase.InplaceObjective) == _INPLACEOBJECTIVE_SPEC_OLD.fields
148-
# Older NLSolversBase / Optim
149-
return _wrap_inplaceobjective(f, tree, refs, _INPLACEOBJECTIVE_SPEC_OLD)
152+
# (Optim < 1 is no longer supported.)
150153
else
151154
fields = fieldnames(NLSolversBase.InplaceObjective)
152155
throw(
153156
ArgumentError(
154157
"Unsupported NLSolversBase.InplaceObjective field layout: $(fields). " *
155-
"This extension supports layouts used by Optim v1 and v2. " *
158+
"This extension supports layouts used by NLSolversBase v7 (Optim v1) and v8 (Optim v2). " *
156159
"Please open an issue at github.com/SymbolicML/DynamicExpressions.jl with your versions.",
157160
),
158161
)

0 commit comments

Comments
 (0)