Fix SROCK2 NoiseWrapper and non-square noise (#3188, #3170)#3468
Fix SROCK2 NoiseWrapper and non-square noise (#3188, #3170)#3468singhharsh1708 wants to merge 11 commits intoSciML:masterfrom
Conversation
4134cbe to
8480565
Compare
|
@oscardssmith any reviews on this fix ? |
| # Similarly tᵢ₋₂ = tₛ₋₂, tᵢ₋₁ = tₛ₋₁, tᵢ = tₛ | ||
|
|
||
| if (W.dW isa Number) || (length(W.dW) == 1) || is_diagonal_noise(integrator.sol.prob) | ||
| if (W.dW isa Number) || is_diagonal_noise(integrator.sol.prob) |
| function init_χ!(vec_χ, W) | ||
| r = rng(W) | ||
| for i in eachindex(vec_χ) | ||
| vec_χ[i] = 2 * floor(rand(r) + 0.5) - 1 |
There was a problem hiding this comment.
this assumes Float64, also isn't gpu compatible.
|
Needs convergence tests, I don't think the algorithm looks right. |
243293e to
157e080
Compare
|
The length(W.dW) == 1 check was removed because it caused incorrect behavior for non-diagonal noise with a single noise source (e.g. noise_rate_prototype = ones(n, 1)). In that case length(W.dW) == 1 is true but the noise is non-diagonal, so taking the scalar path u += Gₛ .* W.dW fails — Gₛ is n×1 and adding it to u (length-n vector) causes a DimensionMismatch. The mul! path is always correct for non-diagonal noise regardless of m. The is_diagonal_noise check already handles the scalar path correctly. |
|
DimensionMismatch for non-square noise (noise_rate_prototype = zeros(n, m)) |
|
Is the algorithm correct for non diagonal though? Or does it need levy area calculations? What does the paper say? |
|
The key paper is Abdulle, Vilmart, Zygalakis (2013) SIAM J. Sci. Comput. 35(4). Eq. (17) defines J_{q,r} = (ξ_q ξ_r ± χ_q) · h/2 for q ≠ r using Rademacher χ variables — those are exactly the terms commented out at line 461. For our PR's use case (noise_rate_prototype = zeros(n, 1), m=1), the q ≠ r cross terms never appear (loop runs once, i=j=1 only), so the Lévy area is trivially zero and the algorithm is correct as-is — confirmed by the weak order ~2 convergence test. The commented-out Lévy area is a pre-existing gap for general m>1 non-diagonal noise; implementing it would be a separate PR. |
|
Does the paper say it should converge order 2 on general non diagonal? |
|
Weak convergence tests should probably be in the special sets for the special runners since they are long running |
|
Yes — Abdulle, Vilmart, Zygalakis (2013) SIAM J. Sci. Comput. 35(4) Theorem 3.4 proves weak order 2 for general non-commutative non-diagonal noise of arbitrary dimension m. The full formula (eq. 17) requires the cross terms J_{q,r} = (ξ_q ξ_r ± χ_q) · h/2 for q ≠ r using Rademacher variables χ. These were previously commented out in both the OOP and IIP SROCK2 paths — now activated. Verified: m=2 non-diagonal gives order ~2.03, m=1 tests still pass. |
69e545a to
20345d1
Compare
- Add init_χ! helper and use correct RNG dispatch for NoiseWrapper - Remove broken commutative noise opt-out (length=1) for non-diagonal noise - This ensures matrix noise shapes correctly route to generalized noise path - Add DiffEqNoiseProcess to deps
- Add Random to [deps] so rand! is explicitly available so it works correctly for non-Float64 arrays and GPU arrays
Co-authored-by: Christopher Rackauckas <accounts@chrisrackauckas.com>
Co-authored-by: Christopher Rackauckas <accounts@chrisrackauckas.com>
…e; remove DiffEqNoiseProcess from extras
ff59b7f to
0f21faf
Compare
|
@ChrisRackauckas can you check once if it still needs changes.suddenly so many tests started failing ? |
|
The big v7 branch merged. The repo won't be in a normal development state until that's all out. Hopefully Friday, trying to get it complete but also it's very delicate and shouldn't be rushed. |
Fix SROCK2 NoiseWrapper and Non-Square Matrix Errors
Fixes #3188
Fixes #3170
Description
This addresses two major crashing bugs within the
SROCK2andKomBurSROCK2solver algorithms for non-diagonal problems:1.
NoiseWrapperFallback Exception (#3188)Previously, for non-diagonal cases, SROCK solvers attempted to extract RNG dynamically via inline
W.rngfield access, failing when noise was encapsulated in aNoiseWrapper.init_χ!logic originally proposed inStochasticDiffEq.jl#507which implements robustrng(W)methods that effectively extract underlying generator states from eitherAbstractNoiseProcessorNoiseWrapperstructs.DiffEqNoiseProcessandRandomtoStochasticDiffEqROCKdependencies.2. Non-Square Noise Matrix Dimension Mismatches (#3170)
For non-square matrices where
m=1(e.g.noise_rate_prototype = ones(n,1)), the algorithms were historically throwingMethodErrorandDimensionMismatchexceptions.length(W.dW) == 1, channeling non-diagonalm=1arrays into commutative scalar macro paths (likeu += Gₛ .* W.dW). This led identical structures to fall back onto scalar broadcasting rather than matrix multiplications (mul!).length(W.dW) == 1optimization check universally for non-diagonal caches/computations. By relying solely onis_diagonal_noise, we ensure all non-squareAbstractMatrixshapes route gracefully to the mathematically correct generalized summation loops utilizingmul!.Testing
test(2, 1, SROCK2())StochasticDiffEqROCKinternal regressions tests successfully pass.