mcdougallab / matlabneuroninterface

Interface for connecting NEURON and MATLAB
BSD 3-Clause "New" or "Revised" License
4 stars 1 forks source link

Add (automated) tests for the interface #63

Closed edovanveen closed 1 year ago

edovanveen commented 1 year ago

Closes #30, closes #56

ramcdougal commented 1 year ago

Do you want a more general reset function that removes sections, sets the temperature to the default, turns off variable step, turns off second order, sets the default time step, ...

edovanveen commented 1 year ago

@ramcdougal @AljenU All example scripts work in isolation, but:

edovanveen commented 1 year ago

Do you want a more general reset function that removes sections, sets the temperature to the default, turns off variable step, turns off second order, sets the default time step, ...

Yes, that would probably help! It looks like the problem now is that Neuron remembers things from previous tests, which somehow interferes with other tests.

edovanveen commented 1 year ago

Stack traces for crashes below. It seems to be a problem with spFactor() and NetCvode::init_events().

example_intfires
Stack Trace (from fault):
[  0] 0x00007ff8388b5a6c                            C:\nrn\bin\libnrniv.dll+01661548 Z8spFactorPc+00000108
[  1] 0x00007ff83883589a                            C:\nrn\bin\libnrniv.dll+01136794 Z9nrn_solveP9NrnThread+00000074
[  2] 0x00007ff83882e19d                            C:\nrn\bin\libnrniv.dll+01106333 Z23nrn_fixed_step_lastpartP9NrnThread+00000221
[  3] 0x00007ff83882c814                            C:\nrn\bin\libnrniv.dll+01099796 Z14nrn_fixed_stepv+00000228
[  4] 0x00007ff83882cb26                            C:\nrn\bin\libnrniv.dll+01100582 Z8fadvancev+00000070
[  5] 0x00007ff8388441f7                            C:\nrn\bin\libnrniv.dll+01196535 Z8hoc_callv+00000199
[  6] 0x00007ff838843fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[  7] 0x00007ff8388442a2                            C:\nrn\bin\libnrniv.dll+01196706 Z8hoc_callv+00000370
[  8] 0x00007ff838843fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[  9] 0x00007ff83884e130                            C:\nrn\bin\libnrniv.dll+01237296 Z12hoc_shortforv+00000368
[ 10] 0x00007ff838843fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[ 11] 0x00007ff83884d992                            C:\nrn\bin\libnrniv.dll+01235346 Z10hoc_ifcodev+00000130
[ 12] 0x00007ff838843fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[ 13] 0x00007ff8388442a2                            C:\nrn\bin\libnrniv.dll+01196706 Z8hoc_callv+00000370
[ 14] 0x00007ff838843fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[ 15] 0x00007ff83884dc60                            C:\nrn\bin\libnrniv.dll+01236064 Z11hoc_forcodev+00000208
[ 16] 0x00007ff838843fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[ 17] 0x00007ff8388442a2                            C:\nrn\bin\libnrniv.dll+01196706 Z8hoc_callv+00000370
[ 18] 0x00007ff838843fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[ 19] 0x00007ff83884ddbc                            C:\nrn\bin\libnrniv.dll+01236412 Z13hoc_call_funcP6Symboli+00000060

example_patternstim
Stack Trace (from fault):
[  0] 0x00007ff8354aed44                            C:\nrn\bin\libnrniv.dll+00519492 ZN8NetCvode11init_eventsEv+00000484
[  1] 0x00007ff83553dc6e                            C:\nrn\bin\libnrniv.dll+01105006 Z15nrn_finitializeid+00000974
[  2] 0x00007ff83553de57                            C:\nrn\bin\libnrniv.dll+01105495 Z11finitializev+00000039
[  3] 0x00007ff8355541f7                            C:\nrn\bin\libnrniv.dll+01196535 Z8hoc_callv+00000199
[  4] 0x00007ff835553fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[  5] 0x00007ff83555ddbc                            C:\nrn\bin\libnrniv.dll+01236412 Z13hoc_call_funcP6Symboli+00000060

example_savestate
Stack Trace (from fault):
[  0] 0x00007ff835595a6c                            C:\nrn\bin\libnrniv.dll+01661548 Z8spFactorPc+00000108
[  1] 0x00007ff83551589a                            C:\nrn\bin\libnrniv.dll+01136794 Z9nrn_solveP9NrnThread+00000074
[  2] 0x00007ff83550e19d                            C:\nrn\bin\libnrniv.dll+01106333 Z23nrn_fixed_step_lastpartP9NrnThread+00000221
[  3] 0x00007ff83550c814                            C:\nrn\bin\libnrniv.dll+01099796 Z14nrn_fixed_stepv+00000228
[  4] 0x00007ff83550cb26                            C:\nrn\bin\libnrniv.dll+01100582 Z8fadvancev+00000070
[  5] 0x00007ff8355241f7                            C:\nrn\bin\libnrniv.dll+01196535 Z8hoc_callv+00000199
[  6] 0x00007ff835523fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[  7] 0x00007ff83552ddbc                            C:\nrn\bin\libnrniv.dll+01236412 Z13hoc_call_funcP6Symboli+00000060

example_acpot (after example_netcon)
Stack Trace (from fault):
[  0] 0x00007ff83556ed44                            C:\nrn\bin\libnrniv.dll+00519492 ZN8NetCvode11init_eventsEv+00000484
[  1] 0x00007ff8355fdc6e                            C:\nrn\bin\libnrniv.dll+01105006 Z15nrn_finitializeid+00000974
[  2] 0x00007ff8355fde57                            C:\nrn\bin\libnrniv.dll+01105495 Z11finitializev+00000039
[  3] 0x00007ff8356141f7                            C:\nrn\bin\libnrniv.dll+01196535 Z8hoc_callv+00000199
[  4] 0x00007ff835613fa3                            C:\nrn\bin\libnrniv.dll+01195939 Z11hoc_executeP4Inst+00000067
[  5] 0x00007ff83561ddbc                            C:\nrn\bin\libnrniv.dll+01236412 Z13hoc_call_funcP6Symboli+00000060

example_netcon
Stack Trace (from fault):
[  0] 0x00007ff835685a6c                            C:\nrn\bin\libnrniv.dll+01661548 Z8spFactorPc+00000108
[  1] 0x00007ff83560589a                            C:\nrn\bin\libnrniv.dll+01136794 Z9nrn_solveP9NrnThread+00000074
[  2] 0x00007ff8355fe19d                            C:\nrn\bin\libnrniv.dll+01106333 Z23nrn_fixed_step_lastpartP9NrnThread+00000221
[  3] 0x00007ff8355fe23d                            C:\nrn\bin\libnrniv.dll+01106493 Z23nrn_fixed_step_lastpartP9NrnThread+00000381
[  4] 0x00007ff8355fcd10                            C:\nrn\bin\libnrniv.dll+01101072 Z20nrn_fixed_step_groupi+00000368
[  5] 0x00007ff83557a3a2                            C:\nrn\bin\libnrniv.dll+00566178 Z17ncs2nrn_integrated+00000450
[  6] 0x00007ff8355b29fc                            C:\nrn\bin\libnrniv.dll+00797180 ZN3BBS12netpar_solveEd+00000300
[  7] 0x00007ff8355d09cc                            C:\nrn\bin\libnrniv.dll+00920012 ZN5OcBBSD2Ev+00004428
[  8] 0x00007ff835629437                            C:\nrn\bin\libnrniv.dll+01283127 Z16hoc_call_ob_procP6ObjectP6Symboli+00000503

example_patternstim
Stack Trace (from fault):
[  0] 0x00007ff835685a6c                            C:\nrn\bin\libnrniv.dll+01661548 Z8spFactorPc+00000108
[  1] 0x00007ff83560589a                            C:\nrn\bin\libnrniv.dll+01136794 Z9nrn_solveP9NrnThread+00000074
[  2] 0x00007ff8355fe19d                            C:\nrn\bin\libnrniv.dll+01106333 Z23nrn_fixed_step_lastpartP9NrnThread+00000221
[  3] 0x00007ff8355fe23d                            C:\nrn\bin\libnrniv.dll+01106493 Z23nrn_fixed_step_lastpartP9NrnThread+00000381
[  4] 0x00007ff8355fcd10                            C:\nrn\bin\libnrniv.dll+01101072 Z20nrn_fixed_step_groupi+00000368
[  5] 0x00007ff83557a3a2                            C:\nrn\bin\libnrniv.dll+00566178 Z17ncs2nrn_integrated+00000450
[  6] 0x00007ff8355b29fc                            C:\nrn\bin\libnrniv.dll+00797180 ZN3BBS12netpar_solveEd+00000300
edovanveen commented 1 year ago

I have isolated the problem to the n.reset_sections() call, which just runs clib.neuron.hoc_oc("forall delete_section()") in the background. If I omit it, there are no crashes. However, we do need some way to reset the topology between tests.

edovanveen commented 1 year ago

It seems like the crash has something to do with Section.delete(), n.reset_sections() and n.allsec().

All problematic examples have in common that they do not define any sections. If I run example_intfires.m (or any of the other problematic examples) everything is fine, but if I run afterwards as = n.allsec(); disp(as{1}); I get a crash:

[  0] 0x000000006f5e01d4     Z:\Git\matlabneuron\neuron\neuronInterface.dll+00393684 cppGetPassThrough+00382196
[  1] 0x000000006f591ead     Z:\Git\matlabneuron\neuron\neuronInterface.dll+00073389 cppGetPassThrough+00061901

If I run only the following script, I also get a crash:

% Try to cause a crash while running NEURON in MATLAB
n = neuron.Neuron();
n.reset_sections();
as = n.allsec();
disp(as{1});

If I add soma = n.Section("soma"); at the top of every problematic example, they behave fine, as far as I can tell.

edovanveen commented 1 year ago

@ramcdougal ready for review