neurophysik / jitcdde

Just-in-time compilation for delay differential equations
Other
56 stars 14 forks source link

[Docu] Kuramoto example should include `delays` and `max_delay` #40

Closed mwappner closed 2 years ago

mwappner commented 2 years ago

The documentatio for this library encourages the user to give the model builder the delay and max_delay of a system when the system is large to cut down on overhead to the pre-processing times of the model. For this reason, I think the Kuramoto example should include this when defining the model:

I = jitcdde(kuramotos,n=n,verbose=False, max_delay=max(τ), delays=τ)

The line as written above doesn't work, and I'm not sure why; it throws

Traceback (most recent call last):

  File "/home/marcos/Documents/DeltaDimer/untitled5.py", line 30, in <module>
    I = jitcdde(kuramotos,n=n,verbose=False, max_delay=max(τ), delays=τ)

  File "/home/marcos/.local/lib/python3.9/site-packages/jitcdde/_jitcdde.py", line 200, in __init__
    self.delays = delays

  File "/home/marcos/.local/lib/python3.9/site-packages/jitcdde/_jitcdde.py", line 218, in delays
    self._delays.append(0)

AttributeError: 'numpy.ndarray' object has no attribute 'append'

The example should of course include a working version of the line above. Note that on my system adding only the max_delay parameter reduced pre-processing times by 20% (from 1.9 seconds average to around 1.55). I'd expect the addition of delay to make this even faster.

Wrzlprmft commented 2 years ago

Thanks for reporting. There were two issues here:

So, to use this speed-up (without updating) you need to call:

I = jitcdde(kuramotos,n=n,verbose=False, delays=list(τ.flat))

After that, specifying max_delay should not result in a relevant speed-up. Mind that since A and τ are random, they influence the runtime as well, so you should fix random’s seed when benchmarking.

Finally, I also added using the delays parameter to the documentation as suggested. I wouldn’t consider the network large yet and the speed-up is only about 0.3 s on my machine, but it’s not bad to illustrate this.