Skip to content

feat: improve performance of the nonlinear functions #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2025
Merged

Conversation

avik-pal
Copy link
Member

No description provided.

Copy link
Member

@ErikQQY ErikQQY left a comment

Choose a reason for hiding this comment

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

LGTM!

I am wondering if the failures of BVProblemLibrary.jl are real? I can't reproduce the same error locally.

@avik-pal avik-pal merged commit 2898045 into master Apr 20, 2025
12 of 18 checks passed
@ChrisRackauckas ChrisRackauckas deleted the ap/eff branch April 23, 2025 09:03
ChrisRackauckas added a commit to SciML/NonlinearSolve.jl that referenced this pull request Apr 23, 2025
This update is required due to SciML/DiffEqProblemLibrary.jl#138. Its inherently just a numerical instability. https://github.com/SciML/DiffEqProblemLibrary.jl/pull/138/files#diff-416284a99fdfe358ae2a33c649aa3a715568ff3cf4d0d0cf62e6c7a183aa9fc7R111 this change is effectively random, looking at:

```julia
zz = out[1] + 3.0 * x[1] - 2.0 * x[1] * x[2] + 2.0 * x[1]^3
zzz = out[2] + x[2] - x[2]^2 - 1.0

out[1] += x[1] * (3.0 - 2.0 * x[2] + 2.0 * x[1]^2)
out[2] += x[2] * (1.0 - x[2]) - 1.0

if abs(out[1] - zz) > 1e5
    @show out[1] - zz, out[2] - zzz, x[1], x[2]
    @show 2.0 * x[2], 2.0 * x[1]^2
    @show 3.0 * x[1], 2.0 * x[1] * x[2], 2.0 * x[1]^3
    error()
end
```

I get:


```
(out[1] - zz, out[2] - zzz, x[1], x[2]) = (-2048.0, 0.0, 1.032129073975807e6, -1.109530258395812e6)
(2.0 * x[2], 2.0 * x[1] ^ 2) = (-2.219060516791624e6, 2.130580850692314e12)
(3.0 * x[1], 2.0 * x[1] * x[2], 2.0 * x[1] ^ 3) = (3.096387221927421e6, -2.2903568762924146e12, 2.1990344404556452e18)
```

```
(out[1] - zz, out[2] - zzz, x[1], x[2]) = (-4.503599627370496e15, 0.0, 2.027697193465798e10, -3.714249421601087e10)
(2.0 * x[2], 2.0 * x[1] ^ 2) = (-7.428498843202174e10, 8.223111816778149e20)
(3.0 * x[1], 2.0 * x[1] * x[2], 2.0 * x[1] ^ 3) = (6.0830915803973946e10, -1.5062746256024978e21, 1.6673980752436494e31)
```

with different thresholds. Basically when `x[1]` is large the error is floating point noise, and that floating point noise is enough for Broyden to be stable vs unstable.
ChrisRackauckas added a commit to SciML/NonlinearSolve.jl that referenced this pull request Apr 23, 2025
This update is required due to SciML/DiffEqProblemLibrary.jl#138. Its inherently just a numerical instability. https://github.com/SciML/DiffEqProblemLibrary.jl/pull/138/files#diff-416284a99fdfe358ae2a33c649aa3a715568ff3cf4d0d0cf62e6c7a183aa9fc7R111 this change is effectively random, looking at:

```julia
zz = out[1] + 3.0 * x[1] - 2.0 * x[1] * x[2] + 2.0 * x[1]^3
zzz = out[2] + x[2] - x[2]^2 - 1.0

out[1] += x[1] * (3.0 - 2.0 * x[2] + 2.0 * x[1]^2)
out[2] += x[2] * (1.0 - x[2]) - 1.0

if abs(out[1] - zz) > 1e5
    @show out[1] - zz, out[2] - zzz, x[1], x[2]
    @show 2.0 * x[2], 2.0 * x[1]^2
    @show 3.0 * x[1], 2.0 * x[1] * x[2], 2.0 * x[1]^3
    error()
end
```

I get:


```
(out[1] - zz, out[2] - zzz, x[1], x[2]) = (-2048.0, 0.0, 1.032129073975807e6, -1.109530258395812e6)
(2.0 * x[2], 2.0 * x[1] ^ 2) = (-2.219060516791624e6, 2.130580850692314e12)
(3.0 * x[1], 2.0 * x[1] * x[2], 2.0 * x[1] ^ 3) = (3.096387221927421e6, -2.2903568762924146e12, 2.1990344404556452e18)
```

```
(out[1] - zz, out[2] - zzz, x[1], x[2]) = (-4.503599627370496e15, 0.0, 2.027697193465798e10, -3.714249421601087e10)
(2.0 * x[2], 2.0 * x[1] ^ 2) = (-7.428498843202174e10, 8.223111816778149e20)
(3.0 * x[1], 2.0 * x[1] * x[2], 2.0 * x[1] ^ 3) = (6.0830915803973946e10, -1.5062746256024978e21, 1.6673980752436494e31)
```

with different thresholds. Basically when `x[1]` is large the error is floating point noise, and that floating point noise is enough for Broyden to be stable vs unstable.
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.

3 participants