Giter VIP home page Giter VIP logo

Comments (3)

Datseris avatar Datseris commented on September 20, 2024

From @SebastianM-C on October 2, 2017 22:54

I implemented the naive way using pmap in order to reduce the time by parallelization.
I used a the following wrapper around lyapunov in order to work directly on ODEProblems

function compute_lyapunov(prob::ODEProblem; d0=1e-9, threshold=10^4*d0, dt = 0.1,
    diff_eq_kwargs = Dict(:abstol=>d0, :reltol=>d0))

    threshold <= d0 && throw(ArgumentError("Threshold must be bigger than d0!"))

    if haskey(diff_eq_kwargs, :solver)
        solver = diff_eq_kwargs[:solver]
    else
        println("Using DPRKN12 as default solver")
        solver = DPRKN12()
    end
    # Initialize
    st1 = prob.u0
    integ1 = init(prob, solver; diff_eq_kwargs..., save_first=false, save_everystep=false)
    integ1.opts.advance_to_tstop = true
    prob.u0 = st1 .+ d0
    integ2 = init(prob, solver; diff_eq_kwargs..., save_first=false, save_everystep=false)
    integ2.opts.advance_to_tstop = true
    prob.u0 = st1
    lyapunov(integ1, integ2, prob.tspan[2]; d0=d0, threshold=threshold, dt=dt)
end

Then I use the following function for the parallel λ computations

function compute_λs(q0list, p0list, tmax, d0, dt, tr, kwargs, prefix)
    n = size(q0list, 1)    # number of initial conditions
    λs = SharedArray{Float64}(n)
    pmap(i->(prob = defProb(q0list[i,:], p0list[i,:], (0., tmax));
            λs[i] = compute_lyapunov(prob, d0=d0, dt=dt, threshold=tr,
                                    diff_eq_kwargs=kwargs)),
        Progress(n),
        1:n)

    save("$prefix/lyapunov.jld", "λs", λs, "d0", d0, "dt", dt, "tr", tr,
        "tmax", tmax, "n", n);
    return λs
end

in a function like this

addprocs(4);
using JLD
using ArgParse
using Plots, LaTeXStrings
using ProgressMeter
using PmapProgressMeter
@everywhere begin
    using OrdinaryDiffEq, DiffEqCallbacks
    using ParallelDataTransfer
end
function main()
    # Hamiltonian parameters
    A, B, D = readdlm("param.dat")
    E_list, tmax, d0, dt, tr, solver, kwargs, defProb = input_param()
    # Broadcast parameters to all workers
    sendto(workers(), A=A, B=B, D=D, defProb=defProb)

    for E in E_list
        sendto(workers(), E=E)
        prefix = "../output/B$B D$D E$E"
        if !isdir(prefix)
            mkpath(prefix)
        end
        if isfile("$prefix/z0.jld")
            q0list, p0list = load("$prefix/z0.jld", "q0list", "p0list")
        else
            error("$prefix/z0.jld not found! Generate the initial conditions.")
        end
        λs = compute_λs(q0list, p0list, tmax, d0, dt, tr, kwargs, prefix)
    end
end

where the initial conditions are read from a file.

from chaostools.jl.

Datseris avatar Datseris commented on September 20, 2024

Thanks! There may be better approaches or algorithms I am not aware of, but on the very least your code gives a concrete start for a general parallelized interface in case a different approach is not found!

from chaostools.jl.

Datseris avatar Datseris commented on September 20, 2024

This is implemented as local_growth_rates.

from chaostools.jl.

Related Issues (20)

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.