JuliaDynamics / NetworkDynamics.jl

Julia package for simulating Dynamics on Networks
https://juliadynamics.github.io/NetworkDynamics.jl/dev/
MIT License
128 stars 13 forks source link

Heterogeneous lags for networks with delay #104

Closed lindnemi closed 2 years ago

lindnemi commented 3 years ago

Delays are now implemented by passing the history function to the components. This allows to define several different lags at every network component and to directly control these lags via the parameter tuple p = (vertexp, edgep). Hence, there is no need for the 3-tuple syntax anymore and it is removed from the codebase. This refactor is important, since previously only homogeneous lags were possible.

For fast solving with heterogeneous parameters we rely on efficient interpolations via h(p,t, idxs=idxs). However, due to a bug in the Julia compiler, some type instability occurs and the performance suffers when using the idxs=idxs interface (https://github.com/SciML/DelayDiffEq.jl/issues/218).

For a diffusion on a small complete graph with 10 vertices and with homogeneous lags i observed 10x slower solving than in the previous versions which used a mutating history function h(buffer, p,t), see test/delay_test.jl.

I am hesitant to merge this PR before the bug has been resolved.

lindnemi commented 2 years ago

The history function is now wrapped, such that it always has access to the global parameters and the global index ranges of the corresponding vertices. As a consequence a call to h has now a shorter syntax. A typical component looks like:

function delay_coupling(e, θ_s, θ_d, h_θ_s, h_θ_d, p, t)
    hist = h_θ_s(t - p[1]; idxs=1)
    e[1] = p[2] * sin(hist - θ_d[1])
    return nothing
end

This should provide reasonable support for heterogeneous delays. However due to the interpolation bug mentioned above even medium-sized heterogeneous systems take very long to solve.