Page 1 of 1

Running pde solver more than once

Posted: Mon Jun 19, 2017 4:56 am
by ren
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/", line 134, in nonvint_block
  File "/home/renat/miniconda2/envs/pde_env/lib/python2.7/site-packages/neuron/rxd/", 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/", 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/", line 337, in __mul__
    raise ValueError('dimension mismatch')
ValueError: dimension mismatch

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

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

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?

Re: Running pde solver more than once

Posted: Mon Jun 19, 2017 10:09 am
by ted
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
to launch each new simulation.

Re: Running pde solver more than once

Posted: Tue Jun 20, 2017 4:17 am
by ren
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 is needed I guess it may worth adding it to the example code and update the documentation. Thank you again!

Re: Running pde solver more than once

Posted: Tue Jun 20, 2017 9:35 am
by ted
If the 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?

Re: Running pde solver more than once

Posted: Wed Jun 21, 2017 12:33 pm
by ramcdougal
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

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


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

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

pyplot.subplot(2, 1, 1)
pyplot.subplot(2, 1, 2)
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.