# Delay Differential Equations Networks with different delay per edge

**URL:** <https://discourse.julialang.org/t/delay-differential-equations-networks-with-different-delay-per-edge/69787>\
**Category:** Modelling & Simulations\
**Tags:** diffeq, performance\
**Created:** [October 14, 2021, 10:41pm UTC](https://discourse.julialang.org/t/delay-differential-equations-networks-with-different-delay-per-edge/69787 "2021-10-14T22:41:49Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [October 15, 2021, 2:00pm UTC](https://discourse.julialang.org/t/delay-differential-equations-networks-with-different-delay-per-edge/69787/6 "2021-10-15T14:00:29Z")

</div>

`solve(prob, MethodOfSteps(BS3()), saveat=0.01, reltol=0, abstol=1e-5)`. `rtol` and `atol` are not options, and you should almost never `force_dtmin`. I should really just remove that argument. If you’re hitting it, then your definition is probably wrong: the warning even says to think of dtmin as divergence for a reason described in [PSA: How to help yourself debug differential equation solving issues](https://discourse.julialang.org/t/psa-how-to-help-yourself-debug-differential-equation-solving-issues/62489) .

And so the first thing is to notice is that these are not the same DDE being solved. In fact, the Julia one isn’t even a DDE: it’s not even a well-defined equation!

```julia
h(p, t; idxs=nothing) = typeof(idxs) <: Number ? 1.0 : rand(Uniform(0, 2π), n)

```

The past does not have a value: every single time the past is called the value changes. So what’s happening is that the starting iterations are unable to converge because there is no sense of convergence: there are no values!

But it’s even worse then that: you’re saying that "the u(t) for t\<0 is a random value at every `t`, but `u(t)[1] = 1.0` for any past value. So that’s even worse, it’s not even consistent 😱. And `u(t)[1] = 1.0` does not match what is in the Python code which uses a uniform random value for the past.

The fixed code is:

```julia
using DelayDiffEq
using Distributions
using Random

function f!(dθ, θ, h, p, t)
    ω, A = p
    n = length(θ)
    lags = reshape(lag, n,n)
    @inbounds for j in 1:n
        coupling = 0.0
        @inbounds for i in 1:n
            coupling += A[i,j]*sin(h(p, t-lags[i,j]; idxs=i) - θ[j])
        end
        dθ[j] = ω[j] + coupling
    end
    nothing
end

n = 10
Random.seed!(1)
ω = rand(n)
A = rand(n,n)
const lag = rand(n*n)
θ₀ = rand(Uniform(0, 2π), n)
p = (ω, A)
const past = rand(Uniform(0, 2π), n)
h(p, t; idxs=nothing) = typeof(idxs) <: Number ? past[idxs] : past

prob = DDEProblem(f!, θ₀, h, (0.0, 1.0), p, constant_lags=lag)

using Profile
@profile solve(prob, MethodOfSteps(BS3()), saveat=0.01, reltol=0, abstol=1e-5)
Juno.profiler()

```

After fixing that it’s still slow though. The issue seems to be that Julia’s inference is bugging in `f!`. This could be [https://github.com/JuliaLang/julia/issues/35800](https://github.com/JuliaLang/julia/issues/35800) or [https://github.com/SciML/OrdinaryDiffEq.jl/pull/1473](https://github.com/SciML/OrdinaryDiffEq.jl/pull/1473)

---

_[View the full topic](https://discourse.julialang.org/t/delay-differential-equations-networks-with-different-delay-per-edge/69787)._
