Running pde solver more than once

Extending NEURON to handle reaction-diffusion problems.

Moderators: hines, wwlytton, ramcdougal

Post Reply
ren
Posts: 2
Joined: Fri Jun 16, 2017 4:21 am

Running pde solver more than once

Post by ren » Mon Jun 19, 2017 4:56 am

Hello everyone! I am new to Neuron and RxD. Recently , I went through examples and stumbled upon scalar bi stable wave. Im using jupyter for running the code and with the first run it seems totally ok, I got all the plots as in example, but the second run already gives this error message. I am using Ubuntu.

Code: Select all

Traceback (most recent call last):
  File "/home/renat/miniconda2/envs/pde_env/lib/python2.7/site-packages/neuron/nonvint_block_supervisor.py", line 134, in nonvint_block
    c[method](*args)
  File "/home/renat/miniconda2/envs/pde_env/lib/python2.7/site-packages/neuron/rxd/rxd.py", line 586, in _w_fixed_step_solve
    def _w_fixed_step_solve(raw_dt): return _fixed_step_solve(raw_dt)
  File "/home/renat/miniconda2/envs/pde_env/lib/python2.7/site-packages/neuron/rxd/rxd.py", line 356, in _fixed_step_solve
    b = _rxd_reaction(states) - _diffusion_matrix * states
  File "/home/renat/miniconda2/envs/pde_env/lib/python2.7/site-packages/scipy/sparse/base.py", line 337, in __mul__
    raise ValueError('dimension mismatch')
ValueError: dimension mismatch

RuntimeError                              Traceback (most recent call last)
<ipython-input-4-39d358bcedc7> in <module>()
     37 
     38 for i in xrange(1, 5):
---> 39     h.continuerun(i * 25)
     40     plot_it()
     41 

RuntimeError: hoc error
Interestingly the code can be run on my MAC OS, but somehow it stores values (at least it seems so) for the second and next runnings. This can be clearly seen on the artefacts in the image
Image

My aim is to run kind of that solver but for different equation parameters, this is why I need more that one time run, but unfortunately I couldn't solve the problem by far. Can anyone help me with that?

ted
Site Admin
Posts: 5091
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Running pde solver more than once

Post by ted » Mon Jun 19, 2017 10:09 am

Looks like you're writing your own simulation flow control code and/or your own initialization code to launch each new simulation. Can't say anything more specific about the cause of your particular problem without seeing exactly what you're doing. However, you wouldn't be having this problem if your model's mechanisms initialize properly and you use
h.run()
to launch each new simulation.

ren
Posts: 2
Joined: Fri Jun 16, 2017 4:21 am

Re: Running pde solver more than once

Post by ren » Tue Jun 20, 2017 4:17 am

Thank you, ted! I didnt check all other examples of Neuron, because I was mainly interested in the pde part , for that ,as I said, I used the example of scalar bi stable wave, running it twice in my Jupyter notebook. The code was exactly the same, I didnt touch it. After the first run, it started to give the error message for which I had to restart kernel.
I hope its clear. If the h.run() is needed I guess it may worth adding it to the example code and update the documentation. Thank you again!

ted
Site Admin
Posts: 5091
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Running pde solver more than once

Post by ted » Tue Jun 20, 2017 9:35 am

If the h.run() is needed I guess it may worth adding it to the example code and update the documentation.
Lots of examples of all kinds of things are floating around on the Internet. Exactly what example code are you referring to?

ramcdougal
Posts: 96
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Medicine

Re: Running pde solver more than once

Post by ramcdougal » Wed Jun 21, 2017 12:33 pm

I assume you're referring to the Scalar Bistable Wave example in the reaction-diffusion documentation.

My guess is that you're putting the entire code into a single Jupyter cell and rerunning. Should this work? Yes, but apparently it's remembering parts of the configuration from one run to the next and getting confused. Out of curiosity, try replacing the definition of where with

Code: Select all

where = rxd.Region([dend])
and see if that avoids the issue, since it explicitly refers to one section instead of all the sections. (Again, there should only ever be one section if you're rerunning but the errors you're reporting make me think for some reason you have two. I'll try to track down why.)

I'd recommend splitting the example into two Jupyter cells: one for the setup and one for initializing and running the simulation.

Alternatively and probably better, have the script control the multiple runs... e.g. here I run the simulation twice, once with a parameter of 0.2 and once with a parameter of 0.4:

Code: Select all

from neuron import h, rxd
import numpy
from matplotlib import pyplot

# needed for standard run system
h.load_file('stdrun.hoc')

dend = h.Section(name='dend')
dend.nseg = 101

# WHERE the dynamics will take place
where = rxd.Region([dend])

# WHO the actors are
u = rxd.Species(where, d=1, initial=0)

# parameter controlling wave spread; will need to set anew for each simulation after initialization
alpha = rxd.Parameter(where)

# HOW they act
bistable_reaction = rxd.Rate(u, -u * (1 - u) * (alpha - u))

def plot_it(color='k'):
    y = u.nodes.concentration
    x = u.nodes.x

    # convert x from normalized position to microns
    x = dend.L * numpy.array(x)

    pyplot.plot(x, y, color)

def run_sim(myalpha):
    # setup initial conditions for simulation
    h.finitialize(-65)    # not actually using membrane potential here, but good practice to specify
    alpha.nodes.value = myalpha
    h.CVode().re_init()   # only needed for variable step, but harmless in fixed step case
    for node in u.nodes:
        if node.x < .2: node.concentration = 1

    plot_it('r')

    for i in xrange(1, 5):
        h.continuerun(i * 25)
        plot_it()

    pyplot.ylim([0, 1.1])
    pyplot.ylabel('alpha = %g' % myalpha)

pyplot.subplot(2, 1, 1)
run_sim(0.2)
pyplot.subplot(2, 1, 2)
run_sim(0.4)

pyplot.show()
If you want to run a new simulation in Jupyter interactively, you'd just call e.g. run_sim(0.3) and it'll plot the new figure.

Post Reply