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

DimensionError with unitful dt for stochastic integrator #529

Open
jebej opened this issue Mar 27, 2023 · 4 comments
Open

DimensionError with unitful dt for stochastic integrator #529

jebej opened this issue Mar 27, 2023 · 4 comments

Comments

@jebej
Copy link
Contributor

jebej commented Mar 27, 2023

Currently the type for the sqdt parameter of SDEIntegrator is tType, which is the same as the type for dt.

This line thus fails with a DimensionError if dt is eg in ns during __init, since the calculated unit for sqdt will be sqrt(ns):

integrator.sqdt = integrator.tdir*sqrt(abs(integrator.dt))

@ChrisRackauckas
Copy link
Member

The random values should have a sqrt(dt) factor for this to work.

@jebej
Copy link
Contributor Author

jebej commented Mar 30, 2023

I'm sorry, I can't see where the random values affect this issue. Is it not simply a question of changing the type parameter?

@jebej
Copy link
Contributor Author

jebej commented Mar 30, 2023

FWIW this is the example:

using Unitful, OrdinaryDiffEq, StochasticDiffEq
using Unitful: uconvert, GHz, J, ns
ℎ = Unitful.h # Plank constant

jj2!(ϕ′,ϕ,(M,η,Ej,i),t) = (Ej*i - Ej*sin(ϕ))/M # BAOAB version
identity_f(v,u,p,t) = v # needed to form second order dynamical ODE
g(u,p,t) = 1.0
setup_noisy_jj(M,η,Ej,i,ϕ_init=0.0,ϕ′_init=0.0/ns,tspan=(0ns,1ns)) =
    DynamicalSDEProblem{false}(jj2!,identity_f,g,ϕ′_init,ϕ_init,tspan,(M,η,Ej,i))

# underdamped
M = 4.2E-28*J*ns^2
η = 1.1E-26*J*ns
Ej =* 50GHz
i = 0.0 # unitless

prob = setup_noisy_jj(M,η,Ej,i,0.5)
res = solve(prob,BAOAB/M, false),dt=0.001ns)

@ChrisRackauckas
Copy link
Member

without the randomness having the appropriate sqrt(t) units, you will later just get a type error that sqrt(t) + t units are combined. We can definitely expand that type signature but I don't think it's enough to get around that.

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