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

Real noise with complex variables gives compilation errors for some solvers #401

Closed
Krastanov opened this issue Dec 13, 2018 · 2 comments
Closed

Comments

@Krastanov
Copy link

With the following code everything works fine:

W = WienerProcess(0.0,0.0,0.0)
prob = SDEProblem(f,g,ρ₀,tspan,parameters,noise=W);
solution = solve(prob,EM(),dt=dt,saveat=dt_save);

f and g are functions returning 2x2 complex matrices. W is real noise. ρ₀ is a 2x2 complex matrix.

When I remove the choice of solver, and leave it to decide on its own (I have poor understanding of how that choice is made and how I can find the default) I get an error:

W = WienerProcess(0.0,0.0,0.0)
prob = SDEProblem(f,g,ρ₀,tspan,parameters,noise=W);
solution = solve(prob,saveat=dt_save);
dt_save = 1/2^5

solution = solve(prob,saveat=dt_save);

MethodError: no method matching abs(::Array{Complex{Float64},2})
Closest candidates are:
  abs(!Matched::Bool) at bool.jl:91
  abs(!Matched::Float16) at float.jl:517
  abs(!Matched::Float32) at float.jl:518
  ...

Stacktrace:
 [1] perform_step! [...] at /home/stefan/.julia/packages/StochasticDiffEq/1UqR9/src/perform_step/lamba.jl:20
 [2] perform_step! at /home/stefan/.julia/packages/StochasticDiffEq/1UqR9/src/perform_step/lamba.jl:2 [inlined]
 [3] macro expansion at /home/stefan/.julia/packages/StochasticDiffEq/1UqR9/src/integrators/integrator_utils.jl:66 [inlined]
 [4] solve! [...]

Any suggestions on how to contribute to tracking this down?

Running on julia 1.0.0 and DifferentialEquations as added from Pkg.add this week.

@ChrisRackauckas
Copy link
Member

The first thing to do would be to dig in and find out what algorithm is being called here. It's probably just SOSRA, so then we need to dig into the caches and find out what is complex when it shouldn't be in the spot where it's pointing to the error, and if we should use internalnorm instead of abs. Likely, the latter might be all that's required to fix it.

Ref on past work: SciML/StochasticDiffEq.jl#101

@Krastanov
Copy link
Author

After running add DifferentialEquations#master and add StochasticDiffEq#master and testing each of the non-stiff solvers (see attached file) I got the following results:

function numerical_sol(solver;kwargs...)
    f(u,p,t) = u
    g(u,p,t) = u
    #u₀=1.0im
    #u₀=[1.0im,2.0im]
    u₀=[1.0im 2.0im; 3.0im 4.0im]
    W = WienerProcess(0.,0.,0.)
    tspan = (0.0,1.0)
    prob = SDEProblem(f,g,u₀,tspan,noise=W)
    solve(prob,solver;kwargs...)
end;

causes the following errors with the following solvers:

MethodError: no method matching abs(::Array{Complex{Float64},1}) in perform_step!

in the two Lamba solvers.

MethodError: no method matching +(::Array{Float64,1}, ::Float64) in mulladd in perform_step!

in SRA, SRA1, and SRA2 (but not in SRA3). This problem seems unrelated to complex numbers?

MethodError: no method matching zero(::Type{Array{Complex{Float64},1}}) in macro expansion in perform_step!

in SRI.

MethodError: no method matching perform_step!

in RKMilCommute. This error happened both for arrays and for scalars and it also seems unrelated to complex numbers?

Disclaimer: I still have poor understanding of the differences between solvers, so I maybe some of those errors are expected to happen? But I did not find that explained in the documentation.

Addressing the Lamba problems

This seems to be the original problem I reported at the start of this issue. I ran a substitution
%s/abs(/integrator.opts.internalnorm(/g which resulted in 8 substitutions on 4 lines of the lamba.jl file. Now these errors do not happen anymore.

Should I be worried that I broke something with this change? As I mentioned, for the moment I have somewhat poor understanding of the code.

SDE_bug_notebook.zip

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

No branches or pull requests

2 participants