Giter Club home page Giter Club logo

sciml / simplenonlinearsolve.jl Goto Github PK

View Code? Open in Web Editor NEW
62.0 7.0 23.0 495 KB

Fast and simple nonlinear solvers for the SciML common interface. Newton, Broyden, Bisection, Falsi, and more rootfinders on a standard interface.

Home Page: https://docs.sciml.ai/NonlinearSolve/stable/

License: MIT License

Julia 100.00%
bisection-method broyden-method falsi-method falsi-position newton-raphson nonlinear-dynamics nonlinear-solvers rootfinding differential-equations julia

simplenonlinearsolve.jl's Introduction

SimpleNonlinearSolve.jl

Join the chat at https://julialang.zulipchat.com #sciml-bridged Global Docs

codecov Build Status Build status

ColPrac: Contributor's Guide on Collaborative Practices for Community Packages SciML Code Style

Fast implementations of root finding algorithms in Julia that satisfy the SciML common interface. SimpleNonlinearSolve.jl focuses on low-dependency implementations of very fast methods for very small and simple problems. For the full set of solvers, see NonlinearSolve.jl, of which SimpleNonlinearSolve.jl is just one solver set.

For information on using the package, see the stable documentation. Use the in-development documentation for the version of the documentation which contains the unreleased features.

High Level Examples

using SimpleNonlinearSolve, StaticArrays

f(u, p) = u .* u .- 2
u0 = @SVector[1.0, 1.0]
probN = NonlinearProblem{false}(f, u0)
solver = solve(probN, SimpleNewtonRaphson(), abstol = 1e-9)

## Bracketing Methods

f(u, p) = u .* u .- 2.0
u0 = (1.0, 2.0) # brackets
probB = IntervalNonlinearProblem(f, u0)
sol = solve(probB, ITP())

For more details on the bracketing methods, refer to the Tutorials and detailed APIs

Breaking Changes in v1.0.0

  • Batched solvers have been removed in favor of BatchedArrays.jl. Stay tuned for detailed tutorials on how to use BatchedArrays.jl with NonlinearSolve & SimpleNonlinearSolve solvers.
  • The old style of specifying autodiff with chunksize, standardtag, etc. has been deprecated in favor of directly specifying the autodiff type, like AutoForwardDiff.
  • Broyden and Klement have been renamed to SimpleBroyden and SimpleKlement to avoid conflicts with NonlinearSolve.jl's GeneralBroyden and GeneralKlement, which will be renamed to Broyden and Klement in the future.
  • LBroyden has been renamed to SimpleLimitedMemoryBroyden to make it consistent with NonlinearSolve.jl's LimitedMemoryBroyden.

simplenonlinearsolve.jl's People

Contributors

arnostrouwen avatar avik-pal avatar chrisrackauckas avatar daniglez avatar deltadahl avatar dependabot[bot] avatar erikqqy avatar fholtorf avatar gdalle avatar huiyuxie avatar oscardssmith avatar prbzrg avatar ranocha avatar timholy avatar tomrottier avatar utkarsh530 avatar vaibhavdixit02 avatar wsshin avatar yash-rs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplenonlinearsolve.jl's Issues

Investigate changing to use `__solve` and `__init` for adjoints and error throwing

Using __solve as mentioned in https://docs.sciml.ai/DiffEqDevDocs/stable/contributing/adding_packages/ allows the package to use the DiffEqBase.jl high level solve handling:

https://github.com/SciML/DiffEqBase.jl/blob/master/src/solve.jl

This will throw better error messages and make the adjoints work. However, we should time it to know if there is an overhead induced by this. There shouldn't be, but we should make sure.

`SimpleLimitedMemoryBroyden` fails inside GPU kernel

using SimpleNonlinearSolve, StaticArrays

using CUDA
f(u, p) = u .* u .- 2
u0 = @SVector[1.f0, 1.f0]
probN = NonlinearProblem{false}(f, u0)
solver = solve(probN, SimpleLimitedMemoryBroyden())

function test(probN)
    solve(probN, SimpleLimitedMemoryBroyden())
    return nothing
end

@cuda test(probN) #fails

abstol and reltol are ignored

abstol and reltol keyword arguments seem to be ignored.

This makes SimpleNonlinearSolve unusable for any problem that returns a result with less than full floating point precision

julia> using SimpleNonlinearSolve

julia> f(u, p) = u^4 .- 2.0
julia> prob = IntervalNonlinearProblem(f, (1.0, 2.0))

julia> sol = solve(probB, Brent())  # full precision
u: 1.1892071150027212

julia> sol = solve(prob, Brent(), maxiters=3) # maxiters works
u: 1.0666666666666667

julia> sol = solve(prob, Brent(), abstol=0.1)  # abstol is ignored and gives the maximum precision
u: 1.1892071150027212

More fundamental problem perhaps is that there are apparently no tests for abstol and reltol ?

`SimpleBroyden` on second invocation segfaults inside the GPU kernel

Describe the bug 🐞

SimpleBroyden on the second invocation segfaults inside the GPU kernel.

Expected behavior
The SimpleBroyden and other "Simple" solvers should be able to work inside the kernel

Minimal Reproducible Example πŸ‘‡

using SimpleNonlinearSolve, StaticArrays

using CUDA
f(u, p) = u .* u .- 2
u0 = @SVector[1.f0, 1.f0]
probN = NonlinearProblem{false}(f, u0)
solver = solve(probN, SimpleBroyden())

function test(probN)
    solve(probN, SimpleBroyden(), abstol = 1f-6, reltol = 1f-6)
    return nothing
end

@cuda test(probN) #works
@cuda test(probN) #fails

Error & Stacktrace ⚠️

julia> @cuda test(probN)
ERROR: CUDA error: an illegal memory access was encountered (code 700, ERROR_ILLEGAL_ADDRESS)
Stacktrace:
  [1] throw_api_error(res::CUDA.cudaError_enum)
    @ CUDA ~/.julia/packages/CUDA/35NC6/lib/cudadrv/libcuda.jl:27
  [2] check
    @ ~/.julia/packages/CUDA/35NC6/lib/cudadrv/libcuda.jl:34 [inlined]
  [3] cuLaunchKernel
    @ ~/.julia/packages/CUDA/35NC6/lib/utils/call.jl:26 [inlined]
  [4] (::CUDA.var"#863#864"{Bool, Int64, CuStream, CuFunction, CuDim3, CuDim3})(kernelParams::Vector{Ptr{Nothing}})
    @ CUDA ~/.julia/packages/CUDA/35NC6/lib/cudadrv/execution.jl:69
  [5] macro expansion
    @ ~/.julia/packages/CUDA/35NC6/lib/cudadrv/execution.jl:33 [inlined]
  [6] macro expansion
    @ ./none:0 [inlined]
  [7] pack_arguments(::CUDA.var"#863#864"{Bool, Int64, CuStream, CuFunction, CuDim3, CuDim3}, ::CUDA.KernelState, ::NonlinearProblem{SVector{2, Float32}, false, SciMLBase.NullParameters, NonlinearFunction{false, SciMLBase.FullSpecialize, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardNonlinearProblem})
    @ CUDA ./none:0
  [8] #launch#862
    @ ~/.julia/packages/CUDA/35NC6/lib/cudadrv/execution.jl:62 [inlined]
  [9] #868
    @ ~/.julia/packages/CUDA/35NC6/lib/cudadrv/execution.jl:136 [inlined]
 [10] macro expansion
    @ ~/.julia/packages/CUDA/35NC6/lib/cudadrv/execution.jl:95 [inlined]
 [11] macro expansion
    @ ./none:0 [inlined]
 [12] convert_arguments
    @ ./none:0 [inlined]
 [13] #cudacall#867
    @ ~/.julia/packages/CUDA/35NC6/lib/cudadrv/execution.jl:135 [inlined]
 [14] cudacall
    @ ~/.julia/packages/CUDA/35NC6/lib/cudadrv/execution.jl:134 [inlined]
 [15] macro expansion
    @ ~/.julia/packages/CUDA/35NC6/src/compiler/execution.jl:219 [inlined]
 [16] macro expansion
    @ ./none:0 [inlined]
 [17] #call#1045
    @ ./none:0 [inlined]
 [18] call
    @ ./none:0 [inlined]
 [19] #_#1060
    @ ~/.julia/packages/CUDA/35NC6/src/compiler/execution.jl:340 [inlined]
 [20] (::CUDA.HostKernel{typeof(test), Tuple{NonlinearProblem{SVector{2, Float32}, false, SciMLBase.NullParameters, NonlinearFunction{false, SciMLBase.FullSpecialize, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardNonlinearProblem}}})(args::NonlinearProblem{SVector{2, Float32}, false, SciMLBase.NullParameters, NonlinearFunction{false, SciMLBase.FullSpecialize, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED_NO_TIME), Nothing, SymbolicIndexingInterface.SymbolCache{Nothing, Nothing, Nothing}, Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardNonlinearProblem})
    @ CUDA ~/.julia/packages/CUDA/35NC6/src/compiler/execution.jl:339
 [21] top-level scope
    @ ~/.julia/packages/CUDA/35NC6/src/compiler/execution.jl:106

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
  • Output of using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
  • Output of versioninfo()

Additional context

Add any other context about the problem here.

Improve the performance of LBroyden

#41

https://github.com/SciML/SimpleNonlinearSolve.jl/blob/main/src/lbroyden.jl#L47-L49
https://github.com/SciML/SimpleNonlinearSolve.jl/blob/main/src/lbroyden.jl#L61-L62
https://github.com/SciML/SimpleNonlinearSolve.jl/blob/main/src/lbroyden.jl#L64-L66
https://github.com/SciML/SimpleNonlinearSolve.jl/blob/main/src/lbroyden.jl#L71

These all allocate. We can instead allocate once and make those all in-place. There's no need for a NonlinearSolve.jl version because it's still a rather straightforward method (no Jacobians), and this is really the only tweak that needs to be done.

ITP default values differ from Tuning Parameters

First of all, thank you for this great package!

When looking through the documentation of the ITP-Method (and the code), I noticed that the default values of the parameters are different between the header (==code) and the 'Tuning Parameters' section which seems to be wrong.
Is there a reason that k2 is not an int as recommended in the text?

Warning: NLSolveTerminationCondition has been deprecated in favor of the new dispatch based termination conditions.

β”Œ SimpleNonlinearSolve [727e6d20-b764-4bd8-a329-72de5adea6c7]
β”‚  β”Œ Warning: NLSolveTerminationCondition has been deprecated in favor of the new dispatch based termination conditions. Please use the new termination conditions API!
β”‚  β”‚   caller = SimpleNonlinearSolve.Broyden() at broyden.jl:20
β”‚  β”” @ SimpleNonlinearSolve ~/.julia/packages/SimpleNonlinearSolve/cW4pm/src/broyden.jl:20
β”‚  β”Œ Warning: NLSolveTerminationCondition has been deprecated in favor of the new dispatch based termination conditions. Please use the new termination conditions API!
β”‚  β”‚   caller = SimpleNonlinearSolve.SimpleDFSane() at dfsane.jl:67
β”‚  β”” @ SimpleNonlinearSolve ~/.julia/packages/SimpleNonlinearSolve/cW4pm/src/dfsane.jl:67
β””  

https://github.com/SciML/NonlinearSolve.jl/actions/runs/6716303943/job/18252333439#step:6:744

SimpleTrustRegion() diverges while SimpleNewtonRaphson() converges in MWE

First, I want to say thank you for developing this package! I've been using NLsolve.jl for years now and am excited by the increased performance I'll obtain with your fast implementations of NewtonRaphson and TrustRegion algorithms.

I've put together an MWE that involves finding the solution to a spacecraft trajectory optimization problem using simple forward shooting. I already know a solution to this problem, and am setting an initial guess that is very near this solution. As expected, SimpleNewtonRaphson() successfully converges to the solution, but SimpleTrustRegion() diverges.

I suppose this could be a non-issue as there are no convergence guarantees when solving general nonlinear systems, but from my experience with this problem, I find it strange that the trust region algorithm fails to converge in this case. I understand that SimpleTrustRegion() was implemented recently, so I wanted to post this issue in the hopes that it will help identify any bug that could be causing this behavior.

using DifferentialEquations
using StaticArrays
using SimpleNonlinearSolve

# State/Costate equations of motion for min-fuel trajectory optimization in CRTBP model
function crtbp_min_fuel_eom(x, p, t)
    # Grab states 
    rx = x[1]; ry = x[2]; rz = x[3]
    vx = x[4]; vy = x[5]; vz = x[6]
    m  = x[7]

    # Grab costates
    lam_rx = x[8]; lam_ry = x[9]; lam_rz = x[10]
    lam_vx = x[11]; lam_vy = x[12]; lam_vz = x[13]

    # Grab parameters
    mu = p[1]
    T_max = p[2]
    c = p[3]
    u = p[4]

    return @fastmath begin
        # Start of MATLAB generated code
        t2 = mu+rx;
        t3 = lam_vx*lam_vx;
        t4 = lam_vy*lam_vy;
        t5 = lam_vz*lam_vz;
        t8 = ry*ry;
        t9 = rz*rz;
        t10 = 1.0/m;
        t11 = mu-1.0;
        t12 = t2-1.0;
        t13 = t2*t2;
        t17 = t3+t4+t5;
        t14 = t12*t12;
        t18 = t8+t9+t13;
        t20 = 1.0/sqrt(t17);
        t19 = t8+t9+t14;

        # We can make this code faster so we will...
        #t21 = 1.0/pow(t18,3.0/2.0);
        #t22 = 1.0/pow(t18,5.0/2.0);
        tt1 = sqrt(t18)
        tt13 = tt1*tt1*tt1
        tt15 = tt13*tt1*tt1
        t21 = 1.0/tt13
        t22 = 1.0/tt15

        # Same thing here...
        #t23 = 1.0/pow(t19,3.0/2.0);
        #t24 = 1.0/pow(t19,5.0/2.0);
        tt2 = sqrt(t19)
        tt23 = tt2*tt2*tt2
        tt25 = tt23*tt2*tt2
        t23 = 1.0/tt23
        t24 = 1.0/tt25

        t26 = t11*t21;
        t29 = ry*rz*t11*t22*3.0;
        t25 = mu*t23;
        t28 = mu*ry*rz*t24*3.0;
        t27 = -t25;
        return SA[
            vx, vy, vz,
            rx+vy*2.0+t2*t26+t12*t27-T_max*lam_vx*t10*t20*u,
            ry-vx*2.0+ry*t26+ry*t27-T_max*lam_vy*t10*t20*u,
            rz*t26+rz*t27-T_max*lam_vz*t10*t20*u,
            -(T_max*u)/c,
            -lam_vy*(mu*ry*t12*t24*3.0-ry*t2*t11*t22*3.0)-lam_vz*(mu*rz*t12*t24*3.0-rz*t2*t11*t22*3.0)-lam_vx*(t26+t27+mu*t14*t24*3.0-t11*t13*t22*3.0+1.0),
            -lam_vz*(t28-t29)-lam_vx*(mu*ry*t12*t24*3.0-ry*t2*t11*t22*3.0)-lam_vy*(t26+t27+mu*t8*t24*3.0-t8*t11*t22*3.0+1.0),
            -lam_vy*(t28-t29)-lam_vx*(mu*rz*t12*t24*3.0-rz*t2*t11*t22*3.0)+lam_vz*(t25-t26-mu*t9*t24*3.0+t9*t11*t22*3.0),
            -lam_rx+lam_vy*2.0,
            -lam_ry-lam_vx*2.0,
            -lam_rz,
            -(T_max*(t10*t10)*u)/t20,
        ]
    end
end

function condition(u,t,integ)
    c = integ.p[3]
    Ξ»v = sqrt(u[11]*u[11] + u[12]*u[12] + u[13]*u[13])
    return -c*Ξ»v/u[7] - u[14] + 1.0
end

function affect!(integrator)
    params_pre_affect   = integrator.p
    new_throttle_factor = params_pre_affect[end] == 1 ? 0 : 1
    integrator.p = (params_pre_affect[1], params_pre_affect[2], params_pre_affect[3], new_throttle_factor)
    return nothing
end

function initialize!(c, u, t, integrator)
    c   = integrator.p[3]
    Ξ»v  = sqrt(u[11]*u[11] + u[12]*u[12] + u[13]*u[13])
    S   = -c*Ξ»v/u[7] - u[14] + 1.0   
    sf  = 1
    if S > 0
        sf = 0
    end
    ps  = integrator.p
    integrator.p = (ps[1], ps[2], ps[3], sf)
    return nothing
end

function shooting_function(Ξ»0, p)
    # Grab parameters
    x0      = p[1]
    xf      = p[2]
    tspan   = p[3]
    mu      = p[4]
    T_max   = p[5]
    c       = p[6]

    # Form full initial state
    y0 = SA[
        x0[1], x0[2], x0[3], x0[4], x0[5], x0[6], x0[7],
        Ξ»0[1], Ξ»0[2], Ξ»0[3], Ξ»0[4], Ξ»0[5], Ξ»0[6], Ξ»0[7],
    ]

    # Integrate dynamics from initial condition
    cb   = ContinuousCallback(
        condition, 
        affect!;
        initialize = initialize!,
        rootfind = SciMLBase.RightRootFind,
    ) 

    prob = ODEProblem{false,SciMLBase.FullSpecialize}(
        crtbp_min_fuel_eom, 
        y0, 
        tspan, 
        (mu, T_max, c, 1),
    )

    sol  = solve(
        prob, 
        Vern9(); 
        abstol = 1e-14, 
        reltol = 1e-14, 
        save_everystep = false, 
        save_start = false, 
        initialize_save = false,
        maxiters = 1e7,
        callback = cb,
    )
    sxf  = sol[end]

    # Return final boundary condition residual
    return SA[
        sxf[1] - xf[1],
        sxf[2] - xf[2],
        sxf[3] - xf[3],
        sxf[4] - xf[4],
        sxf[5] - xf[5],
        sxf[6] - xf[6],
        sxf[14],
    ]
end

function main()
    # CRTBP parameters
    G = 6.673e-20
    m_e = 5.9742e24     # kg
    m_m = 7.3483e22     # kg
    r_em = 384400.0     # km
    mu = 1.21506038e-2

    # Define spacecraft parameters
    T_max_si = 10e-3    # kg*km/s^2
    I_sp_si = 3000.0    # s
    g_0_si = 9.81e-3    # km/s^2
    c_si = I_sp_si * g_0_si
    m0_si = 1500.0      # kg

    # Units
    LU = r_em
    TU = 1.0 / sqrt((G*(m_e + m_m)) / LU^3)
    MU = m0_si

    # Scale parameters
    T_max_nd = T_max_si * TU^2 / (MU * LU) 
    c_nd = c_si * TU / LU

    # Define time of flight
    tspan = (0.0, 8.6404*86400.0 / TU)

    # Define initial spacecraft state
    x0 = SA[
        -0.0194885115, -0.0160334798, 0.0,
        8.9188819237, -4.0817936888, 0.0, 1.0,
    ]

    # Define initial co-state guess (Traj. B min. fuel solution from Acta Astronautica paper)
    Ξ»0 = SA[
        15.68499615832586,
        33.031211178919726,
        -0.09381690521953079,
        -0.10207501688908052,
        0.045012820414046514,
        -0.00015063964363906,
        0.1334329267459845,
    ]

    # Define target spacecraft state (note final mass unconstrainted)
    xf = SA[
        0.8233851820, 0.0, -0.0222775563,
        0.0, 0.1341841703, 0.0,
    ]

    # Define Nonlinear Problem
    params = (x0, xf, tspan, mu, T_max_nd, c_nd)

    # Try to solve
    prob = NonlinearProblem{false}(shooting_function, Ξ»0, params)

    # Here, SimpleTrustRegion() diverges whereas SimpleNewtonRaphson() converges

    Ξ»0 = solve(prob, SimpleTrustRegion(); verbose = true) # Unfortunately, verbose = true does nothing currently :(
    #Ξ»0 = solve(prob, SimpleNewtonRaphson(); verbose = true)

    # Compute residual
    resid = shooting_function(Ξ»0, params)

    # If residual is small enough, we have a solution
    max_resid = maximum(abs.(resid))
    display(max_resid)

    return nothing
end

main()

SimpleNewtonRaphson not using provided Jacobian

The documentation for SimpleNewtonRaphson says autodiff is ignored if a user provides a Jacobian. SimpleNewtonRaphson never uses a provided Jacobian, however, while NewtonRaphson does. For example:

using NonlinearSolve, StaticArrays

const R0 = 3.0
const Z0 = 0.0
const a  = 1.0

function f(u, p)
    r = u[1] * a
    st, ct = sincos(u[2])
    dR = R0 + r * ct - p[1]
    dZ = Z0 - r * st - p[2]
    return @SVector[dR, dZ]
end

u0 = @SVector[0.5, 0.0]
p = @SVector[3.3, 0.5]
probN = NonlinearProblem{false}(f, u0, p)

sol = NonlinearSolve.solve(probN, SimpleNewtonRaphson())
println("No Jac:", sol)
println()

function J(u, p)
    println("Using Jacobian")
    r = a * u[1]
    st, ct = sincos(u[2])
    J11 =   a * ct 
    J12 = - r * st
    J21 = - a * st
    J22 = - r * ct
    return @SMatrix[J11 J12; J21 J22]
end
fJ = NonlinearFunction(f; jac=J)
probN = NonlinearProblem{false}(fJ, u0, p)
sol = NonlinearSolve.solve(probN, SimpleNewtonRaphson())
println("Fails to use Jac: ", sol)
println()

sol = NonlinearSolve.solve(probN, NewtonRaphson())
println("Uses Jac: ", sol)

Gives

No Jac:[0.5830951894845299, -1.030376826524313]

Fails to use Jac: [0.5830951894845299, -1.030376826524313]

Using Jacobian
Using Jacobian
Using Jacobian
Using Jacobian
Uses Jac: [0.5830951894592991, -1.030376830345174]

Return codes for trust region failures

Hey,

For the trust region implementation we currently return ReturnCode.Success even when the algorithm stalled:

if isapprox(xβ‚–β‚Šβ‚, x, atol = atol, rtol = rtol)
return SciMLBase.build_solution(prob, alg, xβ‚–β‚Šβ‚, Fβ‚–β‚Šβ‚;
retcode = ReturnCode.Success)

and

if shrink_counter > max_shrink_times
return SciMLBase.build_solution(prob, alg, x, F;
retcode = ReturnCode.Success)

Changing that to ReturnCode.ConvergenceFailure leads to several broken tests and I don't quite understand what is happening there. Who should I talk to?

Solve with SimpleNewtonRaphson fails with ComplexF64

When defining for example a DAE through DifferentialEquations.jl, some initialization algorithms go through SimpleNewtonRaphson. If the elementary type is complex, say ComplexF64, then the line

atol = abstol !== nothing ? abstol : oneunit(eltype(T)) * (eps(one(eltype(T))))^(4 // 5)

in the function SciMLBase.solve(prob::NonlinearProblem, alg::SimpleNewtonRaphson,...) gives a complex atol, resulting in an error
ERROR: TypeError: in keyword argument atol, expected Real, got a value of type ComplexF64
I suggest to take the absolute value of oneunit, so

atol = abstol !== nothing ? abstol : abs(oneunit(eltype(T))) * (eps(one(eltype(T))))^(4 // 5)

I don't know if this is type stable though...

Implementing Broyden solver

This will be my first open-source PR, so I've got a couple of questions.

  1. Is it ok to add a dependency on "LinearAlgebra"? (added "using LinearAlgebra")
  2. I'm not 100% sure what supertype to use. I'm using "AbstractSimpleNonlinearSolveAlgorithm" at the moment.

Warning at Precompiling

β”Œ SimpleNonlinearSolve
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β”‚  β”Œ Warning: Not specifying the internal norm of termination conditions has been deprecated. Using inf-norm currently.
β”‚  β”‚   caller = check_convergence at termination_conditions.jl:461 [inlined]
β”‚  β”” @ Core C:\Users\prbzr\.julia\packages\DiffEqBase\O8cUq\src\termination_conditions.jl:461
β””

Implement Brent methods

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.brentq.html#scipy.optimize.brentq
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.brenth.html#scipy.optimize.brenth

Brent1973
Brent, R. P., Algorithms for Minimization Without Derivatives. Englewood Cliffs, NJ: Prentice-Hall, 1973. Ch. 3-4.

[PressEtal1992]
Press, W. H.; Flannery, B. P.; Teukolsky, S. A.; and Vetterling, W. T. Numerical Recipes in FORTRAN: The Art of Scientific Computing, 2nd ed. Cambridge, England: Cambridge University Press, pp. 352-355, 1992. Section 9.3: β€œVan Wijngaarden-Dekker-Brent Method.”

Bus, J. C. P., Dekker, T. J., β€œTwo Efficient Algorithms with Guaranteed Convergence for Finding a Zero of a Function”, ACM Transactions on Mathematical Software, Vol. 1, Issue 4, Dec. 1975, pp. 330-345. Section 3: β€œAlgorithm M”. DOI:10.1145/355656.355659

Depreciation warning about retcodes

f(x) = x^2
u0 = 1
probN = NonlinearProblem(f, u0, p)
solver = solve(probN, NewtonRaphson())

Results in the warning:

 Warning: Backwards compatability support of the new return codes to Symbols will be deprecated with the Julia v1.9 release. Please see https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes for more information
β”” @ SciMLBase C:\Users\thvt\.julia\packages\SciMLBase\nzvrv\src\retcodes.jl:360

(this is on NonlinearSolve v1.1.1)

Meaning that somewhere old style retcodes are still used in this? I haven't dug down where yet.

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.