Coder Social home page Coder Social logo

pydde's Introduction

PyDDE: Python/C DDE solver

This is an updated version of PyDDE: Python/C DDE solver Original code here

This version was fixed for and tested on Ubuntu 14.04 LTS and Mac OSX 10.9


Please see the file INSTALL.txt for information on installing PyDDE.

The file LICENSE.txt for important licensing and warranty information; the file GPL.txt contains the actual license. Your use of PyDDE and its source code is governed by these conditions; if you do not agree with them please uninstall PyDDE and delete the source distribution from your computer.

ABOUT PyDDE

PyDDE is an open source numerical solver for systems of delay differential equations (DDEs), implemented as a Python package and written in both Python and C. It is built around the numerical routines of the R package ddesolve, which is itself based on Simon Wood's Solv95, a DDE solver for Microsoft Windows systems written in C.

RELEASE NOTES

0.2.2_2to3 - 21 December 2011

-- Patched 0.2.2 for python3 (patch via renato)

0.2.2 - 07 December 2008

-- Fixed a bug that resulted in failure to compile on some Mac OS X systems. (Thanks to Josh Lippai who reported the bug and coded the fix.) -- Various minor typographical corrections to the code and manual.

0.2.1 - 31 October 2007

-- Migrated to use the back-end from the R package 'ddesolve'.

0.1.3 - 25 April 2007

-- Fixed a memory 'leak' due to poor reference handling of Python objects in the C code. Python was keeping a reference to objects that should have been deleted. -- Fixed a segfault when updating or cleaning up the history buffer for models without any history variables. -- Fixed an apparent bug in setup.py. The libraries field doesn't work with some versions of Python. Removing it doesn't seem to hurt, either.

0.1.2 - 23 April 2007

-- Improved memory management by better allocating and freeing the simulated data and history buffer at each dde.solve() call.

0.1.1 - 13 April 2007

-- Fixed a bug whereby a data variable would be defined twice, causing compilation errors on some systems (e.g. OS X with gcc 4.0.1).

0.1.0 - 14 December 2005

-- First release of PyDDE.

pydde's People

Contributors

hensing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pydde's Issues

Segfault due to lack of error handling.

Whenever a grad function raises an exception instead of displaying the python exception this program generates a segfaut (this is an aritificial example I cooked up from a real dde that was segfaulting for the same reason after iteration 100):

from __future__ import division
import numpy as np
import scipy as sp
import time
from scipy.special import binom
from PyDDE import pydde

tau = 40
d0 = 1 / 100
G = 10 ** (-2)
a = 0.8
A = 100
# NB: B * x_0 < ln(2) for boundaries in U_x to be defined
B = 0.06
x_0 = 3
t_delay = 50
ddecons = np.array([tau, d0, G, a, A, B, x_0, t_delay])

# Duration of the simulation:
stoptime = 1000.0
numpoints = 1000
timestep = 1.0 # this is the timesteps on which the output is given
dt = 0.1 # this is the integration timestep of the solver


# Initial Conditions
N0 = 0.01
No0 = 10
N_infty0 = 0
ddeist = np.array([N0, No0, N_infty0])
# Set state-scaling array for use in error control when values are very close to 0
ddestsc = np.array([0,0,0])

#  Create a dde object
dde_eg = pydde.dde()

def ddegrad(s, c, t):
    if int(s[0]) != 1 :
        return np.array([1,1,1])
    raise BaseException()


ts = np.arange(0.0, stoptime, timestep)

dde_eg.dde(y=ddeist, times=ts,
           func=ddegrad, parms=ddecons,
           tol=0.000005, dt=dt, hbsize=3000, nlag=0, ssc=ddestsc)

looking at the source (inside wrapper.c) the missing of the exception seems to take place here (pyarraycheck is not working it seems):

    result = PyEval_CallObject(grad_func,arglist);
    //printf("Got grad_func result.\n");
    assert(result);
    assert(PyArray_Check(result));
    //printf("result = %p\n", result);
    currentdata = dblArray_from_PyArray(result);

Whenever using PyEval_CallObject it is good to check that it does not return NULL. If it returns NULL this means that an exception occurred within grad_func in python and we should EXPLICITLY call the exception (i.e. https://docs.python.org/3.0/extending/extending.html ) otherwise this will most probably lead to a segfault which it does dblArray_from_PyArray is expecting a pyobject sequence and when passing it to numpy to cast to a contiguous array it raises a segfault since it is receiving a NULL object and not a sequence.

This makes it very hard for users to debug what is going on as it my not be obvious why their gradient function is raising an exception since it jumps to a segfault and not the exception message.

Segmentation fault

Hi Henning,

when using PyDDE with more than 10 state variables I get a segmentation fault possibly due to memory problems. Before digging into the problem myself, I was wondering if you are aware of this issue and can offer some quick help.

Best,
Jannis

Modernizing code base

This project deserves to be brought to current python standards. There are still references to Numeric!
I'll try to contribute a pull request when I have a bit of free time.

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.