Driving synaptic event using vecStim

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

Moderator: hines

rlindroos
Posts: 17
Joined: Thu Jan 02, 2014 2:23 pm

Re: Driving synaptic event using vecStim

Post by rlindroos » Thu Feb 14, 2019 6:52 am

* the setup works fine in regular neuron

hines
Site Admin
Posts: 1580
Joined: Wed May 18, 2005 3:32 pm

Re: Driving synaptic event using vecStim

Post by hines » Thu Feb 14, 2019 8:53 am

look at nrn/src/nrnoc/netstim.mod for an analogy. You need to replace POINTER with BBCOREPOINTER and introduce
bbcore_write and bbcore_read implementations. Anything containing the string BBCORE is of interest.
I should update vecstim.mod to make it compatible with CoreNEURON.

zyc
Posts: 20
Joined: Sun Feb 19, 2017 9:15 pm

Re: Driving synaptic event using vecStim

Post by zyc » Mon Feb 18, 2019 2:36 am

I tried to introduce "bbcore_write" and "bbcore_read" from netstim.mod into our vecstim.mod, but got some errors when compiling the mechanism file with CoreNEURON. The following shows modified code, did I do anything wrong?

Thanks!

Code: Select all


NEURON {
	THREADSAFE
	ARTIFICIAL_CELL VecStim
	BBCOREPOINTER ptr
}


ASSIGNED {
	index
	etime (ms)
	ptr
}

VERBATIM
#if NRNBBCORE /* running in CoreNEURON */

#define IFNEWSTYLE(arg) arg

#else /* running in NEURON */

/*
   1 means noiseFromRandom was called when _ran_compat was previously 0 .
   2 means noiseFromRandom123 was called when _ran_compart was previously 0.
*/
static int _ran_compat; /* specifies the noise style for all instances */
#define IFNEWSTYLE(arg) if(_ran_compat == 2) { arg }

#endif /* running in NEURON */
ENDVERBATIM

...... (INITIAL block, NET_RECEIVE block etc.)

VERBATIM
#include "nrnran123.h"

#if !NRNBBCORE
/* backward compatibility */
double nrn_random_pick(void* r);
void* nrn_random_arg(int argpos);
int nrn_random_isran123(void* r, uint32_t* id1, uint32_t* id2, uint32_t* id3);
#endif
ENDVERBATIM

VERBATIM
static void bbcore_write(double* x, int* d, int* xx, int *offset, _threadargsproto_) {
	/* error if using the legacy scop_exprand */
	if (!_p_ptr) {
		fprintf(stderr, "NetStim: cannot use the legacy scop_negexp generator for the random stream.\n");
		assert(0);
	}
	if (d) {
		uint32_t* di = ((uint32_t*)d) + *offset;
		if (_ran_compat == 1) {
			void** pv = (void**)(&_p_ptr);
			/* error if not using Random123 generator */
			if (!nrn_random_isran123(*pv, di, di+1, di+2)) {
				fprintf(stderr, "NetStim: Random123 generator is required\n");
				assert(0);
			}
		}else{
			nrnran123_State** pv = (nrnran123_State**)(&_p_ptr);
			nrnran123_getids3(*pv, di, di+1, di+2);
		}
		/*printf("Netstim bbcore_write %d %d %d\n", di[0], di[1], di[3]);*/
	}
	*offset += 3;
}
static void bbcore_read(double* x, int* d, int* xx, int* offset, _threadargsproto_) {
	assert(!_p_ptr);
	if (noise) {
		uint32_t* di = ((uint32_t*)d) + *offset;
		nrnran123_State** pv = (nrnran123_State**)(&_p_ptr);
		*pv = nrnran123_newstream3(di[0], di[1], di[2]);
	}else{
		return;
	}
	*offset += 3;
}
ENDVERBATIM


ted
Site Admin
Posts: 5647
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Driving synaptic event using vecStim

Post by ted » Mon Feb 18, 2019 11:16 am

hines wrote:
Thu Feb 14, 2019 8:53 am
I should update vecstim.mod to make it compatible with CoreNEURON.
The file distributed with NEURON is called vecevent.mod, even though it defines the properties of an ARTIFICIAL_CELL class called VecStim. Among my own files, I find something called vecstim.mod from 2002, the source code for which differed from vecevent.mod, and which became deprecated by 2008 if not earlier. Looking to the future, wouldn't it be best to abandon vecstim.mod and base new development on vecevent.mod? zyc, are you so far along in your own code development that you are now stuck with vecstim.mod?

hines
Site Admin
Posts: 1580
Joined: Wed May 18, 2005 3:32 pm

Re: Driving synaptic event using vecStim

Post by hines » Mon Feb 18, 2019 11:47 am

i've updated vecevent.mod (VecStim)
Just need to test with coreneuron.
When it is working I'll push to the github repository and mention that here.

hines
Site Admin
Posts: 1580
Joined: Wed May 18, 2005 3:32 pm

Re: Driving synaptic event using vecStim

Post by hines » Mon Feb 18, 2019 12:08 pm

vecevent.mod has been updated to be compatible with CoreNEURON. See
https://github.com/neuronsimulator/nrn/ ... 64f9402219

This kind of VERBATIM code is quite painful. I need to consider an NMODL syntax for easily describing the use of Random variables and Vectors in
mod files that automatically generate the bbcore_write and bbcore_read functions.

zyc
Posts: 20
Joined: Sun Feb 19, 2017 9:15 pm

Re: Driving synaptic event using vecStim

Post by zyc » Wed Feb 20, 2019 1:17 am

It works, thank you so much.

Post Reply