Skip to content

Commit 754ee71

Browse files
arnavk23Copilottmigot
authored
Add warnings when dimension is modified (#406)
* Fix #354: Add warnings when dimension is modified on NZF1, spmsrtls, and bearing - NZF1: Warn when n is not a multiple of 13 (adjusted to nearest multiple) - spmsrtls: Warn when n is adjusted due to minimum dimension requirement (n >= 100) - bearing: Warn when grid dimensions are adjusted to ensure nx > 0 and ny > 0 These warnings follow the pattern already established in dixmaan* problems. * Update src/ADNLPProblems/bearing.jl Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * n%13 removal * Add @adjust_nvar_warn macro and update all dimension adjustment warnings - Created @adjust_nvar_warn macro in ADNLPProblems module to standardize dimension adjustment warnings across all problems - Updated warning messages to consistently show both original and adjusted values following pattern: 'problem_name: number of variables adjusted from {n_orig} to {n}' - Applied macro to all problems with dimension adjustments: - NZF1 (multiple of 13) - spmsrtls (adjusted formula) - chainwoo (multiple of 4, both :nlp and :nls variants) - woods (multiple of 4) - srosenbr (multiple of 2) - catenary (multiple of 3, minimum 6) - clplatea, clplateb, clplatec (perfect squares) - fminsrf2 (minimum 4, then perfect square) - powellsg (multiple of 4, both :nlp and :nls variants) - watson (clamped between 2 and 31, both :nlp and :nls variants) Addresses issue #354 * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update powellsg :nls variant to use @adjust_nvar_warn macro Ensures consistent warning messages between :nlp and :nls variants, showing both original and adjusted dimension values. * PureJuMP implementations * Update src/PureJuMP/PureJuMP.jl Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add regression tests for dimension-adjustment warnings * unifying macros for defining problems and dimensions, and added warnings for dimension mismatches in the defined problems. * adding copilot suggestions to fix dimension warnings in ADNLPProblems and PureJuMP * Update OptimizationProblems.jl * final changes * Update src/OptimizationProblems.jl Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * addressing review comments * addressing review comments * format * addressing review comments * further macro additions * addressing review comments * missing macro * fixing failing checks * reverting elec.jl to the version before the dimension warnings were added. The changes in this commit are to fix the dimension warnings that were introduced in the previous commit. The changes include changing the bounds on the constraints, building a feasible x0, and changing the number of variables and constraints in the model. The changes are made in both the ADNLPProblems and PureJuMP versions of elec.jl. * passing elec.jl macro * Update elec.jl * PureJuMP changes * Update catenary.jl * Apply suggestions from code review Co-authored-by: Tangi Migot <tangi.migot@gmail.com> * ADNLProblems changes * Update powellsg.jl * updating fminsrf2.jl to remove dimension warnings --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
1 parent 5aaeab7 commit 754ee71

63 files changed

Lines changed: 158 additions & 34 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ADNLPProblems/ADNLPProblems.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module ADNLPProblems
22

33
using Requires
4+
import ..OptimizationProblems: @adjust_nvar_warn
45

56
const default_nvar = 100
67
const data_path = joinpath(@__DIR__, "..", "..", "data")

src/ADNLPProblems/NZF1.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ function NZF1(; use_nls::Bool = false, kwargs...)
66
end
77

88
function NZF1(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
9+
n_org = n
910
nbis = max(2, div(n, 13))
1011
n = 13 * nbis
12+
@adjust_nvar_warn("NZF1", n_org, n)
1113
l = div(n, 13)
1214
function f(x; l = l)
1315
return sum(
@@ -29,8 +31,10 @@ function NZF1(::Val{:nlp}; n::Int = default_nvar, type::Type{T} = Float64, kwarg
2931
end
3032

3133
function NZF1(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
34+
n_org = n
3235
nbis = max(2, div(n, 13))
3336
n = 13 * nbis
37+
@adjust_nvar_warn("NZF1", n_org, n)
3438
l = div(n, 13)
3539
function F!(r, x; l = l)
3640
for i = 1:l

src/ADNLPProblems/bearing.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ function bearing(;
1010
# nx > 0 # grid points in 1st direction
1111
# ny > 0 # grid points in 2nd direction
1212

13+
nx = max(1, nx)
14+
ny = max(1, ny)
15+
@adjust_nvar_warn("bearing", n, (nx + 2) * (ny + 2))
16+
1317
b = 10 # grid is (0,2*pi)x(0,2*b)
1418
e = 1 // 10 # eccentricity
1519

src/ADNLPProblems/broydn7d.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export broydn7d
22

33
function broydn7d(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
4-
mod(n, 2) > 0 && @warn("broydn7d: number of variables adjusted to be even")
4+
n_org = n
55
n2 = max(1, div(n, 2))
66
n = 2 * n2
7+
@adjust_nvar_warn("broydn7d", n_org, n)
78
function f(x; n = length(x), n2 = n2)
89
p = 7 // 3
910
return abs(1 - 2 * x[2] + (3 - x[1] / 2) * x[1])^p +

src/ADNLPProblems/catenary.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ function catenary(
88
FRACT = 0.6,
99
kwargs...,
1010
) where {T}
11-
(n % 3 == 0) || @warn("catenary: number of variables adjusted to be a multiple of 3")
11+
n_org = n
1212
n = 3 * max(1, div(n, 3))
13-
(n < 6) || @warn("catenary: number of variables adjusted to be greater or equal to 6")
1413
n = max(n, 6)
14+
@adjust_nvar_warn("catenary", n_org, n)
1515

1616
## Model Parameters
1717
N = div(n, 3) - 2

src/ADNLPProblems/chain.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export chain
22

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

67
L = 4
78
a = 1

src/ADNLPProblems/chainwoo.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ function chainwoo(; use_nls::Bool = false, kwargs...)
66
end
77

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

2526
function chainwoo(::Val{:nls}; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
26-
(n % 4 == 0) || @warn("chainwoo: number of variables adjusted to be a multiple of 4")
27+
n_org = n
2728
n = 4 * max(1, div(n, 4))
29+
@adjust_nvar_warn("chainwoo", n_org, n)
2830
function F!(r, x; n = length(x))
2931
nb = div(n, 2) - 1
3032
r[1] = 1

src/ADNLPProblems/channel.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export channel
22

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

67
nc = 4
78
nd = 4

src/ADNLPProblems/clnlbeam.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export clnlbeam
22

33
function clnlbeam(args...; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
44
N = div(n - 3, 3)
5+
@adjust_nvar_warn("clnlbeam", n, 3 * N + 3)
56
h = 1 // N
67
alpha = 350
78
function f(y; N = N, h = h, alpha = alpha)

src/ADNLPProblems/clplatea.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ function clplatea(;
66
wght = -0.1,
77
kwargs...,
88
) where {T}
9+
n_org = n
910
p = max(floor(Int, sqrt(n)), 3)
10-
p * p != n && @warn("clplatea: number of variables adjusted from $n to $(p*p)")
1111
n = p * p
12+
@adjust_nvar_warn("clplatea", n_org, n)
1213
hp2 = (1 // 2) * p^2
1314
function f(x; p = p, hp2 = hp2, wght = wght)
1415
return (eltype(x)(wght) * x[p + (p - 1) * p]) +

0 commit comments

Comments
 (0)