You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Documentation for adding new problems in contributing.md (#410)
* Improve contributing.md: clarify requirements for adding new problems, including constraints, compatibility, meta fields, allocation, and scalability
* Clarify meta field completeness and validation requirements in meta.md, as suggested by validation analysis PDF
* Add note to benchmark.md about compatibility and meta field validation requirements for benchmarking, as suggested by validation analysis PDF
* Update meta.md for improved clarity on meta fields
Clarified requirements for meta field completeness and validation.
* Apply suggestions from code review
Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
* addressing review comments
* Update contributing.md
* Fix punctuation and formatting in contributing.md
Corrected punctuation and formatting in the contributing guidelines.
* Apply suggestions from code review
Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
* Enhance contributing.md with NLS problem guidelines
Added guidelines for handling Nonlinear Least Squares (NLS) problems in contributing documentation.
* Apply suggestions from code review
Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* addressing review comments
* Apply suggestions from code review
Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
* addressing review comments
* Apply suggestions from code review
Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
* Update contributing.md
* Apply suggestions from code review
Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
---------
Co-authored-by: Tangi Migot <tangi.migot@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/src/contributing.md
+80-3Lines changed: 80 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,10 @@ Here is a to-do list, to help you add new problems:
20
20
-`src/PureJuMP/problem_name.jl`
21
21
-`src/Meta/problem_name.jl`
22
22
In both cases, the function must have the same name `problem_name` as the file.
23
+
The function should be only exported from `src/ADNLPProblems/problem_name.jl` and `src/PureJuMP/problem_name.jl`.
23
24
* When submitting a problem, please pay particular attention to the documentation. We would like to gather as much information as possible on the provenance of problems, other problem sets where the problems are present, and general information on the problem.
24
25
The documentation should be added to the file in the `PureJuMP` folder.
25
-
* New problems can be scalable, see [ADNLPProblems/arglina.jl](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/arglina.jl) and [PureJuMP/arglina.jl](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/PureJuMP/arglina.jl) for examples. In that case, the first keyword parameter should be the number of variables `n::Int` and have the default value `default_nvar` (constant predefined in the module). If your problem has restrictions on the number of variables, e.g., `n` should be odd, or `n` should have the form `4k + 3`, then, instead of throwing errors when the restrictions are not satisfied, you should instead use the number of variables to be as close to `n` as possible. For example, if you want `n` odd and `n = 100` is passed, you can internally convert to `n = 99`. If you want `n = 4k + 3`, and `n = 100` is passed, then compute `k = round(Int, (n - 3) / 4)` and update `n`.
26
+
* New problems can be scalable, see [ADNLPProblems/arglina.jl](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/arglina.jl) and [PureJuMP/arglina.jl](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/PureJuMP/arglina.jl) for examples. In that case, the first keyword parameter should be the number of variables `n::Int` and have the default value `default_nvar` (constant predefined in the module). If your problem has restrictions on the number of variables, e.g., `n` should be odd, or `n` should have the form `4k + 3`, then, instead of throwing errors when the restrictions are not satisfied, you should instead use the number of variables to be as close to `n` as possible. For example, if you want `n` odd and `n = 100` is passed, you can internally convert to `n = 99`. If you want `n = 4k + 3`, and `n = 100` is passed, then compute `k = round(Int, (n - 3) / 4)` and update `n`. When such an internal adjustment is made, emit a warning indicating the requested `n` and the effective value used.
26
27
* A first version of the `meta` can be generated using `generate_meta`. A `String` is returned that can be copy-pasted into the `Meta` folder, and then edited.
27
28
28
29
```julia
@@ -34,6 +35,7 @@ The documentation should be added to the file in the `PureJuMP` folder.
34
35
```
35
36
36
37
* Problems modeled with `ADNLPModels` should be type-stable, i.e. they should all have keyword argument `type::Type{T} = Float64` where `T` is the type of the initial guess and the type used by the `NLPModel` API.
38
+
* The `name` keyword should be passed to `ADNLPModel`/`ADNLSModel` with a meaningful problem name.
37
39
38
40
## Templates for the new functions
39
41
@@ -66,9 +68,84 @@ Next, we describe the `ADNLPProblems` file `function_name.jl`.
66
68
export function_name
67
69
68
70
function function_name(; n::Int = default_nvar, type::Type{T} = Float64, kwargs...) where {T}
69
-
# define f
70
-
# define x0
71
+
# define f (ensure f(x0) is of type T)
72
+
# define x0 (ensure x0 isa Vector{T})
71
73
# nlp = ADNLPModels.ADNLPModel(f, x0, name = "function_name"; kwargs...)
72
74
return nlp
73
75
end
74
76
```
77
+
78
+
## Validating new problems
79
+
80
+
* Ensure all meta fields are accurate and complete, e.g. `:origin`, `:objtype`, and `:name` in [`src/Meta/arglina.jl`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/Meta/arglina.jl).
81
+
* Implementations in `ADNLPProblems` and `PureJuMP` must use the same initial point, variable bounds, and constraint bounds; compare `arglina` in [`src/ADNLPProblems/arglina.jl`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/arglina.jl) and [`src/PureJuMP/arglina.jl`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/PureJuMP/arglina.jl).
82
+
* The implemented objective function must be callable at the starting point.
83
+
* For `ADNLPModels` problems, the objective should return values of type `T` from `type::Type{T}` and the initial point should be typed consistently (`x0::Vector{T}`).
84
+
* Pass a meaningful `name` keyword to `ADNLPModel` constructors, for example `name = "arglina"` in [`src/ADNLPProblems/arglina.jl`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/arglina.jl).
85
+
* For constrained problems, ensure in-place constraint evaluations (e.g., `cons_nln!`) are allocation-free, for example the checks in [`test/test-utils.jl`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/test/test-utils.jl).
86
+
* Objective function evaluations should have minimal allocations.
87
+
* For variable-size problems, validate at multiple sizes (for example `n = 5`, `n = default_nvar`, and a larger `n`) and check all of the following, e.g. [`arglina`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/arglina.jl) and [`test/test-scalable.jl`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/test/test-scalable.jl):
88
+
- model instantiation succeeds for each tested `n`;
89
+
- effective `nvar` matches the intended rule (including any internal adjustment such as odd `n` or `4k + 3` constraints);
90
+
- if `n` is internally adjusted, the effective value is the closest feasible one to the requested `n`, and a warning is emitted;
91
+
- metadata formulas (`nvar`, `nnzh`, `nnzj`, etc.) match the instantiated model values.
92
+
* Optional (recommended): provide in the PR a local solver sanity check showing that a standard solver can solve the model from the provided starting point, see example below.
93
+
94
+
```julia
95
+
using OptimizationProblems, OptimizationProblems.ADNLPProblems
96
+
using NLPModelsIpopt
97
+
98
+
nlp =problem_name()
99
+
stats =ipopt(nlp)
100
+
stats.status
101
+
```
102
+
### Nonlinear Least Squares (NLS) Problems
103
+
104
+
If your problem is a nonlinear least squares (NLS), please follow these guidelines:
105
+
* Set the `:objtype` entry in the meta file to `:least_squares`.
106
+
* Add a getter for the number of NLS equations, named `get_problemname_nls_nequ`.
107
+
* Support the `use_nls=true/false` keyword to allow both `ADNLPModel` and `ADNLSModel` instantiation from the same problem.
108
+
* Instantiate both `ADNLPModel` and `ADNLSModel`, ensure `residual!(nls, x, Fx)` is allocation-free, and check that objectives agree (or differ by a factor of 2 for LS).
109
+
* In the `PureJuMP` file, clearly document that the problem is a nonlinear least squares (NLS) problem and explain how users can construct both the standard and NLS variants.
110
+
* Explicitly state that the NLS variant can be accessed by passing the keyword argument `use_nls=true` when constructing the problem.
111
+
* Make sure this information is also reflected in the meta file, so users and tools can easily discover the NLS capability.
112
+
* In validation, also run the local solver sanity check with `problem_name(use_nls=true)`.
113
+
See existing NLS problems (e.g., [`lanczos1`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/lanczos1.jl), [`lanczos2`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/lanczos2.jl), [`brownal`](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/brownal.jl)) for templates.
114
+
115
+
## Reviewer Checklist for New Problems
116
+
117
+
-[ ] First check: the problem is added in exactly these three files with the same base name: `src/ADNLPProblems/problem_name.jl`, `src/PureJuMP/problem_name.jl`, and `src/Meta/problem_name.jl`.
118
+
Example: [`arglina` in ADNLPProblems](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/ADNLPProblems/arglina.jl), [`arglina` in PureJuMP](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/PureJuMP/arglina.jl), and [`arglina` in Meta](https://github.com/JuliaSmoothOptimizers/OptimizationProblems.jl/blob/main/src/Meta/arglina.jl).
119
+
120
+
**Meta**
121
+
-[ ] The corresponding meta file exists (`src/Meta/problem_name.jl`), the problem name matches the AD and JuMP files, and `OptimizationProblems.meta` contains the problem entry.
122
+
-[ ] All meta fields (origin, objtype, contype, bounds, best-known, etc.) are filled correctly.
123
+
-[ ] The problem origin/provenance is clearly documented and consistent between the `PureJuMP` problem documentation and the `:origin` meta entry.
124
+
-[ ] Meta formulas for variable sizes match actual model behavior.
125
+
126
+
**Definition**
127
+
-[ ] No extra or spurious exports are introduced.
128
+
-[ ] The problem function is exported in `src/ADNLPProblems/problem_name.jl` and `src/PureJuMP/problem_name.jl`, and not exported in `src/Meta/problem_name.jl`.
129
+
-[ ] Model name matches the file and function name.
130
+
-[ ] The implemented objective, constraints, and bounds match the mathematical problem definition from the cited reference/documentation.
131
+
132
+
**Implementation**
133
+
-[ ] Objective and constraint values agree (ADNLPProblems vs PureJuMP) within tolerance at test points.
134
+
-[ ] Number of variables and constraints match.
135
+
-[ ] For `type::Type{T}`, `x0 isa Vector{T}` and objective values are of type `T`.
136
+
-[ ]`ADNLPModel`/`ADNLSModel` constructors receive a meaningful `name` keyword.
137
+
138
+
**Sanity**
139
+
-[ ] Objective is callable at the starting point and does not return NaN (unless documented).
140
+
-[ ] Model instantiates without error for different types, e.g. Float32 and Float64.
141
+
-[ ] For scalable problems, changing `n` updates `nvar` and all related meta fields, and the effective number of variables remains as close as possible to the requested `n` when internal adjustments are required.
142
+
143
+
**Zero-Allocation**
144
+
-[ ] All in-place APIs (constraints, residuals) are allocation-free.
145
+
-[ ] No unnecessary allocations in tight loops or callbacks.
146
+
-[ ] Objective evaluation has minimal allocations (ideally allocation-free in performance-critical paths).
147
+
148
+
**Least-Squares & In-Place APIs**
149
+
-[ ] If least squares, ADNLP constructor supports `nls=true/false` for both ADNLPModel and ADNLSModel.
150
+
-[ ] In-place nonlinear constraint evaluations (`cons_nln!(nlp, x, cx)`) and least squares residuals (`residual!`) are allocation-free.
151
+
-[ ] For least squares problems, objectives for NLP and NLS must agree (or differ by a factor of 2, as appropriate).
0 commit comments