Programming and Debugging a declarative language

A Python package that facilitates development and use of models of biological neural networks

Moderator: tom_morse

Post Reply
Posts: 66
Joined: Wed May 18, 2005 10:37 pm

Programming and Debugging a declarative language

Post by wwlytton »

I am having trouble getting used to NetPyNE and realize that part of this is my unfamiliarity with proper programming practices in a declarative language such as this.

"Declarative programming is where you say what you want without having to say how to do it"

When working in an imperative language, I work out central data structures, central subroutines, overall toplevel loop (structured programming).

Seems that none of that thinking helps me with declarative languages like netpyne or latex (other declarative langs: yacc/bison, SQL regexp, lex, markup, troff, CSS, VHDL, Maude) My debugging skills -- setting breakpoints, etc -- are also not helping me.

What suggestions can be offered on how to go about the programming process and how to identify bugs? As simulations get more complex many of these bugs will be completely inapparent. It would seem that another useful tool for a declarative language would be something like Lint : "a linter is a tool that flags suspicious usage in software" -- wikipedia.

I found a couple of articles on the topic of declarative debugging -- this one looked interesting -- "Declarative debugging ... is particularly attractive for declarative programming languages,.... Declarative debuggers [use] a program transformation." -- from ... 6108003770 (Declarative Debugging Meets the World; Wolfgang Lux; Electronic Notes in Theoretical Computer Science 216 (2008) 65–77)
Posts: 86
Joined: Tue Aug 18, 2015 3:49 pm

Re: Programming and Debugging a declarative language

Post by salvadord »

Here are some steps to help debug NetPyNE code (which, as mentioned in previous post, is a declarative language):

1) Run first the file containing the NetParams object (e.g. python From version 0.7.0 onwards, NetPyNE provides error checking (set cfg.checkErrors=True), indicating any errors in the code, as well as warnings of potential issues. You can also check the correct syntax and list of valid options in the documentation reference:

Some common errors include:
- syntax/format/typos, e.g. in cellParams using 'cellnum':10 instead of 'numCells': 10
- design/conceptual, e.g. trying to connect a population that doesn't exist
- In some cases the error could be caused by a NetPyNE bug -- if you think this could be the case please report it in this forum.

2) Run the simulation with verbose mode on cfg.verbose=True. The verbose mode provides details of the step-by-step creation of the network and might give insights into what is wrong (both syntax and conceptual design). Check that the expected populations, cells, connections and stims are being created; that the sim configuration is as expected (duration, cells/traces being recorded, plots, saving, etc).

3) If getting a python error, try to get some hint of what could be the issue based on the functions called or variables used (you can use ipython to get more clear error messages), e.g. for the following error:

Code: Select all

  File "/u/salvadord/Documents/ISB/Models/netpyne_repo/netpyne/", line 151, in addStims
    postCell.addStim(params)  # call cell method to add connections
  File "/u/salvadord/Documents/ISB/Models/netpyne_repo/netpyne/", line 996, in addStim
    stim = getattr(h, params['type'])(sec['hSec'](params['loc']))
AttributeError: 'hoc.HocObject' object has no attribute 'NetStimibla'
Notice the call to addStim(), the params['type'] and the no attribute 'NetStimibla' -- the error was caused because the 'type' param of one of the stimulations had an invalid value of 'NetStimbla' instead of 'NetStim' (this error will actually be highlighted by NetPyNE's error checking, but serves to illustrate this complementary approach).

Of course many of these errors will be undecipherable, and should eventually be caught as exceptions by NetPyNE and provided as a clear message to the user with suggestions on how to fix. However, in the meantime, this approach might be useful in some cases.

4) Inspect the instantiated network. You can check all the parameters of all cells, conns etc. using a simple dot notation format. For details on the data structure and how to access it see: ... utput-data

You can check both the python structure containing the parameters (e.g.[0].secs.soma.mechs.nap.gbar) as well as the actual NEURON objects (e.g.[0].secs.soma.hSec(0.5).gbar_nap).

5) Coming soon (~6 months) a GUI will be available to specify all the parameters, create the network, run simulations and visualize the results. It will include error checking and interactive suggestions while designing the network.

6) If can't figure out the error please post a message in this forum -- this is really useful for other users and helps us improve the user experience. Thanks!
Post Reply