NEURON: The total number of cells, 1, is different than the number of user partition cells, 0

General issues of interest both for network and
individual cell parallelization.

Moderator: hines

Post Reply
loremauro
Posts: 3
Joined: Mon Nov 14, 2022 11:09 am

NEURON: The total number of cells, 1, is different than the number of user partition cells, 0

Post by loremauro »

Hi all, I'm using python neuron for an optimization task and to speed up the process I'm implementing this bit of code for the parallelization:

Code: Select all

h.load_file("parcom.hoc")
p = h.ParallelComputeTool()
p.change_nthread(16,1)
p.multisplit(1)
then I'm defining a section and a voltage clamp protocol:

Code: Select all

class Section():
    def __init__(self):
        self.soma = h.Section("name=soma")
        self.soma.nseg = 1
        self.soma.diam = 4
        self.soma.L = 10
        self.soma.Ra = 120
        self.soma.cm = 1 
        self.soma.insert("na18a")
        self.soma.gbar_na18a = 0.1
        self.soma.ena = 60
        
def initialize():
    h.finitialize()
    h.run()

cell = Section()

def voltage_clamp_activation(voltage):

    h.dt = 0.025
    h.celsius = 32
    h.tstop = 210
    h.v_init = -70 
    ina = h.Vector()
    ina.record(cell.soma(0.5)._ref_ina_na18a)
    v = h.Vector()
    v.record(cell.soma(0.5)._ref_v)
    time = h.Vector()
    time.record(h._ref_t)

    clamp = h.SEClamp(cell.soma(0.5))
    clamp.rs /= 100
    clamp.dur1 = 100
    clamp.amp1 = -70
    clamp.dur2 = 100
    clamp.amp2 = voltage
    clamp.dur3 = 10
    clamp.amp3 = -70

    initialize()
    return list(ina), v, time

a, b, c = voltage_clamp_activation(10)
Now the code made this way works fine, but the clamped section is the same, and based on my experience i saw that it's best to clamp a new cell everytime (later in the code i will do this clamp for many voltage steps). Thus what I do is calling the Section() object directly in the clamp function.
Without the code for the multisplit it works, but with that bit implemented I get the neuron message that's the title of this post, followed by an error message:
RuntimeError: hocobj_call error: hoc_execerror
pointing at h.finitialize()
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: NEURON: The total number of cells, 1, is different than the number of user partition cells, 0

Post by ted »

Can't say I've ever seen that.

On an unrelated topic: this

Code: Select all

def initialize():
    h.finitialize()
    h.run()
will execute h.finitialize() twice. The first execution will not affect the membrane potential of any segment. The second execution is built into h.run(), which among other things will set membrane potential in each segment to whatever the current value of h.v_init might be--and then launches a simulation that will run from h.t == 0 to h.t = h.tstop. If you intend your initialize() to either call
h.finitialize()
or
h.finitialize(h.v_init)
you should get rid of the h.run() call.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: NEURON: The total number of cells, 1, is different than the number of user partition cells, 0

Post by hines »

parcom.hoc is only for load balancing an already existing network model (or large cell). To make your 4 line fragment work , the 4 lines must be moved after

Code: Select all

cell = Section()
However, I believe your purpose can be better achieved with

Code: Select all

pc = h.ParallelContext()
pc.nthread(16) # assuming you have 16 cores and create a multiple of 16 single compartment cells.
self.soma = h.Section("name=soma")
Instead use the syntax

Code: Select all

self.soma = h.Section(name="soma", cell=self)
Post Reply