Skip to main content

Dynamical systems simulation in python

Trying out PyDSTools [webpage, download]
These guys look professional - they have a test suite that you can run to check everything out.
Issues:
  1. You need to put a file called PyDSTool.pth [read this]
    Play close attention to the trick about subdirectories - you have to repeat it for each level, not just the root level. I have my install in c:\programs\PyDSTool and my file has
    C:\\
    C:\\Programs\\
    C:\\Programs\\PyDSTool\\
  2. I have scipy version 0.6.0 but PyDSTool doesn't detect that properly. I commented out the relevant lines in PyDSTool's root __init__.py
    #if vernums[1] != 5:
    # raise RuntimeError("SciPy v0.5.1 or above is required")

    and it continued with the tests.
Things seem to work OK, only one thing was declared broken:
PyCont: appears to be broken on your system

But, there were periodic errors of the nature:

***** Testing script impfn_test.py ****************************

Gnuplot not available
------- Examples of implicit function as variable
1D example: a half-circle using newton's method (secant method for estimating de
rivative)
Change sign of 'y' initial condition to solve for other half-circle
Gen defined? => False
traj1 = testimp.compute('traj1')
Error in supplied functional specification code
Traceback (most recent call last):
File "impfn_test.py", line 54, in
traj1 = testimp.compute('traj1')
File "C:\Programs\PyDSTool\Generator\ImplicitFnGen.py", line 294, in compute
exec tempspec[0] in globals()
File "string", line 1
def _specfn_imptest_316e-006(ds, t, x, parsinps):
^
SyntaxError: invalid syntax

***** Testing passed on test file impfn_test.py


Which I can't understand

Comments

  1. Hi -- that's an odd platform specific problem you have with time.clock(). The easy fix is to change the return line in the function PyDSTool.common.timestamp to be the following:

    return c.replace(".","").replace("-","")[:tdigits+1]

    (obviously without the newline that this comment box forces on me!)

    ReplyDelete

Post a Comment

Popular posts from this blog

A note on Python's __exit__() and errors

Python's context managers are a very neat way of handling code that needs a teardown once you are done. Python objects have do have a destructor method ( __del__ ) called right before the last instance of the object is about to be destroyed. You can do a teardown there. However there is a lot of fine print to the __del__ method. A cleaner way of doing tear-downs is through Python's context manager , manifested as the with keyword. class CrushMe: def __init__(self): self.f = open('test.txt', 'w') def foo(self, a, b): self.f.write(str(a - b)) def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): self.f.close() return True with CrushMe() as c: c.foo(2, 3) One thing that is important, and that got me just now, is error handling. I made the mistake of ignoring all those 'junk' arguments ( exc_type, exc_val, exc_tb ). I just skimmed the docs and what popped out is that you need to return True or

Store numpy arrays in sqlite

Use numpy.getbuffer (or sqlite3.Binary ) in combination with numpy.frombuffer to lug numpy data in and out of the sqlite3 database: import sqlite3, numpy r1d = numpy.random.randn(10) con = sqlite3.connect(':memory:') con.execute("CREATE TABLE eye(id INTEGER PRIMARY KEY, desc TEXT, data BLOB)") con.execute("INSERT INTO eye(desc,data) VALUES(?,?)", ("1d", sqlite3.Binary(r1d))) con.execute("INSERT INTO eye(desc,data) VALUES(?,?)", ("1d", numpy.getbuffer(r1d))) res = con.execute("SELECT * FROM eye").fetchall() con.close() #res -> #[(1, u'1d', <read-write buffer ptr 0x10371b220, size 80 at 0x10371b1e0>), # (2, u'1d', <read-write buffer ptr 0x10371b190, size 80 at 0x10371b150>)] print r1d - numpy.frombuffer(res[0][2]) #->[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] print r1d - numpy.frombuffer(res[1][2]) #->[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] Note that for work where data ty