I have a python algorithm that solves ODE. Now I noticed that this code for several different input parameters is extremely slow. Thus, I profiled the code and got the result:
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.004 0.004 429.032 429.032 gnlse.py:153(perform_simulation)
2 0.001 0.000 429.017 214.508 _ode.py:564(integrate)
2 0.000 0.000 429.016 214.508 _ode.py:381(integrate)
2 18.985 9.492 429.016 214.508 _ode.py:1013(run)
52007 22.260 0.000 410.031 0.008 _ode.py:495(_wrap)
52007 188.766 0.004 387.243 0.007 gnlse.py:234(GNLSE_RHS)
208033 1.300 0.000 173.272 0.001 fftpack.py:46(_raw_fft)
104018 18.316 0.000 108.077 0.001 fftpack.py:195(ifft)
104015 0.857 0.000 90.410 0.001 fftpack.py:100(fft)
104015 85.626 0.001 85.626 0.001 {numpy.fft.fftpack_lite.cfftf}
104018 85.607 0.001 85.607 0.001 {numpy.fft.fftpack_lite.cfftb}
29108 25.776 0.001 25.776 0.001 {min}
530887 3.275 0.000 3.275 0.000 {numpy.core.multiarray.array}
104034 2.522 0.000 2.522 0.000 {method 'astype' of 'numpy.ndarray' objects}
What part of the algorithm can be optimized best (what can be answered without a whole code based on cProfile measurements?)? According to the data, I would say that the function GNLSE_RHSwhen the total time spent in this function is the most significant.
This function calls fft-functions (four times each call). Would it be wiser to make them faster instead of improving the algorithm in GNLSE_RHS? Function in question
AT = np.fft.fft( np.multiply( AW , np.exp( simp['linop'] * z)))
IT = np.abs(AT)**2
if simp['raman'] == True:
RS = simp['dt'] * np.fft.fft( np.multiply( np.fft.ifft(IT), simp['RW'] ))
M = np.fft.ifft( np.multiply( AT,( (1-simp['fr'])*IT + simp['fr']*RS ) ) )
else:
M = np.fft.ifft( np.multiply( AT, IT))
return 1.0j * simp['gamma'] * np.multiply( simp['W'], np.multiply( M, np.exp( -simp['linop'] * z)) )
: , , , .. , ?