Skip to content

Commit

Permalink
Neuron9 compatibility (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienJaquier committed Dec 15, 2022
1 parent 824bcb3 commit 614955f
Show file tree
Hide file tree
Showing 16 changed files with 950 additions and 966 deletions.
325 changes: 259 additions & 66 deletions examples/sscx_sample_dir/mechanisms/ProbAMPANMDA_EMS.mod

Large diffs are not rendered by default.

385 changes: 295 additions & 90 deletions examples/sscx_sample_dir/mechanisms/ProbGABAAB_EMS.mod

Large diffs are not rendered by default.

73 changes: 50 additions & 23 deletions examples/sscx_sample_dir/mechanisms/StochKv3.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TITLE StochKv2.mod
TITLE StochKv3.mod

COMMENT
----------------------------------------------------------------
Expand Down Expand Up @@ -28,11 +28,11 @@ NEURON {
USEION k READ ek WRITE ik
RANGE N, eta, gk, gamma, deterministic, gkbar, ik
RANGE N0, N1, n0_n1, n1_n0
GLOBAL ninf, linf, ltau, ntau, an, bn, al, bl
GLOBAL P_an, P_bn, P_al, P_bl
RANGE ninf, linf, ltau, ntau, an, bn, al, bl
RANGE P_an, P_bn, P_al, P_bl
GLOBAL vmin, vmax
:BBCOREPOINTER rng
POINTER rng
BBCOREPOINTER rng
:POINTER rng
}

UNITS {
Expand Down Expand Up @@ -99,15 +99,22 @@ for comparison with Pr to decide whether to activate the synapse or not
ENDCOMMENT

VERBATIM
#ifndef NRN_VERSION_GTEQ_8_2_0
#include "nrnran123.h"
extern int cvode_active_;

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#ifndef CORENEURON_BUILD
double nrn_random_pick(void* r);
void* nrn_random_arg(int argpos);
#endif
#define RANDCAST
#else
#define RANDCAST (Rand*)
#endif

ENDVERBATIM
: ----------------------------------------------------------------
Expand All @@ -117,6 +124,10 @@ INITIAL {
if (cvode_active_ && !deterministic) {
hoc_execerror("StochKv2 with deterministic=0", "cannot be used with cvode");
}

if( usingR123 ) {
nrnran123_setseq((nrnran123_State*)_p_rng, 0, 0);
}
ENDVERBATIM

eta = (gkbar / gamma) * (10000)
Expand Down Expand Up @@ -273,11 +284,12 @@ PROCEDURE setRNG() {
VERBATIM
// For compatibility, allow for either MCellRan4 or Random123. Distinguish by the arg types
// Object => MCellRan4, seeds (double) => Random123
#if !NRNBBCORE
#ifndef CORENEURON_BUILD
usingR123 = 0;
if( ifarg(1) && hoc_is_double_arg(1) ) {
nrnran123_State** pv = (nrnran123_State**)(&_p_rng);
uint32_t a2 = 0;
uint32_t a3 = 0;

if (*pv) {
nrnran123_deletestream(*pv);
Expand All @@ -286,7 +298,10 @@ VERBATIM
if (ifarg(2)) {
a2 = (uint32_t)*getarg(2);
}
*pv = nrnran123_newstream((uint32_t)*getarg(1), a2);
if (ifarg(3)) {
a3 = (uint32_t)*getarg(3);
}
*pv = nrnran123_newstream3((uint32_t)*getarg(1), a2, a3);
usingR123 = 1;
} else if( ifarg(1) ) {
void** pv = (void**)(&_p_rng);
Expand All @@ -306,7 +321,9 @@ VERBATIM
if( usingR123 ) {
value = nrnran123_dblpick((nrnran123_State*)_p_rng);
} else if (_p_rng) {
value = nrn_random_pick(_p_rng);
#ifndef CORENEURON_BUILD
value = nrn_random_pick(RANDCAST _p_rng);
#endif
} else {
value = 0.5;
}
Expand All @@ -315,33 +332,40 @@ ENDVERBATIM
}

VERBATIM
/*
static void bbcore_write(double* x, int* d, int* xx, int* offset, _threadargsproto_) {
if (d) {
uint32_t* di = ((uint32_t*)d) + *offset;
// temporary just enough to see how much space is being used
if (!_p_rng) {
di[0] = 0; di[1] = 0;
di[0] = 0; di[1] = 0, di[2] = 0;
}else{
nrnran123_State** pv = (nrnran123_State**)(&_p_rng);
nrnran123_getids(*pv, di, di+1);
nrnran123_getids3(*pv, di, di+1, di+2);
// write stream sequence
char which;
nrnran123_getseq(*pv, di+3, &which);
di[4] = (int)which;
}
//printf("StochKv2.mod %p: bbcore_write offset=%d %d %d\n", _p, *offset, d?di[0]:-1, d?di[1]:-1);
//printf("StochKv3.mod %p: bbcore_write offset=%d %d %d\n", _p, *offset, d?di[0]:-1, d?di[1]:-1);
}
*offset += 2;
*offset += 5;
}
static void bbcore_read(double* x, int* d, int* xx, int* offset, _threadargsproto_) {
assert(!_p_rng);
uint32_t* di = ((uint32_t*)d) + *offset;
if (di[0] != 0 || di[1] != 0)
if (di[0] != 0 || di[1] != 0|| di[2] != 0)
{
nrnran123_State** pv = (nrnran123_State**)(&_p_rng);
*pv = nrnran123_newstream(di[0], di[1]);
#if !NRNBBCORE
if(*pv) {
nrnran123_deletestream(*pv);
}
#endif
*pv = nrnran123_newstream3(di[0], di[1], di[2]);
nrnran123_setseq(*pv, di[3], (char)di[4]);
}
//printf("StochKv2.mod %p: bbcore_read offset=%d %d %d\n", _p, *offset, di[0], di[1]);
*offset += 2;
//printf("StochKv3.mod %p: bbcore_read offset=%d %d %d\n", _p, *offset, di[0], di[1]);
*offset += 5;
}
*/
ENDVERBATIM

: Returns random numbers drawn from a binomial distribution
Expand Down Expand Up @@ -471,13 +495,16 @@ VERBATIM
FUNCTION bbsavestate() {
bbsavestate = 0
VERBATIM
#ifdef ENABLE_SAVE_STATE
#ifndef CORENEURON_BUILD
// TODO: since N0,N1 are no longer state variables, they will need to be written using this callback
// provided that it is the version that supports multivalue writing
/* first arg is direction (-1 get info, 0 save, 1 restore), second is value*/
double *xdir, *xval, *hoc_pgetarg();
double *xdir, *xval;
#ifndef NRN_VERSION_GTEQ_8_2_0
double *hoc_pgetarg();
long nrn_get_random_sequence(void* r);
void nrn_set_random_sequence(void* r, int val);
#endif
xdir = hoc_pgetarg(1);
xval = hoc_pgetarg(2);
if (_p_rng) {
Expand All @@ -498,13 +525,13 @@ VERBATIM
xval[0] = (double) seq;
xval[1] = (double) which;
} else {
xval[0] = (double)nrn_get_random_sequence(_p_rng);
xval[0] = (double)nrn_get_random_sequence(RANDCAST _p_rng);
}
} else{
if( usingR123 ) {
nrnran123_setseq( (nrnran123_State*)_p_rng, (uint32_t)xval[0], (char)xval[1] );
} else {
nrn_set_random_sequence(_p_rng, (long)(xval[0]));
nrn_set_random_sequence(RANDCAST _p_rng, (long)(xval[0]));
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions examples/sscx_sample_dir/mechanisms/VecStim.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COMMENT
* @brief
* @author king
* @date 2011-03-16
* @remark Copyright © BBP/EPFL 2005-2011; All rights reserved. Do not distribute without further notice.
* @remark Copyright © BBP/EPFL 2005-2011;
*/
ENDCOMMENT

Expand All @@ -28,6 +28,11 @@ ASSIGNED {


VERBATIM
#if defined(NRN_VERSION_GTEQ)
#if NRN_VERSION_GTEQ(9,0,0)
#define NRN_VERSION_GTEQ_9_0_0
#endif
#endif
#ifdef STIM_DEBUG
# define debug_printf(...) printf(__VA_ARGS__)
#else
Expand Down Expand Up @@ -95,17 +100,23 @@ VERBATIM
// Invoke low-level artcell_net_send, since generic NMODL net_send is only
// available in INITIAL and NET_RECEIVE blocks. It takes an ABSOLUTE time instead
debug_printf("[VecStim] restartEvent(delay=%g): index=%d, etime=%g, t=%g\n", delay, (int)index - 1, etime, t);
artcell_net_send(_tqitem, (double*)0, _ppvar[1]._pvoid, etime, 1.0);
#if defined(NRN_VERSION_GTEQ_9_0_0)
artcell_net_send(_tqitem, (double*)0, _ppvar[1].get<Point_process*>(), etime, 1.0);
#else
artcell_net_send(_tqitem, (double*)0, (Point_process*)_ppvar[1]._pvoid, etime, 1.0);
#endif
}
#endif
ENDVERBATIM
}


VERBATIM
#ifndef NRN_VERSION_GTEQ_8_2_0
extern double* vector_vec();
extern int vector_capacity();
extern void* vector_arg();
#endif
ENDVERBATIM


Expand All @@ -122,7 +133,8 @@ ENDCOMMENT
FUNCTION element() {
VERBATIM
const int i = (int)index;
void* const vv = *((void**)(&space));
IvocVect* const vv = *((IvocVect**)(&space));

int size; double* px;
if (i < 0 || vv == NULL)
return 0;
Expand Down
23 changes: 12 additions & 11 deletions examples/synplas_sample_dir/mechanisms/DetAMPANMDA.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COMMENT
* @brief Adapted from ProbAMPANMDA_EMS.mod by Eilif, Michael and Srikanth
* @author chindemi
* @date 2014-05-25
* @remark Copyright © BBP/EPFL 2005-2014; All rights reserved. Do not distribute without further notice.
* @remark Copyright © BBP/EPFL 2005-2014;
*/
ENDCOMMENT

Expand Down Expand Up @@ -62,11 +62,12 @@ VERBATIM

#ifndef CORENEURON_BUILD
extern int ifarg(int iarg);

#ifndef NRN_VERSION_GTEQ_8_2_0
extern void* vector_arg(int iarg);
extern double* vector_vec(void* vv);
extern int vector_capacity(void* vv);
#endif
#endif

ENDVERBATIM

Expand Down Expand Up @@ -175,8 +176,8 @@ NET_RECEIVE (weight, weight_AMPA, weight_NMDA, R, Pr, u, tsyn (ms), nc_type){
: }
VERBATIM
// setup self events for delayed connections to change weights
void *vv_delay_times = *((void**)(&_p_delay_times));
void *vv_delay_weights = *((void**)(&_p_delay_weights));
IvocVect *vv_delay_times = *((IvocVect**)(&_p_delay_times));
IvocVect *vv_delay_weights = *((IvocVect**)(&_p_delay_weights));
if (vv_delay_times && vector_capacity(vv_delay_times)>=1) {
double* deltm_el = vector_vec(vv_delay_times);
int delay_times_idx;
Expand Down Expand Up @@ -204,7 +205,7 @@ NET_RECEIVE (weight, weight_AMPA, weight_NMDA, R, Pr, u, tsyn (ms), nc_type){
: self event to set next weight at delay
VERBATIM
// setup self events for delayed connections to change weights
void *vv_delay_weights = *((void**)(&_p_delay_weights));
IvocVect *vv_delay_weights = *((IvocVect**)(&_p_delay_weights));
if (vv_delay_weights && vector_capacity(vv_delay_weights)>=next_delay) {
double* weights_v = vector_vec(vv_delay_weights);
double next_delay_weight = weights_v[(int)next_delay];
Expand Down Expand Up @@ -258,8 +259,8 @@ FUNCTION toggleVerbose() {
VERBATIM
static void bbcore_write(double* x, int* d, int* x_offset, int* d_offset, _threadargsproto_) {

void *vv_delay_times = *((void**)(&_p_delay_times));
void *vv_delay_weights = *((void**)(&_p_delay_weights));
IvocVect *vv_delay_times = *((IvocVect**)(&_p_delay_times));
IvocVect *vv_delay_weights = *((IvocVect**)(&_p_delay_weights));

// serialize connection delay vectors
if (vv_delay_times && vv_delay_weights &&
Expand Down Expand Up @@ -309,11 +310,11 @@ static void bbcore_read(double* x, int* d, int* x_offset, int* d_offset, _thread
double* x_i = x + *x_offset;

// allocate vectors
_p_delay_times = vector_new1(delay_times_sz);
_p_delay_weights = vector_new1(delay_weights_sz);
_p_delay_times = (double*)vector_new1(delay_times_sz);
_p_delay_weights = (double*)vector_new1(delay_weights_sz);

double* delay_times_el = vector_vec(_p_delay_times);
double* delay_weights_el = vector_vec(_p_delay_weights);
double* delay_times_el = vector_vec((IvocVect*)_p_delay_times);
double* delay_weights_el = vector_vec((IvocVect*)_p_delay_weights);

// copy data
int x_idx;
Expand Down
23 changes: 12 additions & 11 deletions examples/synplas_sample_dir/mechanisms/DetGABAAB.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COMMENT
* @brief Adapted from ProbGABAA_EMS.mod by Eilif, Michael and Srikanth
* @author chindemi
* @date 2014-05-25
* @remark Copyright © BBP/EPFL 2005-2014; All rights reserved. Do not distribute without further notice.
* @remark Copyright © BBP/EPFL 2005-2014;
*/
ENDCOMMENT

Expand Down Expand Up @@ -61,11 +61,12 @@ VERBATIM

#ifndef CORENEURON_BUILD
extern int ifarg(int iarg);

#ifndef NRN_VERSION_GTEQ_8_2_0
extern void* vector_arg(int iarg);
extern double* vector_vec(void* vv);
extern int vector_capacity(void* vv);
#endif
#endif

ENDVERBATIM

Expand Down Expand Up @@ -173,8 +174,8 @@ NET_RECEIVE (weight, weight_GABAA, weight_GABAB, R, Pr, u, tsyn (ms), nc_type){
: }
VERBATIM
// setup self events for delayed connections to change weights
void *vv_delay_times = *((void**)(&_p_delay_times));
void *vv_delay_weights = *((void**)(&_p_delay_weights));
IvocVect *vv_delay_times = *((IvocVect**)(&_p_delay_times));
IvocVect *vv_delay_weights = *((IvocVect**)(&_p_delay_weights));
if (vv_delay_times && vector_capacity(vv_delay_times)>=1) {
double* deltm_el = vector_vec(vv_delay_times);
int delay_times_idx;
Expand Down Expand Up @@ -202,7 +203,7 @@ NET_RECEIVE (weight, weight_GABAA, weight_GABAB, R, Pr, u, tsyn (ms), nc_type){
: self event to set next weight at delay
VERBATIM
// setup self events for delayed connections to change weights
void *vv_delay_weights = *((void**)(&_p_delay_weights));
IvocVect *vv_delay_weights = *((IvocVect**)(&_p_delay_weights));
if (vv_delay_weights && vector_capacity(vv_delay_weights)>=next_delay) {
double* weights_v = vector_vec(vv_delay_weights);
double next_delay_weight = weights_v[(int)next_delay];
Expand Down Expand Up @@ -256,8 +257,8 @@ FUNCTION toggleVerbose() {
VERBATIM
static void bbcore_write(double* x, int* d, int* x_offset, int* d_offset, _threadargsproto_) {

void *vv_delay_times = *((void**)(&_p_delay_times));
void *vv_delay_weights = *((void**)(&_p_delay_weights));
IvocVect *vv_delay_times = *((IvocVect**)(&_p_delay_times));
IvocVect *vv_delay_weights = *((IvocVect**)(&_p_delay_weights));

// serialize connection delay vectors
if (vv_delay_times && vv_delay_weights &&
Expand Down Expand Up @@ -307,11 +308,11 @@ static void bbcore_read(double* x, int* d, int* x_offset, int* d_offset, _thread
double* x_i = x + *x_offset;

// allocate vectors
_p_delay_times = vector_new1(delay_times_sz);
_p_delay_weights = vector_new1(delay_weights_sz);
_p_delay_times = (double*)vector_new1(delay_times_sz);
_p_delay_weights = (double*)vector_new1(delay_weights_sz);

double* delay_times_el = vector_vec(_p_delay_times);
double* delay_weights_el = vector_vec(_p_delay_weights);
double* delay_times_el = vector_vec((IvocVect*)_p_delay_times);
double* delay_weights_el = vector_vec((IvocVect*)_p_delay_weights);

// copy data
int x_idx;
Expand Down
Loading

0 comments on commit 614955f

Please sign in to comment.