`NonlinearFunction(::ODEFunction)` drops the vector argument of `jvp`/`vjp`, so `NonlinearProblem(::SteadyStateProblem)` throws for any ODE function with a `jvp`
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 78/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- julia
調査の方向性
Read the conversion wrappers in src/scimlfunctions.jl, especially NonlinearFunction{iip}(f::ODEFunction) and ODEFunction{iip}(f::NonlinearFunction), then check test/convert_tests.jl for existing conversion coverage. Add tests for jvp and vjp in both directions and for in-place and out-of-place functions. Done means the converted products match the originals at t = Inf and the conversions succeed.
索引モデルが issue の本文から書いたものです。
説明
When an ODEFunction is converted to a NonlinearFunction at t = Inf, the jvp and vjp wrappers copy the jac wrapper and lose the vector argument v. The resulting jvp has one argument too few, and the NonlinearFunction constructor rejects it. So NonlinearProblem(SteadyStateProblem(prob)) throws whenever prob.f has a jvp, both in place and out of place. The reverse conversion ODEFunction(::NonlinearFunction) has the same defect.
Versions
SciMLBase 3.58.0 (the latest registered release), Julia 1.12.6, Linux x86_64. The wrappers are unchanged on master (f75f097e, 2026-11-02, version 3.59.1). We read the source there but did not run it.
Reproducer
using SciMLBase
f!(du, u, p, t) = (du .= -u; nothing)
jvp!(Jv, v, u, p, t) = (Jv .= -v; nothing) # documented in-place form
prob = SteadyStateProblem(ODEFunction{true}(f!; jvp = jvp!), [1.0, 2.0])
NonlinearProblem(prob)
# ERROR: Nonconforming functions detected. … Nonconforming functions: ["jvp"]
# out of place: jvp(v, u, p, t)
NonlinearFunction(ODEFunction{false}((u, p, t) -> -u; jvp = (v, u, p, t) -> -v))
# ERROR: All methods for the model function `f` had too few arguments. … Offending function: jvp
# (::SciMLBase.var"#101#102")(u, p) @ scimlfunctions.jl:3409
# the reverse direction
ODEFunction(NonlinearFunction{true}((du, u, p) -> (du .= -u; nothing); jvp = (Jv, v, u, p) -> (Jv .= -v; nothing)))
# ERROR: Nonconforming functions detected. … Nonconforming functions: ["jvp"]
All three errors were reproduced on 3.58.0. NonlinearFunction(odef) called directly fails like the first case.
Actual vs expected
Actual: the conversions throw. If the arity check were skipped, the wrapper would call f.jvp(Jv, u, p, Inf), which is 4 arguments for a 5-argument function.
Expected: the conversion succeeds, and the converted jvp(Jv, v, u, p) equals f.jvp(Jv, v, u, p, Inf). Written by hand, this works:
nf = NonlinearFunction{true}((du, u, p) -> f!(du, u, p, Inf); jvp = (Jv, v, u, p) -> jvp!(Jv, v, u, p, Inf))
Jv = zeros(2); nf.jvp(Jv, [1.0, 1.0], [1.0, 2.0], nothing) # Jv == [-1.0, -1.0]
Cause
src/scimlfunctions.jl (3.58.0; the same lines on master):
-
NonlinearFunction{iip}(f::ODEFunction), lines 3406-3417:_jvp = iip ? (Jv, u, p) -> (f.jvp(Jv, u, p, Inf); nothing) : (u, p) -> f.jvp(u, p, Inf) _vjp = iip ? (vJ, u, p) -> (f.vjp(vJ, u, p, Inf); nothing) : (u, p) -> f.vjp(u, p, Inf) -
ODEFunction{iip}(f::NonlinearFunction), lines 3356-3365:(Jv, u, p, t) -> f.jvp(Jv, u, p)and(u, p, t) -> f.jvp(u, p), and the same forvjp. -
The checks that reject them:
isinplace(jvp, 4 + argshift, "jvp", iip)inNonlinearFunction{iip, specialize}(line 4777), andisinplace(jvp, 5, "jvp", iip)inODEFunction{iip, specialize}(line 3191).
The wrappers date from 2022 (8e4bb3ae and #283). The jvp/vjp conversions have no test.
Suggested fix
Pass the vector through in all eight wrappers:
# NonlinearFunction{iip}(f::ODEFunction)
_jvp = iip ? (Jv, v, u, p) -> (f.jvp(Jv, v, u, p, Inf); nothing) : (v, u, p) -> f.jvp(v, u, p, Inf)
_vjp = iip ? (vJ, v, u, p) -> (f.vjp(vJ, v, u, p, Inf); nothing) : (v, u, p) -> f.vjp(v, u, p, Inf)
# ODEFunction{iip}(f::NonlinearFunction)
_jvp = iip ? (Jv, v, u, p, t) -> (f.jvp(Jv, v, u, p); nothing) : (v, u, p, t) -> f.jvp(v, u, p)
_vjp = iip ? (vJ, v, u, p, t) -> (f.vjp(vJ, v, u, p); nothing) : (v, u, p, t) -> f.vjp(v, u, p)
Suggested test: convert both ways, in place and out of place, with jvp and vjp set, and compare the products with the originals at t = Inf. It would fit in test/convert_tests.jl, which converts ODEProblems and SteadyStateProblems but has no conversion with a jvp or vjp set.
Related
We found no existing issue or PR. We searched SciMLBase, NonlinearSolve and SteadyStateDiffEq for "jvp" with "NonlinearFunction", "SteadyStateProblem", "Nonconforming" and "conversion". The nearest is #1430 (merged): it added the λ-shifted arity check (argshift) that these wrappers fail, but it did not touch the wrappers. We work around the bug with a NonlinearProblem method for our own problem type. We are glad to open a PR.
- 主要言語
- Julia
- スター
- 180
- フォーク
- 138
- 平均マージ
- 3日 18時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
SciML/SciMLBase.jl のほかの issue
-
`EnsembleSummary` `ci_type = :SEM` ribbon is `sqrt(N)` too wide for scalar states対応中かも @isaacsas が 14 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
SciML/SciMLBase.jl#1654 ·
メンテナーはふだん 3 日以内に返信
-
SavedSubsystem with an integer save_idxs maps the index the wrong way round対応中かも @ChrisRackauckas が 26 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
SciML/SciMLBase.jl#1643 ·
メンテナーはふだん 3 日以内に返信
-
Documentation of the fields in the problem types再び着手できるかも @Mxyank24 が 172 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンgood first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
SciML/SciMLBase.jl#152 · コメント 3 件 ·
メンテナーはふだん 3 日以内に返信
-
`value` and `unitfulvalue` strip only one layer from types, but all layers from values対応中かも @devmotion が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
SciML/SciMLBase.jl#1664 ·
メンテナーはふだん 3 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
SciML/SciMLBase.jl#1661 ·
メンテナーはふだん 3 日以内に返信
SciML/SciMLBase.jl の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
MagneticResonanceImaging/MRIReco.jl#366 ·
メンテナーはふだん 3 日以内に返信
-
`AdamW` gives `NaN` for zero-gradient entries of `Float16` parameters (epsilon underflows to 0)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
FluxML/Optimisers.jl#253 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
JuliaGraphs/GraphNeuralNetworks.jl#736 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信