Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c56d05a
Fix #354: Add warnings when dimension is modified on NZF1, spmsrtls, …
arnavk23 Feb 27, 2026
d23f459
Update src/ADNLPProblems/bearing.jl
arnavk23 Feb 27, 2026
7222fc4
n%13 removal
arnavk23 Feb 27, 2026
039a60c
Add @adjust_nvar_warn macro and update all dimension adjustment warnings
arnavk23 Feb 27, 2026
4d99e6d
Apply suggestions from code review
arnavk23 Feb 27, 2026
a9c3d38
Update powellsg :nls variant to use @adjust_nvar_warn macro
arnavk23 Feb 27, 2026
0b01780
PureJuMP implementations
arnavk23 Apr 7, 2026
106ad0b
Update src/PureJuMP/PureJuMP.jl
arnavk23 Apr 18, 2026
f6c9e0a
Add regression tests for dimension-adjustment warnings
arnavk23 Apr 18, 2026
4af9763
unifying macros for defining problems and dimensions, and added warni…
arnavk23 Apr 18, 2026
b59e1ba
adding copilot suggestions to fix dimension warnings in ADNLPProblems…
arnavk23 Apr 18, 2026
be0c0e1
Update OptimizationProblems.jl
arnavk23 Apr 18, 2026
b5a7f23
final changes
arnavk23 Apr 18, 2026
39ea750
Merge branch 'fix/issue-354-dimension-warnings' of https://www.github…
arnavk23 Apr 18, 2026
95b8843
Update src/OptimizationProblems.jl
arnavk23 Apr 18, 2026
120031d
addressing review comments
arnavk23 Apr 21, 2026
270308f
addressing review comments
arnavk23 Apr 25, 2026
abd2a67
format
arnavk23 Apr 25, 2026
1828bf5
addressing review comments
arnavk23 Apr 30, 2026
25b360a
further macro additions
arnavk23 May 4, 2026
1858c62
addressing review comments
arnavk23 May 4, 2026
528a616
missing macro
arnavk23 May 4, 2026
f60efc2
fixing failing checks
arnavk23 May 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ADNLPProblems/ADNLPProblems.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ADNLPProblems

using Requires
import ..OptimizationProblems: @adjust_nvar_warn

const default_nvar = 100
const data_path = joinpath(@__DIR__, "..", "..", "data")
Expand Down
4 changes: 4 additions & 0 deletions src/ADNLPProblems/NZF1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ function NZF1(; use_nls::Bool = false, kwargs...)
end

function NZF1(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
nbis = max(2, div(n, 13))
n = 13 * nbis
@adjust_nvar_warn("NZF1", n_orig, n)
Comment thread
arnavk23 marked this conversation as resolved.
l = div(n, 13)
function f(x; l = l)
return sum(
Expand All @@ -29,8 +31,10 @@ function NZF1(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwarg
end

function NZF1(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
nbis = max(2, div(n, 13))
n = 13 * nbis
@adjust_nvar_warn("NZF1", n_orig, n)
l = div(n, 13)
function F!(r, x; l = l)
for i = 1:l
Expand Down
6 changes: 6 additions & 0 deletions src/ADNLPProblems/bearing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ function bearing(;
# nx > 0 # grid points in 1st direction
# ny > 0 # grid points in 2nd direction

n_orig = n
nx = max(1, nx)
ny = max(1, ny)
n = (nx + 2) * (ny + 2)
@adjust_nvar_warn("bearing", n_orig, n)
Comment thread
arnavk23 marked this conversation as resolved.

b = 10 # grid is (0,2*pi)x(0,2*b)
e = 1 // 10 # eccentricity

Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/broydn7d.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export broydn7d

function broydn7d(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
mod(n, 2) > 0 && @warn("broydn7d: number of variables adjusted to be even")
n_orig = n
n2 = max(1, div(n, 2))
n = 2 * n2
@adjust_nvar_warn("broydn7d", n_orig, n)
function f(x; n = length(x), n2 = n2)
p = 7 // 3
return abs(1 - 2 * x[2] + (3 - x[1] / 2) * x[1])^p +
Expand Down
4 changes: 2 additions & 2 deletions src/ADNLPProblems/catenary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ function catenary(
FRACT = 0.6,
kwargs...,
) where {T}
(n % 3 == 0) || @warn("catenary: number of variables adjusted to be a multiple of 3")
n_orig = n
n = 3 * max(1, div(n, 3))
(n < 6) || @warn("catenary: number of variables adjusted to be greater or equal to 6")
n = max(n, 6)
@adjust_nvar_warn("catenary", n_orig, n)

## Model Parameters
N = div(n, 3) - 2
Expand Down
3 changes: 3 additions & 0 deletions src/ADNLPProblems/chain.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export chain

function chain(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
nh = max(2, div(n - 4, 4))
n = 4 * nh + 4
@adjust_nvar_warn("chain", n_orig, n)

L = 4
a = 1
Expand Down
6 changes: 4 additions & 2 deletions src/ADNLPProblems/chainwoo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ function chainwoo(; use_nls::Bool = false, kwargs...)
end

function chainwoo(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("chainwoo: number of variables adjusted to be a multiple of 4")
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("chainwoo", n_orig, n)
function f(x; n = length(x))
return 1 + sum(
100 * (x[2 * i] - x[2 * i - 1]^2)^2 +
Expand All @@ -23,8 +24,9 @@ function chainwoo(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, k
end

function chainwoo(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("chainwoo: number of variables adjusted to be a multiple of 4")
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("chainwoo", n_orig, n)
function F!(r, x; n = length(x))
nb = div(n, 2) - 1
r[1] = 1
Expand Down
3 changes: 3 additions & 0 deletions src/ADNLPProblems/channel.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export channel

function channel(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
nh = max(2, div(n, 8))
n = 8 * nh
@adjust_nvar_warn("channel", n_orig, n)

nc = 4
nd = 4
Expand Down
3 changes: 3 additions & 0 deletions src/ADNLPProblems/clnlbeam.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export clnlbeam

function clnlbeam(args...; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
N = div(n - 3, 3)
n = 3 * N + 3
@adjust_nvar_warn("clnlbeam", n_orig, n)
h = 1 // N
alpha = 350
function f(y; N = N, h = h, alpha = alpha)
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/clplatea.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ function clplatea(;
wght = -0.1,
kwargs...,
) where {T}
n_orig = n
p = max(floor(Int, sqrt(n)), 3)
p * p != n && @warn("clplatea: number of variables adjusted from $n to $(p*p)")
n = p * p
@adjust_nvar_warn("clplatea", n_orig, n)
hp2 = (1 // 2) * p^2
function f(x; p = p, hp2 = hp2, wght = wght)
return (eltype(x)(wght) * x[p + (p - 1) * p]) +
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/clplateb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ function clplateb(;
wght = -0.1,
kwargs...,
) where {T}
n_orig = n
p = max(floor(Int, sqrt(n)), 3)
p * p != n && @warn("clplateb: number of variables adjusted from $n to $(p*p)")
n = p * p
@adjust_nvar_warn("clplateb", n_orig, n)
hp2 = 1 // 2 * p^2
function f(x; p = p, hp2 = hp2, wght = wght)
return sum(eltype(x)(wght) / (p - 1) * x[p + (j - 1) * p] for j = 1:p) +
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/clplatec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ function clplatec(;
l = 0.01,
kwargs...,
) where {T}
n_orig = n
p = max(floor(Int, sqrt(n)), 3)
p * p != n && @warn("clplatec: number of variables adjusted from $n to $(p*p)")
n = p * p
@adjust_nvar_warn("clplatec", n_orig, n)

hp2 = 1 // 2 * p^2
function f(x; p = p, hp2 = hp2, wght = wght, r = r, l = l)
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/dixmaan_efgh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ function dixmaane(;
δ = 125 // 1000,
kwargs...,
) where {T}
(n % 3 == 0) || @warn("dixmaan: number of variables adjusted to be a multiple of 3")
n_orig = n
m = max(1, div(n, 3))
n = 3 * m
@adjust_nvar_warn("dixmaane", n_orig, n)
function f(x; n = length(x), α = α, β = β, γ = γ, δ = δ)
return 1 +
sum(i // n * α * x[i]^2 for i = 1:n) +
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/dixmaan_ijkl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ function dixmaani(;
δ = 125 // 1000,
kwargs...,
) where {T}
(n % 3 == 0) || @warn("dixmaan: number of variables adjusted to be a multiple of 3")
n_orig = n
m = max(1, div(n, 3))
n = 3 * m
@adjust_nvar_warn("dixmaani", n_orig, n)
function f(x; n = length(x), α = α, β = β, γ = γ, δ = δ)
return 1 +
sum((i // n)^2 * α * x[i]^2 for i = 1:n) +
Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/dixmaan_mnop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ function dixmaanm(;
δ = 125 // 1000,
kwargs...,
) where {T}
(n % 3 == 0) || @warn("dixmaan: number of variables adjusted to be a multiple of 3")
n_orig = n
m = max(1, div(n, 3))
n = 3 * m
@adjust_nvar_warn("dixmaanm", n_orig, n)
function f(x; n = length(x), α = α, β = β, γ = γ, δ = δ)
return 1 +
sum((i // n)^2 * α * x[i]^2 for i = 1:n) +
Expand Down
25 changes: 14 additions & 11 deletions src/ADNLPProblems/elec.jl
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
export elec

function elec(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n = max(2, div(n, 3))
n_orig = n
m = max(2, div(n_orig, 3))
n = 3 * m
@adjust_nvar_warn("elec", n_orig, n)
# Define the objective function to minimize
function f(x; n = n)
return sum(
sum(
1 / sqrt((x[j] - x[i])^2 + (x[n + j] - x[n + i])^2 + (x[2n + j] - x[2n + i])^2) for
j = (i + 1):n
) for i = 1:(n - 1)
1 / sqrt((x[j] - x[i])^2 + (x[m + j] - x[m + i])^2 + (x[2m + j] - x[2m + i])^2) for
j = (i + 1):m
) for i = 1:(m - 1)
)
end

# Define the constraints on these points (sum of the square of the coordinates = 1)
function c!(cx, x; n = n)
for k = 1:n
cx[k] = x[k]^2 + x[n + k]^2 + x[2n + k]^2
for k = 1:m
cx[k] = x[k]^2 + x[m + k]^2 + x[2m + k]^2
end
return cx
end

# bounds on the constraints
lcon = ucon = ones(T, n)
lcon = ucon = ones(T, m)

# building a feasible x0
range0 = T[i / n for i = 1:n]
range0 = T[i / m for i = 1:m]

θ0 = 2π .* range0
ϕ0 = π .* range0
xini = T[sin(θ0[i]) * cos(ϕ0[i]) for i = 1:n] # x coordinate
yini = T[sin(θ0[i]) * sin(ϕ0[i]) for i = 1:n] # y coordinate
zini = T[cos(θ0[i]) for i = 1:n] # z coordinate
xini = T[sin(θ0[i]) * cos(ϕ0[i]) for i = 1:m] # x coordinate
yini = T[sin(θ0[i]) * sin(ϕ0[i]) for i = 1:m] # y coordinate
zini = T[cos(θ0[i]) for i = 1:m] # z coordinate
x0 = [xini; yini; zini]

return ADNLPModels.ADNLPModel!(f, x0, c!, lcon, ucon, name = "elec"; kwargs...)
Expand Down
5 changes: 2 additions & 3 deletions src/ADNLPProblems/fminsrf2.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export fminsrf2

function fminsrf2(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n < 4 && @warn("fminsrf2: number of variables must be ≥ 4")
n_orig = n
n = max(4, n)

p = floor(Int, sqrt(n))
p * p != n && @warn("fminsrf2: number of variables adjusted from $n down to $(p*p)")
n = p * p
@adjust_nvar_warn("fminsrf2", n_orig, n)

h00 = 1
slopej = 4
Expand Down
10 changes: 8 additions & 2 deletions src/ADNLPProblems/hovercraft1d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ function hovercraft1d(
type::Type{T} = Float64,
kwargs...,
) where {T}
N = div(n, 3)
n_orig = n
N = div(n_orig, 3)
n = 3 * N - 1
@adjust_nvar_warn("hovercraft1d", n_orig, n)
function f(y; N = N)
@views x, v, u = y[1:N], y[(N + 1):(2 * N)], y[(2 * N + 1):end]
return 1 // 2 * sum(u .^ 2)
Expand Down Expand Up @@ -72,7 +75,10 @@ function hovercraft1d(
type::Type{T} = Float64,
kwargs...,
) where {T}
N = div(n, 3)
n_orig = n
N = div(n_orig, 3)
n = 3 * N - 1
@adjust_nvar_warn("hovercraft1d", n_orig, n)
function F!(r, y; N = N)
@views x, v, u = y[1:N], y[(N + 1):(2 * N)], y[(2 * N + 1):end]
r .= u
Expand Down
3 changes: 3 additions & 0 deletions src/ADNLPProblems/marine.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
export marine

function marine(; n::Int = default_nvar, nc::Int = 1, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
nc = max(min(nc, 4), 1) # number of collocation points
ne = 8 # number of differential equations
nm = 21 # number of measurements

n = max(n, 3 * ne * nc + ne + 2 * ne)
nh = Int(round((n - 2 * ne + 1) / (3 * ne * nc + ne))) # number of partition intervals
n = 8 + 7 + nh * (8 + 3 * 8 * nc)
@adjust_nvar_warn("marine", n_orig, n)

# roots of k-th degree Legendre polynomial
rho = if nc == 1
Expand Down
8 changes: 5 additions & 3 deletions src/ADNLPProblems/powellsg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ function powellsg(; use_nls::Bool = false, kwargs...)
end

function powellsg(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("powellsg: number of variables adjusted to be a multiple of 4")
n = 4 * max(1, div(n, 4)) # number of variables adjusted to be a multiple of 4
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("powellsg", n_orig, n)
Comment thread
arnavk23 marked this conversation as resolved.
function f(x; n = length(x))
return sum(
(x[j] + 10 * x[j + 1])^2 +
Expand All @@ -24,8 +25,9 @@ function powellsg(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, k
end

function powellsg(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 4 == 0) || @warn("powellsg: number of variables adjusted to be a multiple of 4")
n_orig = n
n = 4 * max(1, div(n, 4))
@adjust_nvar_warn("powellsg", n_orig, n)
function F!(r, x; n = length(x))
@inbounds for j = 1:4:n
r[j] = x[j] + 10 * x[j + 1]
Expand Down
5 changes: 4 additions & 1 deletion src/ADNLPProblems/robotarm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ export robotarm
# classification OOR2-AN-V-V

function robotarm(; n::Int = default_nvar, L = 4.5, type::Type{T} = Float64, kwargs...) where {T}
N = max(2, div(n, 9))
n_orig = n
N = max(2, div(n_orig, 9))
n = N + 1
nvars = 9 * n + 1
@adjust_nvar_warn("robotarm", n_orig, nvars)
L = T(L)

# x : vector of variables, of the form : [ρ(t=t1); ρ(t=t2); ... ρ(t=tf), θ(t=t1), ..., then ρ_dot, ..., then ρ_acc, .. ϕ_acc, tf]
Expand Down
4 changes: 4 additions & 0 deletions src/ADNLPProblems/spmsrtls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ function spmsrtls(; use_nls::Bool = false, kwargs...)
end

function spmsrtls(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
m = max(Int(round((n + 2) / 3)), 34)
n = m * 3 - 2
@adjust_nvar_warn("spmsrtls", n_orig, n)
p = [sin(i^2) for i = 1:n]
x0 = T[p[i] / 5 for i = 1:n]

Expand Down Expand Up @@ -59,8 +61,10 @@ function spmsrtls(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, k
end

function spmsrtls(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n_orig = n
m = max(Int(round((n + 2) / 3)), 34)
n = m * 3 - 2
@adjust_nvar_warn("spmsrtls", n_orig, n)
Comment thread
arnavk23 marked this conversation as resolved.
p = [sin(i^2) for i = 1:n]
x0 = T[p[i] / 5 for i = 1:n]

Expand Down
3 changes: 2 additions & 1 deletion src/ADNLPProblems/srosenbr.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export srosenbr

function srosenbr(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
(n % 2 == 0) || @warn("srosenbr: number of variables adjusted to be even")
n_orig = n
n = 2 * max(1, div(n, 2))
@adjust_nvar_warn("srosenbr", n_orig, n)
function f(x; n = length(x))
return sum(100 * (x[2 * i] - x[2 * i - 1]^2)^2 + (x[2 * i - 1] - 1)^2 for i = 1:div(n, 2))
end
Expand Down
6 changes: 5 additions & 1 deletion src/ADNLPProblems/structural.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export structural

function structural(args...; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
n = max(n, 100)
n_orig = n
n = max(n_orig, 100)

sub2ind(shape, a, b) = LinearIndices(shape)[CartesianIndex.(a, b)]
Nx = min(Int(round(n^(1 / 3))), 6)
Expand All @@ -23,6 +24,9 @@ function structural(args...; n::Int = default_nvar, type::Type{T} = Float64, kwa

M = Int(N * (N - 1) / 2) # number of edges

nvars = 2 * M
@adjust_nvar_warn("structural", n_orig, nvars)

# EDGES: columns are the indices of the nodes at either end
edges = Array{Int}(zeros(M, 2))

Expand Down
Loading
Loading