Ticket #1187: ode crashes if rhs returns a tuple instead of a list
![](https://secure.gravatar.com/avatar/b80364cc6fbb2eac7dcfdb7738bae083.jpg?s=120&d=mm&r=g)
I just want to draw attention to the bug report in http://projects.scipy.org/scipy/ticket/1187. Basically, scipy.integrate.ode takes a function as input, and the error occurs if that function returns a tuple (instead of, e.g., a list). If there isn't a simple fix (I can't tell b/c the error occurs within C-code, which I'm not at all proficient in), then I think this should print a more informative error message. Best, -Tony
![](https://secure.gravatar.com/avatar/38d5ac232150013cbf1a4639538204c0.jpg?s=120&d=mm&r=g)
On Wed, Nov 9, 2011 at 4:02 PM, Tony Yu <tsyu80@gmail.com> wrote:
I just want to draw attention to the bug report in http://projects.scipy.org/scipy/ticket/1187. Basically, scipy.integrate.ode takes a function as input, and the error occurs if that function returns a tuple (instead of, e.g., a list).
If there isn't a simple fix (I can't tell b/c the error occurs within C-code, which I'm not at all proficient in), then I think this should print a more informative error message.
Best, -Tony
There are 2 full releases and an release candidate since Scipy 0.7.2 was released (2010-04-22). So, could you please update your numpy and scipy installations accordingly? Works for scipy.10.0.rc1 (last part below) Bruce
while r.successful() and r.t < t1: r.integrate(r.t+dt) print r.t, r.y
array([-0.71+0.237j, 0.40+0.j ]) 1.0 [-0.71+0.237j 0.40+0.j ] array([ 0.191-0.524j, 0.222+0.j ]) 2.0 [ 0.191-0.524j 0.222+0.j ] array([ 0.472+0.527j, 0.154+0.j ]) 3.0 [ 0.472+0.527j 0.154+0.j ] array([-0.619+0.307j, 0.118+0.j ]) 4.0 [-0.619+0.307j 0.118+0.j ] array([ 0.023-0.614j, 0.095+0.j ]) 5.0 [ 0.023-0.614j 0.095+0.j ] array([ 0.586+0.34j, 0.080+0.j ]) 6.0 [ 0.586+0.34j 0.080+0.j ] array([-0.521+0.445j, 0.069+0.j ]) 7.0 [-0.521+0.445j 0.069+0.j ] array([-0.160-0.612j, 0.061+0.j ]) 8.0 [-0.160-0.612j 0.061+0.j ] array([ 0.649+0.15j, 0.054+0.j ]) 9.0 [ 0.649+0.15j 0.054+0.j ] array([-0.384+0.564j, 0.049+0.j ]) 10.0 [-0.384+0.564j 0.049+0.j ]
![](https://secure.gravatar.com/avatar/b0f62d137f9ea1d0b6cc4e7e6f61b119.jpg?s=120&d=mm&r=g)
Bruce, did you change the return values of f and jac to be tuples instead of lists? It crashes when I run it. ticket1187demo.py: ----- import scipy from scipy.integrate import ode print print "scipy version:", scipy.__version__ print y0, t0 = [1.0j, 2.0], 0 def f(t, y, arg1): return (1j*arg1*y[0] + y[1], -arg1*y[1]**2) def jac(t, y, arg1): return ([1j*arg1, 1], [0, -arg1*2*y[1]]) r = ode(f, jac).set_integrator('zvode', method='bdf', with_jacobian=True) r.set_initial_value(y0, t0).set_f_params(2.0).set_jac_params(2.0) t1 = 10 dt = 1 while r.successful() and r.t < t1: r.integrate(r.t+dt) print r.t, r.y ----- Run it: $ python ticket1187demo.py scipy version: 0.11.0.dev-96e39ec 0-th dimension must be 2 but got 0 (not defined). rv_cb_arr is NULL Call-back cb_f_in_zvode__user__routines failed. Traceback (most recent call last): File "ticket1187demo.py", line 23, in <module> r.integrate(r.t+dt) File "/Users/warren/local_scipy/lib/python2.7/site-packages/scipy/integrate/_ode.py", line 333, in integrate self.f_params, self.jac_params) File "/Users/warren/local_scipy/lib/python2.7/site-packages/scipy/integrate/_ode.py", line 760, in run args[5:])) SystemError: NULL result without error in PyObject_Call Warren On Wed, Nov 9, 2011 at 9:32 PM, Bruce Southey <bsouthey@gmail.com> wrote:
I just want to draw attention to the bug report in http://projects.scipy.org/scipy/ticket/1187. Basically, scipy.integrate.ode takes a function as input, and the error occurs if that function returns a tuple (instead of, e.g., a list).
If there isn't a simple fix (I can't tell b/c the error occurs within C-code, which I'm not at all proficient in), then I think this should
On Wed, Nov 9, 2011 at 4:02 PM, Tony Yu <tsyu80@gmail.com> wrote: print
a more informative error message.
Best, -Tony
There are 2 full releases and an release candidate since Scipy 0.7.2 was released (2010-04-22). So, could you please update your numpy and scipy installations accordingly?
Works for scipy.10.0.rc1 (last part below)
Bruce
while r.successful() and r.t < t1: r.integrate(r.t+dt) print r.t, r.y
array([-0.71+0.237j, 0.40+0.j ]) 1.0 [-0.71+0.237j 0.40+0.j ] array([ 0.191-0.524j, 0.222+0.j ]) 2.0 [ 0.191-0.524j 0.222+0.j ] array([ 0.472+0.527j, 0.154+0.j ]) 3.0 [ 0.472+0.527j 0.154+0.j ] array([-0.619+0.307j, 0.118+0.j ]) 4.0 [-0.619+0.307j 0.118+0.j ] array([ 0.023-0.614j, 0.095+0.j ]) 5.0 [ 0.023-0.614j 0.095+0.j ] array([ 0.586+0.34j, 0.080+0.j ]) 6.0 [ 0.586+0.34j 0.080+0.j ] array([-0.521+0.445j, 0.069+0.j ]) 7.0 [-0.521+0.445j 0.069+0.j ] array([-0.160-0.612j, 0.061+0.j ]) 8.0 [-0.160-0.612j 0.061+0.j ] array([ 0.649+0.15j, 0.054+0.j ]) 9.0 [ 0.649+0.15j 0.054+0.j ] array([-0.384+0.564j, 0.049+0.j ]) 10.0 [-0.384+0.564j 0.049+0.j ]
SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
![](https://secure.gravatar.com/avatar/b80364cc6fbb2eac7dcfdb7738bae083.jpg?s=120&d=mm&r=g)
On Wed, Nov 9, 2011 at 10:48 PM, Warren Weckesser < warren.weckesser@enthought.com> wrote:
Bruce, did you change the return values of f and jac to be tuples instead of lists? It crashes when I run it.
ticket1187demo.py: ----- import scipy from scipy.integrate import ode
print print "scipy version:", scipy.__version__ print
y0, t0 = [1.0j, 2.0], 0
def f(t, y, arg1): return (1j*arg1*y[0] + y[1], -arg1*y[1]**2)
def jac(t, y, arg1): return ([1j*arg1, 1], [0, -arg1*2*y[1]])
r = ode(f, jac).set_integrator('zvode', method='bdf', with_jacobian=True) r.set_initial_value(y0, t0).set_f_params(2.0).set_jac_params(2.0) t1 = 10 dt = 1
while r.successful() and r.t < t1: r.integrate(r.t+dt) print r.t, r.y -----
Run it:
$ python ticket1187demo.py
scipy version: 0.11.0.dev-96e39ec
0-th dimension must be 2 but got 0 (not defined). rv_cb_arr is NULL Call-back cb_f_in_zvode__user__routines failed. Traceback (most recent call last): File "ticket1187demo.py", line 23, in <module> r.integrate(r.t+dt) File "/Users/warren/local_scipy/lib/python2.7/site-packages/scipy/integrate/_ode.py", line 333, in integrate self.f_params, self.jac_params) File "/Users/warren/local_scipy/lib/python2.7/site-packages/scipy/integrate/_ode.py", line 760, in run args[5:])) SystemError: NULL result without error in PyObject_Call
Warren
On Wed, Nov 9, 2011 at 9:32 PM, Bruce Southey <bsouthey@gmail.com> wrote:
I just want to draw attention to the bug report in http://projects.scipy.org/scipy/ticket/1187. Basically, scipy.integrate.ode takes a function as input, and the error occurs if that function returns a tuple (instead of, e.g., a list).
If there isn't a simple fix (I can't tell b/c the error occurs within C-code, which I'm not at all proficient in), then I think this should
On Wed, Nov 9, 2011 at 4:02 PM, Tony Yu <tsyu80@gmail.com> wrote: print
a more informative error message.
Best, -Tony
There are 2 full releases and an release candidate since Scipy 0.7.2 was released (2010-04-22). So, could you please update your numpy and scipy installations accordingly?
Works for scipy.10.0.rc1 (last part below)
Bruce
I forgot to mention it before, but like Warren, I'm using a recent version (0.11.0.dev-96e39ec) and still see the error. -Tony
![](https://secure.gravatar.com/avatar/38d5ac232150013cbf1a4639538204c0.jpg?s=120&d=mm&r=g)
On 11/09/2011 04:02 PM, Tony Yu wrote:
I just want to draw attention to the bug report in http://projects.scipy.org/scipy/ticket/1187. Basically, scipy.integrate.ode takes a function as input, and the error occurs if that function returns a tuple (instead of, e.g., a list).
If there isn't a simple fix (I can't tell b/c the error occurs within C-code, which I'm not at all proficient in), then I think this should print a more informative error message.
Best, -Tony
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user Ah Now I understand, perhaps providing the actual code to the ticket would avoid confusion.
Here you are replacing a mutable object with an immutable object so that may be an issue. Bruce
![](https://secure.gravatar.com/avatar/b80364cc6fbb2eac7dcfdb7738bae083.jpg?s=120&d=mm&r=g)
On Thu, Nov 10, 2011 at 9:39 AM, Bruce Southey <bsouthey@gmail.com> wrote:
** On 11/09/2011 04:02 PM, Tony Yu wrote:
I just want to draw attention to the bug report in http://projects.scipy.org/scipy/ticket/1187. Basically, scipy.integrate.ode takes a function as input, and the error occurs if that function returns a tuple (instead of, e.g., a list).
If there isn't a simple fix (I can't tell b/c the error occurs within C-code, which I'm not at all proficient in), then I think this should print a more informative error message.
Best, -Tony
_______________________________________________ SciPy-User mailing listSciPy-User@scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
Ah Now I understand, perhaps providing the actual code to the ticket would avoid confusion.
Here you are replacing a mutable object with an immutable object so that may be an issue.
I was thinking the same; for example, if the input function returns an array it also works fine. I'm not sure whether the correct behavior is to simply cast the tuple to a list or to simply raise a more informative error. Unfortunately, I don't understand the C-code well enough to submit a patch. Best, -Tony
![](https://secure.gravatar.com/avatar/b0f62d137f9ea1d0b6cc4e7e6f61b119.jpg?s=120&d=mm&r=g)
On Thu, Nov 10, 2011 at 9:05 AM, Tony Yu <tsyu80@gmail.com> wrote:
On Thu, Nov 10, 2011 at 9:39 AM, Bruce Southey <bsouthey@gmail.com> wrote:
** On 11/09/2011 04:02 PM, Tony Yu wrote:
I just want to draw attention to the bug report in http://projects.scipy.org/scipy/ticket/1187. Basically, scipy.integrate.ode takes a function as input, and the error occurs if that function returns a tuple (instead of, e.g., a list).
If there isn't a simple fix (I can't tell b/c the error occurs within C-code, which I'm not at all proficient in), then I think this should print a more informative error message.
Best, -Tony
_______________________________________________ SciPy-User mailing listSciPy-User@scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
Ah Now I understand, perhaps providing the actual code to the ticket would avoid confusion.
Here you are replacing a mutable object with an immutable object so that may be an issue.
I was thinking the same; for example, if the input function returns an array it also works fine. I'm not sure whether the correct behavior is to simply cast the tuple to a list or to simply raise a more informative error. Unfortunately, I don't understand the C-code well enough to submit a patch.
Looks like a bug in f2py. I've added some comments to the ticket: http://projects.scipy.org/scipy/ticket/1187 Warren
Best, -Tony
_______________________________________________ SciPy-User mailing list SciPy-User@scipy.org http://mail.scipy.org/mailman/listinfo/scipy-user
participants (3)
-
Bruce Southey
-
Tony Yu
-
Warren Weckesser