Skip to content

add ScaledModel - #123

Open
frapac wants to merge 7 commits into
JuliaSmoothOptimizers:mainfrom
frapac:fp/scaler
Open

frapac wants to merge 7 commits into
JuliaSmoothOptimizers:mainfrom
frapac:fp/scaler

Conversation

@frapac

@frapac frapac commented Jul 25, 2024

Copy link
Copy Markdown

Following a suggestion by @dpo

@codecov

codecov Bot commented Jul 25, 2024 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.04762% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.87%. Comparing base (b28197a) to head (fadaf72).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
src/scaled-model.jl 69.04% 52 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #123      +/-   ##
==========================================
- Coverage   97.29%   92.87%   -4.42%     
==========================================
  Files           6        7       +1     
  Lines         886     1067     +181     
==========================================
+ Hits          862      991     +129     
- Misses         24       76      +52     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor
Package name latest stable
ADNLPModels.jl
AmplNLReader.jl
CUTEst.jl
CaNNOLeS.jl
DCI.jl
FletcherPenaltySolver.jl
JSOSolvers.jl
LLSModels.jl
NLPModelsIpopt.jl
NLPModelsJuMP.jl
NLPModelsTest.jl
Percival.jl
QuadraticModels.jl
SolverBenchmark.jl
SolverTools.jl

@tmigot tmigot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @frapac for the PR! Here is a first pass of comments. Sorry if I ask for a lot of clarification.
By the way, would you have a more general use case that would serve as a basis for a tutorial?

Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl
Comment thread src/scaled-model.jl Outdated
the gradient and the Jacobian evaluated at the initial point ``x0``.

"""
struct ScaledModel{T, S, M} <: NLPModels.AbstractNLPModel{T, S}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and same comment throughout the file

@frapac

frapac commented Jul 22, 2026

Copy link
Copy Markdown
Author

The linear and nonlinear API for the constraints have been implemented.

@dpo dpo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I think we can use this in multiple places. I just have a few comments to make the code more explicit.

Comment thread test/nlp/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl
Comment thread src/scaled-model.jl Outdated
end
end

function _set_jacobian_scaling!(Jx, Ji, Jj, cons)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name cons suggests "constraint" (values). But that's not what it is, is it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the name scaling is more appropriate

Comment thread src/scaled-model.jl
Comment thread src/scaled-model.jl
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
Co-authored-by: Maxence Gollier <134112149+MaxenceGollier@users.noreply.github.com>
@dpo

dpo commented Aug 11, 2026

Copy link
Copy Markdown
Member

@MaxenceGollier Does this work for you now?

@MaxenceGollier

Copy link
Copy Markdown
Contributor

@dpo yes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate correctness issues require remediation before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 High severity · 2 Medium severity · 1 Low severity

Open (6)
What changed in this PR

Adds a ScaledModel wrapper for scaling NLP objectives, constraints, Jacobians, and Hessians.

Changes:

  • Implements scaled model operations.
  • Registers the model and tests.
  • Extends test metadata and API coverage.
File Summary and review findings
test/​runtests.jl Registers scaled-model tests.
test/​nlp/​simple-model.jl Extends test metadata.
test/​nlp/​scaled-model.jl Adds API tests. Moderate (2 votes): tests use identity scaling and do not cover non-unit scaling, split Jacobian products, or multiplier Hessians.
src/​scaled-model.jl Implements scaling. Critical (3 votes): jprod_nln! delegates to the linear product. Critical (3 votes): passes unscaled y to the constraint Hessian. Critical (2 votes): CPU-only zeros allocations are incompatible with custom array types on lines 112 and 118. Moderate (3 votes): counters are neither delegated nor updated. Moderate (1 vote): y0 uses an incorrect multiplier transformation. Nit (3 votes): bound descriptions on lines 49 and 57 use ≥ instead of ≤.
src/​NLPModelsModifiers.jl Registers the new model implementation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/scaled-model.jl
# Get scaling for linear and nonlinear constraints.
scaling_cons_lin = scaling_cons[nlp.meta.lin]
scaling_cons_nln = scaling_cons[nlp.meta.nln]
scaling_jac_lin = zeros(T, nlp.meta.lin_nnzj)
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
Comment thread src/scaled-model.jl Outdated
return ScaledModel(
nlp,
meta,
NLPModels.Counters(),
Comment thread test/nlp/scaled-model.jl
@testset "ScaledModel NLP tests" begin
@testset "API" for T in [Float64, Float32], M in [NLPModelMeta, SimpleNLPMeta]
original_nlp = SimpleNLPModel(T, M)
nlp = ScaledModel(original_nlp)
Comment thread src/scaled-model.jl Outdated
@frapac

frapac commented Sep 20, 2026

Copy link
Copy Markdown
Author

The remaining comments have been addressed. Let me know if you any remaining feedback before merging this branch in main.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants