[SciPy-user] odeintegrate, speed

Lars Friedrich lfriedri at imtek.de
Wed Apr 25 05:55:37 EDT 2007


Hello,

recently, I successfully used scipy.integrate.odepack.odeint (scipy 
version 0.5.2) to solve a simple ODE. The system function I used is a 
standard python function like

def systemFunction(self, x, t): 
        fThermal = ...
        k = ...
        gamma = ...
        fExternal = externalForce(x)
       
        xDeriv = (fThermal - k * x - fExternal) / gamma
        return xDeriv

where externalForce(x) is another python function.

I have the feeling that the simulation is somewhat "slow", although I 
have no hard timing data available at the moment. I compared it to 
simulations done in Igor (a scientific software from wavemetrics) and 
tried to set the accuracy targets to the same values, and Igor was much 
faster.

I can imagine that my Python code is slow because I use a standard 
python function as the systemFunction. I read that it is possible to 
speed things up using scipy.weave. However, I am not sure if this is the 
right way for me, because I do not have a complicated numpy-expression 
in my systemFunction but rather simple one-number-arithmetic.

Anyway, I did

import scipy.weave
scipy.weave.test

and the result was:


Found 0 tests for scipy.weave.c_spec
  Found 2 tests for scipy.weave.blitz_tools
building extensions here: c:\docume~1\larsfr~1\locals~1\temp\Lars 
Friedrich\python24_compiled\m1
  Found 1 tests for scipy.weave.ext_tools
  Found 74 tests for scipy.weave.size_check
  Found 9 tests for scipy.weave.build_tools
  Found 0 tests for scipy.weave.inline_tools
  Found 1 tests for scipy.weave.ast_tools
  Found 0 tests for scipy.weave.wx_spec
  Found 3 tests for scipy.weave.standard_array_spec
  Found 26 tests for scipy.weave.catalog
  Found 16 tests for scipy.weave.slice_handler
  Found 0 tests for __main__
Traceback (most recent call last):
  File "<input>", line 1, in ?
  File 
"C:\PROGRA~1\Python24\Lib\site-packages\numpy\testing\numpytest.py", 
line 476, in test
    runner.run(all_tests)
  File "C:\Program Files\Python24\lib\unittest.py", line 696, in run
    test(result)
  File "C:\Program Files\Python24\lib\unittest.py", line 428, in __call__
    return self.run(*args, **kwds)
  File "C:\Program Files\Python24\lib\unittest.py", line 424, in run
    test(result)
  File 
"C:\PROGRA~1\Python24\Lib\site-packages\numpy\testing\numpytest.py", 
line 140, in __call__
    unittest.TestCase.__call__(self, result)
  File "C:\Program Files\Python24\lib\unittest.py", line 281, in __call__
    return self.run(*args, **kwds)
  File "C:\Program Files\Python24\lib\unittest.py", line 276, in run
    if ok: result.addSuccess(self)
  File "C:\Program Files\Python24\lib\unittest.py", line 648, in addSuccess
    self.stream.write('.')
  File 
"C:\PROGRA~1\Python24\Lib\site-packages\numpy\testing\numpytest.py", 
line 107, in write
    self.stream.flush()
IOError: [Errno 9] Bad file descriptor


My numpy version is 1.0.1

What is the right way to do a fast ODE simulation with scipy? Shall I 
use weave.inline? Do I need an additional C-compiler then? Or is there 
an easier / better approach?

Thanks for lighting my darkness....

Lars

-- 
Dipl.-Ing. Lars Friedrich
Optical Measurement Technology
Department of Microsystems Engineering -- IMTEK University of Freiburg
Georges-Köhler-Allee 102
D-79110 Freiburg Germany

phone: +49-761-203-7531
fax: +49-761-203-7537
room: 01 088
email: lfriedri at imtek.de




More information about the SciPy-User mailing list