Problem with hclass in NEURON 7.4

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
apdavison
Posts: 14
Joined: Tue May 24, 2005 3:56 am
Location: CNRS, Gif sur Yvette, France
Contact:

Problem with hclass in NEURON 7.4

Post by apdavison »

I'm getting an error with NEURON 7.4 for code which worked fine in versions 7.0-7.3. An example:

Code: Select all

from neuron import h, hclass

class SpikeArray(hclass(h.VecStim)):

    def __init__(self, spike_times=[]):
        self.spike_times = h.Vector(spike_times)
        self.play(self.spike_times)

stim = SpikeArray([1, 2, 3, 4, 5])
The error message is:

Code: Select all

Traceback (most recent call last):
  File "tmp.py", line 10, in <module>
    stim = SpikeArray([1, 2, 3, 4, 5])
  File "/home/docker/env/neurosci/local/lib/python2.7/site-packages/neuron/__init__.py", line 170, in __new__
    return hoc.HocObject.__new__(cls, *args, **kwds)
RuntimeError: invalid keyword argument
The strange thing is that when I compare neuron/__init__.py between the 7.3 and 7.4 releases, the code around line 170 hasn't changed.

Many thanks in advance for any help.
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Problem with hclass in NEURON 7.4

Post by ramcdougal »

Sorry about that; ironically, this was caused by an attempt to improve error checking in the hocobj_call function.

A fix is to add the line:

Code: Select all

PyDict_DelItemString(kwds, "hocbase");
at line 182 in src/nrnpython/nrnpy_hoc.cpp (right before the call to hocobj_call).

We'll try to update the repository soon.
apdavison
Posts: 14
Joined: Tue May 24, 2005 3:56 am
Location: CNRS, Gif sur Yvette, France
Contact:

Re: Problem with hclass in NEURON 7.4

Post by apdavison »

Thanks for the quick reply. The fix solved the problem with the example I showed, but if I change the last line to:

Code: Select all

stim = SpikeArray(spike_times=[1, 2, 3, 4, 5])
the error reappears.
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Problem with hclass in NEURON 7.4

Post by ramcdougal »

One more change should fix that, this time in share/lib/python/neuron/__init__.py :

Replace the __new__ method (starts at line 168) with

Code: Select all

        def __new__(cls, *args, **kwds):
            kwds2 = {'hocbase': cls.htype}
            if 'sec' in kwds:
                kwds2['sec'] = kwds['sec']
            return hoc.HocObject.__new__(cls, *args, **kwds2)
(Depending on how you installed NEURON, you may or may not need to run "python setup.py install" from src/nrnpython to get the changes to the Python library copied into a location on your PYTHONPATH.)

Update: the fix is now included in the NEURON repository.
apdavison
Posts: 14
Joined: Tue May 24, 2005 3:56 am
Location: CNRS, Gif sur Yvette, France
Contact:

Re: Problem with hclass in NEURON 7.4

Post by apdavison »

Many thanks!
apdavison
Posts: 14
Joined: Tue May 24, 2005 3:56 am
Location: CNRS, Gif sur Yvette, France
Contact:

Re: Problem with hclass in NEURON 7.4

Post by apdavison »

Do you expect to update the tar.gz package at http://www.neuron.yale.edu/ftp/neuron/v ... 7.4.tar.gz soon?
Post Reply