mcdougallab / matlabneuroninterface

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

Add callback support #93

Closed hvangeffen closed 9 months ago

hvangeffen commented 10 months ago

Closes #11, closes #9

ramcdougal commented 10 months ago

As far as NEURON is concerned, there can be many finitialize callbacks, with each one responsible for solving is part of the problem. (e.g. maybe one handles calcium initialization in a certain cell type.)

Also, there are multiple points in the initialization where the callbacks can be invoked.

hvangeffen commented 10 months ago

As far as NEURON is concerned, there can be many finitialize callbacks, with each one responsible for solving is part of the problem. (e.g. maybe one handles calcium initialization in a certain cell type.)

In that case is there a way to dynamically create c function to be passed to hoc install

sym = hoc_install(FINITIALIZE_RULE, function_type, 0, &hoc_top_level_symlist);
sym->u.u_proc->defn.pf = finitialize_callback;
sym->u.u_proc->nauto = 0;
sym->u.u_proc->nobjauto = 0;

Or add a callback function accepting an argument. I would like to be able to do something like:

sym = hoc_install(FINITIALIZE_RULE, function_type, 0, &hoc_top_level_symlist);
sym->u.u_proc->defn.pf = [func_name]() { mexEvalString(func_name + "()"); hoc_ret(); hoc_pushx(0); };
sym->u.u_proc->nauto = 0;
sym->u.u_proc->nobjauto = 0;

Also, there are multiple points in the initialization where the callbacks can be invoked.

As in the same function could be invoked multiple times during the initialization or can you specify when adding the callback when it should be invoked?

ramcdougal commented 10 months ago

FInitializeHandler takes an optional numeric argument to specify at which point in the initialization process the callback should be invoked:

https://nrn.readthedocs.io/en/8.2.3/python/simctrl/programmatic.html#FInitializeHandler

If MATLAB cannot dynamically generate C callbacks, the string for invoking the function could have an argument in it... E.g. instead of callback() we could do callback(73)

You could get the argument in position 1 via getarg(1)... This returns a double*