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

Leveraging EnsembleProblem for parameter scans #104

Open
thompsonmj opened this issue May 25, 2022 · 5 comments · May be fixed by #142
Open

Leveraging EnsembleProblem for parameter scans #104

thompsonmj opened this issue May 25, 2022 · 5 comments · May be fixed by #142

Comments

@thompsonmj
Copy link
Contributor

In the MOL docs, it discusses how to Remake with different parameter values, but can this be accelerated with EnsembleProblem interface and use parameter design matrices?

@thompsonmj thompsonmj changed the title Leveraging EnsembleProblem Leveraging EnsembleProblem for parameter scans May 25, 2022
@ChrisRackauckas
Copy link
Member

Yes, if you use remake inside of an EnsembleProblem then you can use this all to for example multithread over multiple solves.

@thompsonmj
Copy link
Contributor Author

Huh, it's working, but the ensemble is much slower ...

Using the tutorial problem,

@parameters t x
@parameters Dn, Dp
@variables u(..) v(..)
Dt = Differential(t)
Dx = Differential(x)
Dxx = Differential(x)^2

eqs  = [Dt(u(t,x)) ~ Dn * Dxx(u(t,x)) + u(t,x)*v(t,x), 
        Dt(v(t,x)) ~ Dp * Dxx(v(t,x)) - u(t,x)*v(t,x)]
bcs = [u(0,x) ~ sin(pi*x/2),
       v(0,x) ~ sin(pi*x/2),
       u(t,0) ~ 0.0, Dx(u(t,1)) ~ 0.0,
       v(t,0) ~ 0.0, Dx(v(t,1)) ~ 0.0]

domains = [t ∈ Interval(0.0,1.0),
           x ∈ Interval(0.0,1.0)]

@named pdesys = PDESystem(eqs,bcs,domains,[t,x],[u(t,x),v(t,x)],[Dn=>0.5, Dp=>2])
discretization = MOLFiniteDifference([x=>0.1],t)
prob = discretize(pdesys,discretization) # This gives an ODEProblem since it's time-dependent

N = 10000
lb = [0.01,0.01]
ub = [2.0,2.0]
par = QuasiMonteCarlo.sample(N,lb,ub,LatinHypercubeSample())
sols1 = []
@time begin
for (Dnval, Dpval) in zip(par[1,:], par[2,:])
    newprob = remake(prob, p=[Dnval, Dpval])
    push!(sols1, solve(newprob, Tsit5()))
end
end
# 5.7 s

function prob_func(prob,i,repeat)
    remake(prob,p=par[:,i])
end

ensemble_prob = EnsembleProblem(prob, prob_func=prob_func)
@time begin
sols2 = solve(ensemble_prob, Tsit5(), trajectories=N)
end
# 91.0 s

@ChrisRackauckas
Copy link
Member

Your function solves too fast for parallelism (multithreading) to be beneficial. We may be able to batch that differently.

@thompsonmj
Copy link
Contributor Author

Ah, well it would help too if I started Julia with more than 1 thread.

For my real problem, the Ensemble speeds it up nicely when I start it up right. Could be a helpful tutorial to include!

@ChrisRackauckas
Copy link
Member

haha yes, always need those threads.

thompsonmj added a commit to thompsonmj/MethodOfLines.jl that referenced this issue Jul 23, 2022
@thompsonmj thompsonmj linked a pull request Jul 23, 2022 that will close this issue
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 a pull request may close this issue.

2 participants