简体   繁体   中英

Python script taking over 20 hours to run

I have a system of 16 coupled differential equations and I'm using the Scipy.integrate.odeint package.

The code has to run from 0 to 5 gigayears and then plots the data, the nature of the differential equations is that they are extremely oscillatory. On top of that the timestep I have used is 1e+8 or I get this constant error:

'Excess work done on this call (perhaps wrong Dfun type). Run with full_output = 1 to get quantitative information.'

I'm just wondering, is there any other method I can take to make my integrator solve faster? Are there any better integration methods for large systems of coupled ODEs? The code has been running for over 20 hours now to no avail.

  • For most large systems of differential equations the main bottleneck is usually computing the derivative (the right-hand side). You probably do this purely in Python, which makes it much slower than it could be. I wrote a Python module called JiTCODE that speeds up the integration by hard-coding the derivative and that is particularly intended for large systems of ODEs.

  • Also note that odeint uses LSODA which is not the most efficient method for non-stiff systems.

  • The error you are getting is usually raised if the number of integration steps exceeds a certain threshold. For a long integration, this may be expected. You can control this by adjusting the parameter mxstep .

  • odeint also has a maximum step size parameter that is automatically chosen in a manner I do not know. While this seems to reasonably scale with your time scale in a quick test, I cannot exclude that it doesn't handle working with gigayears in SI units well in your case, which may cause absurdly many steps.

  • Given that you work with gigayears (which hints at an astronomy, which in turn makes energy conservation likely), you should also check whether a symplectic integrator is more appropriate for your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM