Code Monkey home page Code Monkey logo

pydstool's Issues

Uncertainty about hacky module / class name conflicts in __init__

What's the best way to deal with PyDSTool/init.py's

from . import Generator as GenModule
from .Generator import Generator as Generator_
from .Generator import *
Generator = GenModule
from . import Model as ModelModule
from .Model import Model as Model_
from .Model import *
Model = ModelModule

Remove or update 'fixedpickle' module and dependency

A 2006-era python built-in 'pickle' serializer module was patched to allow pickling of IEE754 special values NaN and Inf on Win32 when cpickle was not available (original could not load these correctly on Win32 platforms).

http://bytes.com/topic/python/answers/501305-numerics-nans-ieee-754-c99

Not sure what the status of this issue is now, but it doesn't seem to have been fixed. However, the provided module is out of date and can crash on some platforms. It should either be extracted and all 'fixedpickle' use should revert to default 'pickle', or load_float method's patch (approx line 981) applied to a recent version of 'pickle'.

Replace output redirector

Current output redirector (see PyDSTool.Redirector class) has several issues:

  • must be manually started/stopped
  • does not properly handle exceptions, which raise between start and stop calls
  • hardcoded to use temporary files, which are deleted when redirector is stopped

So suggestion is to replace current redirector with the one, which support context manager API (this will fix first two issues) and optionally support different targets for redirection. Something, like in this recipe.

[PyCont] No method to delete (rather than reset) a curve in a PyCont Objects

Dear all,
I could not find any method to delete a previously computed curve rather than reset (yet keeping it) in a PyCont object.

Sometimes one would like to try to compute just some branches but then see that those branches were not informative or were included in other brances yet computed from a different initial point.
Yet once created in a PyCont object, a curve seems not to be removable any more. The outcome is a that in some cases, for complex bifurcation diagrams, one may end up with a lot of curves, of which however only a few are the one that really matter. Hence it would be nice to keep the PyContObject.curves list clean.

Thanks for your consideration of the matter.
Maurizio

ContClass.newcurve not overtaking all parameters values when giving a curve point as initpoint

When creating a new curve, if the user specify the initial point using the reference of a point on an existing curve, only the value of the state variables and the one of the free parameters would be taken over.

For example, gen is a generator instance of a dynamical system having var1, var2 as state variables and a and b as parameters:

# Initialize the parameters value for the generator
gen.set(pars={'a':0, 'b' : 0}

# Instanciate ContClass for this generator
PyCont = dst.ContClass(gen)

PCargs = dst.args(name='EQ1', type='EP-C')
PCargs.freepars = ['a']     # Parameter to vary for the continuation
initPointEQ1 = { 'var1': 0, 'var2': 1, 'a': 1, 'b': 2}
PCargs.initpoint = initPointEQ1
PyCont.newCurve(PCargs)
PyCont['EQ1'].forward()

# Let's say EQ1 found an Andronov-Hopf bifurcation EQ1:H1, and I want to start a limit cycle curve from this point

PCargs.name = 'LC1'
PCargs.type = 'LC-C'
PCargs.initpoint = 'EQ1:H1'
PyCont.newCurve(PCargs)

# The following line fails since the value of the parameter "b" used in the curve EQ1 was not taken over, i.e. b is equal to 0 and not 1
PyCont['LC1'].forward()

The problem comes from ContClass.py l. 161.
When the user specify the initial point using the reference of an existing bifurcation point, the point on the curve is selected and given farther in the initializiation but this point contains only the value of the state variables and the bifurcation parameters. It does not contains the value of the static parameters for the curve.

Use of SymPy when available (instead of Symbolic classes)

If SymPy is installed, it would be nice to provide a transparent way to use its symbolic object classes instead of those in the present Symbolic module. Maybe a thin wrapper to ensure one API for the user? There may be some Symbolic module features used that are not supported in SymPy, and this will need to be explored carefully.

Phaseplane toolbox variable naming expectations

find_fixedpoints() function expects '_'-based (FuncSpec-compatible) hierarchical variable and parameter names (e.g. 'mymodule_element1_x' instead of 'mymodule.element1.x') from ModelSpec model building. However, find_nullclines() works with the user-friendly '.' syntax. Both should transparently support the '.' version.

Sync versions everywhere

There is little divergence in mentioned PyDSTool versions:

So I suggest add 0.90.1 tag in repo on proper revision, upload new release on PyPi and update version on homepage.

swig issues on win32

Hi,

I installed the latest revision of PyDSTool from git (153421f), and while running the examples, I get a number of errors apparently related to swig. Is there something I need to do based on my naïve installation of swig on win32 (unzipping the swig binaries and changing my path to include the unzipped directory)?

Thanks.

$ python .\run_all_tests.py
...
Summary:
Basic PyDSTool functions: appears to work on your system
Map related modules: appears to work on your system
VODE related modules: appears to work on your system
Symbolic differentiation module: appears to work on your syste
Parameter estimation module: appears to work on your system
PyCont: appears to be broken on your system
Dopri ODE systems: appears to be broken on your system
Radau ODE systems: appears to be broken on your system
Parameter estimation module with external compilers: appears t
PyCont interface to AUTO: appears to be broken on your system
$ swig
Must specify an input file. Use -help for available options.
$ python PyCont_vanDerPol.py
At end of testing you can delete the temp file vanderPol.dat
Must specify an input file. Use -help for available options.
error: command 'C:\\Program Files\\swig\\swig.exe' failed with exit status 1
$ python
Python 2.7.8 |Anaconda 2.1.0 (32-bit)| (default, Jul  2 2014, 15:13:35) [MSC v.1500 32 bit (Intel)] on win32

PyCont not being pickable

When attempting to save PyCont (ContClass) objects, method saveObject gives error:

Example:
(import PyDSTool as dst)
DSargs - ode system;
ode - generator
traj - trajectory
pts - some points
PC - ContClass object

$ dst.saveObjects([DSargs,ode,traj,pts,PC],'chain3.sav',force=True)

Error:

TypeError Traceback (most recent call last)
dst.saveObjects([DSargs,ode,traj,pts,PC],'chain3.sav',force=True)
/home/maurizio/Downloads/PyDSTool/utils.pyc in saveObjects(objlist, filename, force)
628 for obj in objlist:
629 try:
--> 630 pickle.dump(obj, pklfile, opt)
631 except:
632 if hasattr(obj, 'name'):

TypeError: expected string or Unicode object, NoneType found

Failed to save object 'ContClass of model chain3'


If I leave out the PC object from my list instead, everything seem to work fine.

PyCont examples are broken

After PyCont update (commit 42b8acd) these PyCont examples are broken:

  • PyCont_Catalytic.py
  • PyCont_DiscPredPrey.py
  • PyCont_Hopfield.py
  • PyCont_Logistic.py
  • PyCont_MorrisLecar_TypeI.py
  • PyCont_MorrisLecar_TypeII.py
  • PyCont_LPNeuron.py
  • PyCont_HindmarshRose.py
  • PyCont_ABReaction.py
  • PyCont_Hamiltonian.py
  • PyCont_Lorenz.py
  • PyCont_vanDerPol.py

Remove API docs from the repo

They bloat repository size and tarballs of releases. And in current state they have dubious value.

Instead, I suggest to place them somewhere on project homepage like scipy/numpy projects do.

Inefficient memory usage

While preparing data to be returned to Python, function PackOut (PyDSTool/integrator/interface.c) makes a copy of all computed data and doubles amount of used memory as a result.

EvMapping: broken comparison

EvMapping object from PyDSTool/ModelTools.py defines __cmp__ method. This method returns True or False. That contradicts to Python 2 demands (Python 2 data model - method must return integer, and 0 means 'eqaulity'). As a result, 'equality' and 'inequality' of EvMapping objects are reverted: when __cmp__ returns False, this means 'objects are equal' (int(False) == 0).

Replacing __cmp__ with rich comparison operators (a must for Python 3, see patch below) leads to 'RuntimeError' in _applyStateMap method of HybridModel object (Model.py, lines 2205-2207) both on Python 2 and Python 3. To get error, apply patch

diff --git a/PyDSTool/ModelTools.py b/PyDSTool/ModelTools.py
index b74102c..312809b 100755
--- a/PyDSTool/ModelTools.py
+++ b/PyDSTool/ModelTools.py
@@ -1536,7 +1536,7 @@ class EvMapping(object):
         self.makeCallFn()


-    def __cmp__(self, other):
+    def __eq__(self, other):
         try:
             return alltrue([self.assignDict==other.assignDict,
                             self.defString==other.defString,
@@ -1544,6 +1544,11 @@ class EvMapping(object):
         except AttributeError:
             return False

+    def __ne__(self, other):
+        return not self == other
+
+    __hash__ = None
+
     def makeCallFn(self):
         """Note that the function created alters xdict, pdict, idict, and estruct
         *in place*, and does not return any values.

and run 'examples/IF_delaynet_syn.py'.

So either 'equatlity' checking in EvMapping, or check in _applyStateMap (or both) shoud be adjusted.

[PyCont] Setting of NumCollocation > 7 freezes kernel

Dear all,
not sure it is a bug or I am doing something wrong. But while trying to play a bit with the parameters for LC-C curves, as soon as I changed the default NumCollocation=4 to some other number >4, the kernel of my ipython notebook froze and had to restart it.

M

[PyCont] Point Number is reset when starting curve from that point

Special points detected and labelled on some computed curve in an orderly fashion, when used to initialize a new curve, have their number reset to 1 leading to some confusion.

Example:
Assuming that I have computed an EP-C curve 'EQ1' and I found on this curve two branching points BP1 and BP2 from where I would like to run a further continuation EP-C 'EQ2':

PCargs = args(name='EQ2',type='EP-C',force=True)
PCargs.initpoint = 'EQ1:BP2'
...
...
PC.newCurve(PCargs)
PC['EQ2'].forward()

Then:
PC.display([bif_par,var],figure='fig1',stability=True)

shows me the original EQ1:BP2 as EQ2:BP1.
Quite confusing.
Perhaps, it shall just keep the point name 'BP2'.

Maurizio

[PyCont] Ability to continue from MX points

It would be nice to use the point previous and continue from there once numerical parameters have been adjusted. This is tricky with LC-C, however, as AUTO doesn't necessarily store the cycle information.

Memory leak in Dopri/Radau

While preparing events' data to be returned to Python, code allocates memory for temporary arrays but does not free it (excerpt from PackOut function in PyDSTool/integrator/interface.c):

  /* Only allocate memory for events if something was caught */
  if( numEvents > 0 ) {
    /* Allocate separate arrays for each event */
    EventPointsOutArray = PyMem_Malloc(sizeof(PyObject *) * numEvents);
    assert(EventPointsOutArray);
    EventTimesOutArray = PyMem_Malloc(sizeof(PyObject *) * numEvents);
    assert(EventTimesOutArray);
    ...

Incorporation of logger

PyDSTool should use a logger to note internal warnings and information going to stdout rather than plain print statements. Logging options will help with recording provenance of model development / usage.

Performance on stiff system

Hi,
I have recently started using PyDSTools, I have been using matplotlib and AUTO for a while, I would like to complete cut out matlab but at the moment PyDSTool is really slow compared to matlabs ODE solvers. I was wondering if someone can give me advice on how to speed things up.

I have a 6D stiff ODE system and I am using the VODE integrator. I do have a lot of parameters (~40) and auxiliary functions. Parameters and auxiliary functions are supplied by dictionairies.

For testing purposes my time domain is t=[0,5]. Matlab integrates this with given initial conditions in a fraction of a second.
My VODE integrator takes either ~47 seconds or ~80 seconds if I explicitly set the stiff option. It seems to me that matlab has a good adaptive time step algorithm where the VODE integrator has a fixed time step?

I tried using either Radau or Dopri C integrators but they are both not working on my system.
I currently use numpy 1.8, as numarray disappeared in numpy 1.9. and python 2.7.

Does anyone have ideas how to get comparable integration times?
Or are there any news on release of an update with Dopri and Radau support?

Cheers

Sebooo

Allow PySCes_SBML to accept a file object

I'm working through the PyDSTool tutorials right now, and I'm very impressed! This is a great tool!

One thing that I tried to do and failed was to use a StringIO object instead of a file path to load an SBML file. I'm working in the IPython notebook, and I wanted everything to be in the same place, rather than having several files.

Here's my script:

import StringIO
from PyDSTool.Toolbox import PySCes_SBML

test_branch1 = StringIO.StringIO("""
# PySCeS test input file
# Branched pathway (2004)
FIX: x0 x5 x6
R0:
    x0 = s1
    Vf0*(x0 - s1/Keq0)/(x0 + KS0*(1 + s1/KP0))
R1:
    s1 = s2
    Vf1*(s1 - s2/Keq1)/(s1 + KS1*(1 + s2/KP1))
R2:
    s2 = s3
    Vf2*(s2 - s3/Keq2)/(s2 + KS2*(1 + s3/KP2))
R3:
    s2 = s4
    Vf3*(s2 - s4/Keq3)/(s2 + KS3*(1 + s4/KP3))
R4:
    s3 = x5
    Vf4*(s3 - x5/Keq4)/(s3 + KS4*(1 + x5/KP4))
R5:
    s4 = x6
    Vf5*(s4 - x6/Keq5)/(s4 + KS5*(1 + x6/KP5))

# InitExt
x0 = 10.0
x5 = 1.0
x6 = 1.0

# InitPar
Vf0 = 10.0
Vf1 = 10.0
Vf2 = 10.0
Vf3 = 10.0
Vf4 = 10.0
Vf5 = 10.0

Keq0 = 10.0
Keq1 = 10.0
Keq2 = 10.0
Keq3 = 10.0
Keq4 = 10.0
Keq5 = 10.0

KS0 = 5.0
KS1 = 5.0
KS2 = 5.0
KS3 = 5.0
KS4 = 5.0
KS5 = 5.0

KP0 = 1.0
KP1 = 1.0
KP2 = 1.0
KP3 = 1.0
KP4 = 1.0
KP5 = 1.0

# InitVar
s1 = 1.0
s2 = 1.0
s3 = 1.0
s4 = 1.0
""")
gen = PySCes_SBML.get_pysces_model(test_branch1, 'Vode')

This fails with the following traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-5-c5a452db018d> in <module>()
     66 """)
     67 
---> 68 gen = PySCes_SBML.get_pysces_model(test_branch1, 'Vode')
     69 gen.set(tdata=[0, 10])
     70 gen.set(algparams={'init_step': 0.03})

/home/tbekolay/.virtualenvs/jneuro/lib/python2.7/site-packages/PyDSTool/Toolbox/PySCes_SBML.pyc in get_pysces_model(filename, target)
     77 
     78 def get_pysces_model(filename, target='Vode'):
---> 79     path, fname = os.path.split(filename)
     80     m = pysces.model(fname, dir=path)
     81 

/home/tbekolay/.virtualenvs/jneuro/lib/python2.7/posixpath.pyc in split(p)
     90     """Split a pathname.  Returns tuple "(head, tail)" where "tail" is
     91     everything after the final slash.  Either part may be empty."""
---> 92     i = p.rfind('/') + 1
     93     head, tail = p[:i], p[i:]
     94     if head and head != '/'*len(head):

AttributeError: StringIO instance has no attribute 'rfind'

Basically indicating that get_pysces_model expects a path instead of a file object. It seems like a common way to do this is to allow the function to accept either, and if it's passed in a path (or string-like) it loads it, otherwise it just uses the file object. I'm not sure if this is a PySCes limitation though.

[PyCont] Implement neutral saddle points

Add an NS (Neutral Saddle) "bifurcation" type to equilibrium point curves. Change continuation of "Hopf" curves so that Hopf and NS are in different shades of blue (or NS dotted line).

Phaseplane toolbox - multiple branches of nullclines not supported & buggy

Presently, the user must micro-manage the computation of nullclines. The find_nullclines() function will only find one branch of a nullcline at a time, regardless of search/starting point resolution parameter n and size of domain. In fact, the function can get confused if starting points converge to different branches and then it may complain about points being "out of order".

"UnsupportedOperation: fileno" or similar with Dopri/Radau's use of RedirectStdout

It seems that the RedirectStdout call in Generator/mixins.py does not always function as intended. On both Python 2.7 and 3.4, there have been reports of an error (on IDLE with OS X and Anaconda/iPythonQT on Windows) much like this:

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyDSTool-0.90.0-py2.7.egg/PyDSTool/Generator/Dopri_ODEsystem.py", line 370, in __init__
    self.makeLib()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyDSTool-0.90.0-py2.7.egg/PyDSTool/Generator/mixins.py", line 102, in makeLib
    self.compileLib(libsources, libdirs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyDSTool-0.90.0-py2.7.egg/PyDSTool/Generator/mixins.py", line 82, in compileLib
    self._builder.build(libsources, libdirs, self._compiler)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyDSTool-0.90.0-py2.7.egg/PyDSTool/Generator/mixins.py", line 186, in build
    with RedirectStdout(os.path.join(self.tempdir, 'build.log')):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PyDSTool-0.90.0-py2.7.egg/PyDSTool/core/context_managers.py", line 29, in _stdchannel_redirected
    oldstdchannel = os.dup(stdchannel.fileno())
UnsupportedOperation: fileno

It's not very informative feedback from the python system/terminal, but after some research it appears that the stdout stream may not be defined for some terminals, e.g.:

http://code.activestate.com/lists/python-list/676123/
http://www.tagwith.com/question_1366929_python-3-4-accessing-stdout

@z2v What should the fix be? Should we trap the error raised, or is there a more intelligent check we can make before trying to redirect? Alas, I cannot reproduce this error on my own system so I can't test a solution myself. It may be that, for systems where this exception is raised, there is no need to try to redirect any output, as the output may already be invisible.

Complex variable support?

More than an issue this is a question. Is complex variable support planned? I ask because the systems I'm working with are kind of hard to decouple into real/imaginary or magnitude/phase representations.

Radau and Dopri integrators will not compile if the current path contains white space

Hi,

I just had a hard time running the "PyCont_Catalytic_demo.py" and "PyCont_LPNeuron.py" demo script. I got an error during the compilation of the integrators.

It turns out that I was running IPython from a path containing a white space "/home//test python". If I run the same scripts from a path without white space "/home//test_python" everything works fine.

This is not a major bug, but I though it could be useful to document it, to help other users saving time..

BTW, I'm running Ubuntu 64bits 13.04 and Python 2.7

Cheers,
Florian

C code generator doesn't convert powers properly

If varspecs uses powers in defenition like

varspecs = {'x': 'y', 'y': '-d*y - (x**3) + (x**4)'}

building Radau generator fails with compilation error:

...
gcc: /home/vovka/projects/science/PyDSTool/radau5_temp/TEST_vf.c
/home/vovka/projects/science/PyDSTool/radau5_temp/TEST_vf.c: In function ‘vfieldfunc’:
/home/vovka/projects/science/PyDSTool/radau5_temp/TEST_vf.c:75:17: error: invalid type argument of unary ‘*’ (have ‘int
 f_[1] = -d*y-(x**3)+(x**4);
                 ^
/home/vovka/projects/science/PyDSTool/radau5_temp/TEST_vf.c:75:24: error: invalid type argument of unary ‘*’ (have ‘int
 f_[1] = -d*y-(x**3)+(x**4);
                        ^
/home/vovka/projects/science/PyDSTool/radau5_temp/TEST_vf.c: In function ‘vfieldfunc’:
/home/vovka/projects/science/PyDSTool/radau5_temp/TEST_vf.c:75:17: error: invalid type argument of unary ‘*’ (have ‘int
 f_[1] = -d*y-(x**3)+(x**4);
                 ^
/home/vovka/projects/science/PyDSTool/radau5_temp/TEST_vf.c:75:24: error: invalid type argument of unary ‘*’ (have ‘int
 f_[1] = -d*y-(x**3)+(x**4);

Pointed by Brian M on PyDSTool forum.

'examples/sloppycell_example.py' is broken

'examples/sloppycell_example.py' is broken as a result of commit 9fcb090.

Traceback:

Traceback (most recent call last):
File "sloppycell_example.py", line 323, in
algParams=algparams, silent=True)
File "/home/vovka/projects/science/PyDSTool/PyDSTool/Toolbox/makeSloppyModel.py", line 163, in makeSloppyModel
evmap = makeEvMapping(mappingDict, varnames+auxvarnames, parnames)
File "/home/vovka/projects/science/PyDSTool/PyDSTool/ModelTools.py", line 1600, in makeEvMapping
raise NotImplementedError("Use EvMapping directly now with infodict argument of 'vars' and 'pars' keys")
NotImplementedError: Use EvMapping directly now with infodict argument of 'vars' and 'pars' keys

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.