Skip to content
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

Robust Singular Jacobian Handling #414

Merged
merged 7 commits into from
Apr 29, 2024
Merged

Conversation

avik-pal
Copy link
Member

@avik-pal avik-pal commented Apr 23, 2024

Current approach is:

  1. Proceed as usual
  2. On first linear solve failure:
    1. Construct a QRPivoted Cache and cache it
    2. Solve using Pivoted QR but warn the user that there is a potential singular Jacobian detected
    3. If successful, proceed as usual
    4. Otherwise:
      1. For "current" jacobian: stop nonlinear solve
      2. For approximate methods: follow a policy similar to line search routines
      3. For non-current exact jacobian: force a reset
  3. On later linear solve failure:
    1. Goto 2.2

TODOs

  • Switching to Pivoted QR
  • Add tests
  • Use verbose to turn off printing
  • Integrate it correctly into the algorithms -- currently assumes that switching is always successful.
  • How do we deal with non-standard Arrays? Basically how do we determine that PivotedQR is defined for the matrix A
  • Add missing docstrings to the documentation

@ChrisRackauckas any idea how to handle this last part?

@avik-pal
Copy link
Member Author

With this PR all of the following work:

using NonlinearSolve, LinearSolve

function nlls!(du, u, p)
    du[1] = 2u[1] - 2
    du[2] = (u[1] - 4u[2])^2 + 0.1
    du[3] = 0
end

u0 = [0.0, 0.0]
prob = NonlinearLeastSquaresProblem(
    NonlinearFunction(nlls!, resid_prototype = zeros(3)), u0)

solve(prob)

solve(prob, GaussNewton(; linsolve = QRFactorization()))

solve(prob, GaussNewton(; linsolve = LUFactorization()))

I always display a warning rn, but I will configure the verbose to not show the warning if needed.

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 73.73737% with 26 lines in your changes are missing coverage. Please review.

Project coverage is 86.34%. Comparing base (b389d0e) to head (914f556).

Files Patch % Lines
src/core/approximate_jacobian.jl 28.57% 10 Missing ⚠️
src/core/generalized_first_order.jl 64.28% 5 Missing ⚠️
src/descent/steepest.jl 16.66% 5 Missing ⚠️
src/internal/linear_solve.jl 86.66% 4 Missing ⚠️
src/descent/damped_newton.jl 85.71% 1 Missing ⚠️
src/descent/newton.jl 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #414      +/-   ##
==========================================
- Coverage   86.77%   86.34%   -0.44%     
==========================================
  Files          46       47       +1     
  Lines        2851     2914      +63     
==========================================
+ Hits         2474     2516      +42     
- Misses        377      398      +21     

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

@avik-pal avik-pal changed the title [WIP] Robust Singular Jacobian Handling Robust Singular Jacobian Handling Apr 25, 2024
@avik-pal
Copy link
Member Author

Needs SciML/LinearSolve.jl#494 before the tests pass

@avik-pal
Copy link
Member Author

avik-pal commented Apr 26, 2024

@ChrisRackauckas do you have a suggestion on how to deal with this

How do we deal with non-standard Arrays? Basically how do we determine that PivotedQR is defined for the matrix A

Apart for this, we are good to go here.

Okay maybe we can use ArrayInterface.isstructured and AnyGPUArray to safeguard against this

@avik-pal avik-pal marked this pull request as ready for review April 26, 2024 19:50
@ChrisRackauckas ChrisRackauckas merged commit d434b8d into master Apr 29, 2024
12 of 20 checks passed
@ChrisRackauckas ChrisRackauckas deleted the ap/linearsolve_retcode branch April 29, 2024 04:00
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.

2 participants