bifurcationkit / BifurcationInference.jl

learning state-space targets in dynamical systems
https://github.com/gszep/BifurcationFit.jl/blob/master/docs/article.pdf
MIT License
27 stars 2 forks source link

kwargs in continuation cause illegal instruction #1

Closed gszep closed 4 years ago

gszep commented 4 years ago

adding any kwarg into Cont.continuation - in the below example verbosity=0

function continuation( f, u₀,p₀ ; kwargs...)

    u₀, _, stable = Cont.newton( u -> f(u,p₀), u₀, Cont.NewtonPar(verbose=false) )
    branch, _, _ = Cont.continuation( f, u₀,p₀,

        ContinuationPar{eltype(u₀),AbstractLinearSolver,EigenSolver}(
            pMin=kwargs[:pMin],pMax=kwargs[:pMax],ds=kwargs[:ds],
            maxSteps=kwargs[:maxSteps]) ; verbosity=0
    )
    return Tracker.data.(u₀), unpack(branch)...
end

crashes julia when running main.jl with the following output

Unreachable reached at 0x7f64eea046ac

signal (4): Illegal instruction
in expression starting at /home/gszep/Documents/code/fold-inference/main.jl:14
#infer#21 at /home/gszep/Documents/code/fold-inference/inference.jl:15
unknown function (ip: 0x7f64eea046eb)
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1842
jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2348
#infer at ./none:0
unknown function (ip: 0x7f64eea044a1)
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1842
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2197
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:323
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:411
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:362 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:773
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:885
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f64e182ba7f)
unknown function (ip: 0xc)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:894
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:764
jl_parse_eval_all at /buildworker/worker/package_linux64/build/src/ast.c:883
include_string at ./loading.jl:1008
include_string at /home/gszep/.julia/packages/CodeTools/xGemk/src/eval.jl:30
unknown function (ip: 0x7f64eea011f3)
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2197
#127 at /home/gszep/.julia/packages/Atom/X8fAI/src/eval.jl:94
withpath at /home/gszep/.julia/packages/CodeTools/xGemk/src/utils.jl:30
jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2332
withpath at /home/gszep/.julia/packages/Atom/X8fAI/src/eval.jl:47 [inlined]
#126 at /home/gszep/.julia/packages/Atom/X8fAI/src/eval.jl:93 [inlined]
with_logstate at ./logging.jl:395
with_logger at ./logging.jl:491 [inlined]
#125 at /home/gszep/.julia/packages/Atom/X8fAI/src/eval.jl:92 [inlined]
hideprompt at /home/gszep/.julia/packages/Atom/X8fAI/src/repl.jl:85
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2197
macro expansion at /home/gszep/.julia/packages/Atom/X8fAI/src/eval.jl:91 [inlined]
macro expansion at /home/gszep/.julia/packages/Media/ItEPc/src/dynamic.jl:24 [inlined]
#124 at /home/gszep/.julia/packages/Atom/X8fAI/src/eval.jl:86
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2197
handlemsg at /home/gszep/.julia/packages/Atom/X8fAI/src/comm.jl:164
unknown function (ip: 0x7f650f29d7ec)
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2197
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1571 [inlined]
jl_f__apply at /buildworker/worker/package_linux64/build/src/builtins.c:556
#19 at ./task.jl:259
unknown function (ip: 0x7f650f2e4ca4)
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2197
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1571 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:572
unknown function (ip: 0xffffffffffffffff)
Allocations: 389195905 (Pool: 389146779; Big: 49126); GC: 724

Julia has exited. Press Enter to start a new session.
rveltz commented 4 years ago

This call

ContinuationPar{eltype(u₀),AbstractLinearSolver,EigenSolver}

is strange. You should never use AbstractLinearSolver, it is used for dispatch. Looking at Newton.jl, I understand why you where mislead.

Something like the following should be favoured:

u₀, _, stable = Cont.newton( u -> f(u,p₀), u₀, Cont.NewtonPar(verbose=false) )
optCont = Cont.ContinuationPar{eltype(u₀),typeof(DefaultLS()), typeof(DefaultEig())}(
            pMin=kwargs[:pMin],pMax=kwargs[:pMax],ds=kwargs[:ds],
            maxSteps=kwargs[:maxSteps])
rveltz commented 4 years ago

It seems they did not implement broadcasting:

u0 = param([-2.0,0.0])
u1 = copy(u0)

All of this fails except the last one:

u0 .= u0 .- u1
axpy!(2,u0,u1)
u0 = u0 .- u1

It comes from the fact that copyto! is not implemented. This is troublesome because typeof(u0) <: AbstractArray and hence, all my BorderedArrays methods will be called, like this one.

So you have to extend minus!(x::TrackedArray, y::TrackedArray) = x = x .- y. However, in newton, the return type of d by the linear solver is not TrackedArray. So I define:

minus!(x::TrackedArray, y) = x = x .- y

Now the code works but newton does not converge. At least it does not error!

rveltz commented 4 years ago

The branch errors because of finiteDifferences. You can either import finiteDifferences and redefine it for TrackedArrays or use the function fdTracked I put on master.