3 Replies - 200 Views - Last Post: 12 January 2019 - 11:19 AM Rate Topic: -----

#1 esadri21   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 09-November 17

Python restarts the shell when I tried to do math

Posted 11 January 2019 - 10:12 AM

I have a problem with the following code. I tried a lot of web pages to find some solutions but I could not manage to.
The problem is when I run this script after just 4 lines of printing, Python restarts the shell. Also, in jupyter it sends message: The kernel appears to have died. It will restart automatically. Even with data file with 20 rows I ve got this error. and For more information this is not memory problem. I have 8 GB ddr3 memory. And I have performed more harder tasks.

I try to read a file at the first of the script containing (300,000) rows of data. then after calculating the `ODE` and other functions, I expect to print the results for comparison

    import numpy as np
    from scipy.integrate import odeint
    from math import *
    from scipy.integrate import quad  
    import math
    import pandas as pd

    hr, dr, cr, br = np.genfromtxt('outputs/new.txt',unpack=True)

    def OD_H(od, z, c, B)/>/>:
       Omegai = (1-od)
       div1 = np.divide(1, (1 + z), where = (1 + z)!= 0)     
       dMdt = -(div1) * (2 *(1-od)* (-2 + (od/(6 * c))) + 3 - 3 * b**2 * Omegai - 3 * od)
    return dMdt

    def ant(H0, z, od0, c, B)/>/>:
        z1 = 0
        od = odeint(OD_H, od0, [z1, z], args=(c, B)/>/>)[-1]                   
        return od   

    def dec(H0, z, od0, c, B)/>/>:
        od = ant(H0, z, od0, c, B)/>/>
        q = -1 - (-2 + od/(6 * c))
        return q

    for i in range(len(hr)):
        for z in range (0,1):
            print(dec(hr[i], z, dr[i], cr[i], br[i]),hr[i], dr[i], cr[i], br[i])








It is a simple code, but I do not know what the eventual problem is.
I really appreciate any help.


the input file (`new.txt`) could be


71.076588184266 0.40147988209522 0.080396967668756 0.050302016457046
    71.02284157687 0.39756707964421 0.080918035449145 0.050501956013259
    71.102923163306 0.41587392748136 0.07823452108922 0.049336707395359
    70.860444589498 0.46748446539443 0.072392464271658 0.046667808684486
    70.181278149341 0.44888833570037 0.077917371645449 0.04777288009128
    70.588452406351 0.49035265611716 0.072303154996487 0.045942096884044
    70.588452406351 0.49035265611716 0.072303154996487 0.045942096884044
    70.011812869146 0.44210637315163 0.07871914246357 0.048393990901086
    69.807956729005 0.41349634394633 0.082020266421564 0.049900569076028
    69.807956729005 0.41349634394633 0.082020266421564 0.049900569076028
    69.807956729005 0.41349634394633 0.082020266421564 0.049900569076028
    70.123419349447 0.43961350279409 0.07862300319627 0.048607832896286
    70.361666430312 0.41397677666087 0.080502527828865 0.049745843125116
    70.361666430312 0.41397677666087 0.080502527828865 0.049745843125116
    70.357430153315 0.41485946940097 0.08042642593323 0.049703105696664
    70.357430153315 0.41485946940097 0.08042642593323 0.049703105696664
    71.551080656041 0.51047305096688 0.066682530098241 0.0446474321235


Is This A Good Question/Topic? 0
  • +

Replies To: Python restarts the shell when I tried to do math

#2 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 507
  • View blog
  • Posts: 1,596
  • Joined: 27-December 13

Re: Python restarts the shell when I tried to do math

Posted 11 January 2019 - 11:25 AM

At first glance, all I see is the wrong indentation of line 14 - but I guess this is not the case in your real program..?
Was This Post Helpful? 0
  • +
  • -

#3 esadri21   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 82
  • Joined: 09-November 17

Re: Python restarts the shell when I tried to do math

Posted 11 January 2019 - 12:04 PM

A guy has told me to use solv_ivp. It solved my problem. but I could not understand why ODE has many problem in scripts
Was This Post Helpful? 0
  • +
  • -

#4 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 971
  • View blog
  • Posts: 3,828
  • Joined: 13-June 14

Re: Python restarts the shell when I tried to do math

Posted 12 January 2019 - 11:19 AM

I ran the code on my machine with your sample input file and it aborted:

$ python3 stuff.py 
[ 0.16771346] 71.0765881843 0.401479882095 0.0803969676688 0.050302016457
[ 0.18113212] 71.0228415769 0.397567079644 0.0809180354491 0.0505019560133
[ 0.11404428] 71.1029231633 0.415873927481 0.0782345210892 0.0493367073954
[-0.07627332] 70.8604445895 0.467484465394 0.0723924642717 0.0466678086845
 lsoda--  repeated calls with istate = 1 and tout = t (=r1)  
      in above message,  r1 =  0.0000000000000D+00
 lsoda--  run aborted.. apparent infinite loop     


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1