[SciPy-user] (no subject)

Adrián López alopez at imim.es
Fri Feb 24 03:23:15 CST 2006


Hi,

the code file is generated automatically, that was the reason for the  
strange lines as

xdot[0] = + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0

On the other hand, the reason for the arguments was because I'm  
saving the velocities and the trajectories on two different files,  
and I was passing them as part of the arguments. Nevertheless, my  
background is not computer science and all I learnt about programming  
was by myself, so please feel free to tell me how to do things  
properly ;-)

Here is exactly the code I'm running:

from numpy import *

from scipy.integrate import odeint

def func(x, t, *args):

         xdot = [0.0, 5.0, 0.0, 15.0, 0.0, 0.0, 0.0]

         xdot[0] = 0

         xdot[1] = - (x[1] * beta) + x[4] * beta

         xdot[2] = - (x[2] * beta) + x[5] * beta

         xdot[3] = + x[6] * beta - (x[3] * beta)

         xdot[4] = + alpha0 + (alpha + (x[3])**( n) * alpha1) / ((K)** 
( n) + (x[3])**( n)) - (k1 * x[4])

         xdot[5] = + alpha0 + (alpha + (x[1])**( n) * alpha1) / ((K)** 
( n) + (x[1])**( n)) - (k1 * x[5])

         xdot[6] = - (k1 * x[6]) + alpha0 + (alpha + (x[2])**( n) *  
alpha1) / ((K)**( n) + (x[2])**( n))

         g.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n'%(t, xdot[0], xdot 
[1], xdot[2], xdot[3], xdot[4], xdot[5], xdot[6]))

         return xdot

t = arange(0, 100.01, 0.01)

alpha0 = 0.0
alpha1 = 0.0
K = 1.0
beta = 5.0
n = 2.1
k1 = 1.0
alpha = 250.0
cell = 1.0

parameters = [alpha0, alpha1, K, beta, n, k1, alpha, cell]

x_0 = [0.0, 5.0, 0.0, 15.0, 0.0, 0.0, 0.0]

g = open('repressilator.veloc.out', 'w')

args = (parameters, g)
print 'message1'
x = odeint(func, x_0, t, args)
print 'message 2'
g.close()

f = open('repressilator.out', 'w')

for i in range(len(t)):

         f.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n'%(t[i], x[i][0], x 
[i][1], x[i][2], x[i][3], x[i][4], x[i][5], x[i][6]))

f.close()

That gives me this error:

[alopez at rosmarinus tmp]$ python file.py
message 1
Segmentation fault

when I run it on a machine Fedora Core 2 with numpy-0.9.5,   
Python-2.4.2 and scipy-0.4.6. As you can see, it does not give any  
error while importing numpy or scipy. As you said there might be some  
problems during installation. If it could be of any help, I can tell  
you that when I install Python-2.4.2, numpy-0.9.5 and scipy-0.4.6 (in  
this order) I had the problem documented here

http://www.scipy.org/FAQ#head-8371c35ef08b877875217aaac5489fc747b4aceb

about  "BLAS sources shipped with LAPACK are incomplete". But after I  
did what it is described on the Building General Instructions about  
BLAS and LAPACK from NetLib the import was clean.

Thanks for your help,

Adrián.


On Feb 23, 2006, at 9:37 PM, Travis Oliphant wrote:

> Adrián López wrote:
>
>> Hi people,
>>
>> I use SciPy since a few months ago. I use it mainly to integrate a
>> system of ODEs. Until now this piece of code was running nicely with
>> the previous version of SciPy:
>>
>>
>> from Numeric import *
>>
>>
> from numpy import *
>
>> from scipy.integrate import odeint
>>
>> def func(x, t, *args):
>>
>>
> You don't actually use the *args variable so don't define it.  All of
> your parameters are being grabbed from the module name-space.
>
> def func(x, t0):
>
>>         xdot = [0.0, 5.0, 0.0, 15.0, 0.0, 0.0, 0.0]
>>
>>         xdot[0] = + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0
>>
>>
> I have no idea why you are doing this instead of xdot[0]=0.
>
>>         xdot[1] = - (x[1] * beta) + x[4] * beta
>>
>>         xdot[2] = - (x[2] * beta) + x[5] * beta
>>
>>         xdot[3] = + x[6] * beta - (x[3] * beta)
>>
>>
> This line kept giving me errors.   I'm not sure why....
>
>>         xdot[4] = + alpha0 + (alpha + (x[3])**( n) * alpha1) / ((K)**
>> ( n) + (x[3])**( n)) - (k1 * x[4])
>>
>>         xdot[5] = + alpha0 + (alpha + (x[1])**( n) * alpha1) / ((K)**
>> ( n) + (x[1])**( n)) - (k1 * x[5])
>>
>>         xdot[6] = - (k1 * x[6]) + alpha0 + (alpha + (x[2])**( n) *
>> alpha1) / ((K)**( n) + (x[2])**( n))
>>
>>         g.write('%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n'%(t, xdot[0], xdot
>> [1], xdot[2], xdot[3], xdot[4], xdot[5], xdot[6]))
>>
>>         return xdot
>>
>> t = arange(0, 100.01, 0.01)
>>
>> alpha0 = 0.0
>> alpha1 = 0.0
>> K = 1.0
>> beta = 5.0
>> n = 2.1
>> k1 = 1.0
>> alpha = 250.0
>> cell = 1.0
>>
>> parameters = [alpha0, alpha1, K, beta, n, k1, alpha, cell]
>>
>> x_0 = [0.0, 5.0, 0.0, 15.0, 0.0, 0.0, 0.0]
>>
>> g = open('repressilator.veloc.out', 'w')
>>
>> args = (parameters, g)
>>
>> x = odeint(func, x_0, t, args)
>>
>>
>>
> You don't actually use the arguments in the function call but instead
> the use global variables inside the function, so you don't need the  
> args
> (or parameters) variables and can just write
>
> x = odeint(func, x_0, t)
>
>> [alopez at thymus tmp]$ python file.py
>> Segmentation fault
>>
>> on a linux machine and
>>
>> Macintosh-3:~/work/tmp adrianlopez$ python test.py
>> Bus error
>>
>>
>
> Can you tell when the error is occurring.  Put print statements in
> file.py to see when the segfault is actually happening.  If it's on
> import of scipy (which I suspect), then it's a problem with your
> installation (the wrong NumPy C-API is being used for some reason).
>
> -Travis
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.net
> http://www.scipy.net/mailman/listinfo/scipy-user



More information about the SciPy-user mailing list