Allow default_counters macro to skip functions#560
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates how NLP model wrappers can forward evaluation-counter accessors by enhancing @default_counters to support excluding selected forwarded counter functions, and adjusts module include order + tests accordingly.
Changes:
- Extend
@default_countersto accept an optional exclusion list to avoid generating forwarding methods for specific counters. - Reorder
include("nlp/*.jl")socountersis loaded beforeutils/api. - Expand test coverage around excluded counter forwarding behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/NLPModels.jl |
Reorders include sequence so counters loads before utils/api. |
src/nlp/utils.jl |
Extends @default_counters with an excluded parameter and updates its docstring. |
test/nlp/utils.jl |
Updates tests to exercise the new excluded argument path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@tmigot @MaxenceGollier The macro push!(
ex.args,
:(
Base.getproperty(nlp::$(esc(Model)), s::Symbol) =
(s == :counters ? nlp.$inner.counters : getfield(nlp, s))
),
)is redundant. In addition, some models do not have a Admittedly, this is fairly old code. |
4abce4b to
3208a49
Compare
Skipping certain functions is useful to avoid overwriting methods.
If, e.g., neval_hprod is forwarded by
@default_counters Model inner
and the user redefines
NLPModels.neval_hprod(m::Model) = ...
then, neval_hprod is being overwritten, and that prevents
precompilation. That is the case in quasi-Newton models.
3208a49 to
31bdca8
Compare
Skipping certain functions is useful to avoid overwriting methods. If, e.g., neval_hprod is forwarded by
and the user redefines
then, neval_hprod is being overwritten, and that prevents precompilation. That is the case in quasi-Newton models.