consistent_meta: add an absolute tolerance (zero initial points fail on rounding), and test the boolean fields
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 57/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 領域
- testing
調査の方向性
Read src/nlp/consistency.jl, especially consistent_meta at lines 95–123 and the consistent_functions comparison around line 182. Check existing tests for consistent_meta and how consistent_nlps passes keyword arguments; then add coverage for near-zero vector fields and boolean fields. Done means the tolerance handles the reproducer and boolean comparisons are tested, with any intended exceptions clarified.
索引モデルが issue の本文から書いたものです。
説明
Written by Claude (Claude Code) at the request of @ocots.
Summary
consistent_meta compares the vector fields of the meta (x0, lvar, uvar, y0, …) with a relative tolerance only. Two NLPs whose initial points are both zero, up to rounding, are therefore reported as inconsistent. The comparisons of consistent_functions already add an absolute floor; consistent_meta could do the same.
A second, smaller point: the boolean fields (grad_available, …) are read but never tested.
Where
src/nlp/consistency.jl, v0.10.9, unchanged on main: consistent_meta, lines 95–123
function consistent_meta(nlps; rtol = 1.0e-8)
fields = [:nvar, :x0, :lvar, :uvar, :ifix, :ilow, :iupp, :irng, :ifree, :ncon, :y0]
boolean_fields = [:grad_available, :jac_available, :hess_available,
:jprod_available, :jtprod_available, :hprod_available]
N = length(nlps)
for field in fields
@testset "Field $field" begin
for i = 1:(N - 1)
fi = getfield(nlps[i].meta, field)
fj = getfield(nlps[i + 1].meta, field)
@test isapprox(fi, fj, rtol = rtol) # relative only
end
end
end
for field in boolean_fields
@testset "Field $field" begin
for i = 1:(N - 1)
fi = getfield(nlps[i].meta, field)
fj = getfield(nlps[i + 1].meta, field)
# no @test: the fields are read, not compared
end
end
end
end
For vectors, isapprox(a, b; rtol) tests ‖a − b‖ ≤ rtol · max(‖a‖, ‖b‖). When both vectors are zero up to rounding, the right-hand side is itself at rounding level, and the test fails.
The functions are compared with an absolute floor instead, for example the objective at line 182:
@test isapprox(fs[i], fs[j], atol = rtol * max(fmin, 1.0))
Reproducer
using ADNLPModels, NLPModelsTest, Test
f(x) = sum(x .^ 2)
a = ADNLPModel(f, [0.0, 0.0])
b = ADNLPModel(f, [0.0, 1e-14]) # the same point, up to rounding
@testset "repro" begin
NLPModelsTest.consistent_meta([a, b])
end
Field x0: Test Failed at .../NLPModelsTest/src/nlp/consistency.jl:111
Expression: isapprox(fi, fj, rtol = rtol)
Evaluated: isapprox([0.0, 0.0], [0.0, 1.0e-14]; rtol = 1.0e-8)
Test Summary: | Pass Fail Total
repro | 10 1 11
Field x0 | 1 1
...
Field grad_available | 0
Field jac_available | 0
The last lines show the second point: the *_available fields contribute no test.
How we use it
In OptimalControlProblems.jl, we check that the JuMP model of each optimal control problem is exactly the NLP that CTDirect builds with ADNLPModels (control-toolbox/OptimalControlProblems.jl#371, control-toolbox/OptimalControlProblems.jl#166). The two NLPs have their variables and constraints in different orders, so we wrap one of them in an AbstractNLPModel that presents it in the order of the other, then call consistent_nlps([adnlp, wrapped]).
consistent_functions evaluates at x = 10 * [-(-1)^i], which is outside the domain of several of our problems (NaN from log, sqrt, divisions). We therefore recentre both NLPs the same way around their initial point: x ↦ x0 + s·x. The initial point of the recentred NLPs is then 0 for one and about 1e-13 for the other, and Field x0 fails, although the two models are the same. We work around it by recentring so that the initial point becomes 1 instead of 0. That works, but it is a trick to avoid a tolerance problem.
Suggestion
-
Give
consistent_metathe same absolute floor asconsistent_functions, with anatolkeyword thatconsistent_nlpspasses through:function consistent_meta(nlps; rtol = 1.0e-8, atol = rtol) ... @test isapprox(fi, fj, rtol = rtol, atol = atol)This reads
‖a − b‖ ≤ max(atol, rtol · max(‖a‖, ‖b‖)). A test that passes today still passes. For the integer fields (nvar,ncon,ifix, …),==would be clearer thanisapprox. -
Test the boolean fields:
@test fi == fjOne caveat: some tests in the ecosystem may compare models that differ in these flags on purpose, for example a model without
hprodagainst one with it. Thenconsistent_nlpscould take the list of flags to compare, or report a difference in them as a warning.
We are happy to open a pull request if this direction suits you.
- 主要言語
- Julia
- スター
- 7
- フォーク
- 4
- 平均マージ
- 17時間 32分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaSmoothOptimizers/NLPModelsTest.jl のほかの issue
-
Update the tests with the counters with both legacy and linear API are implemented再び着手できるかも @tmigot が 483 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug
JuliaSmoothOptimizers/NLPModelsTest.jl#124 · 担当者 1 名 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
enhancement good first issue
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
JuliaSmoothOptimizers/NLPModelsTest.jl の issue をすべて見る
似ている issue
-
Release CorleoneInverse as 0.1.1対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
SciML/Corleone.jl#200 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
JuliaAI/MLJTransforms.jl#120 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
exercism/julia#1205 · コメント 3 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
SciML/OrdinaryDiffEq.jl#5175 ·
メンテナーはふだん 1 日以内に返信