Skip to content

Commit b68a97b

Browse files
author
Dilawar Singh
committed
SynapseTest is also passing.
1 parent 8f2a039 commit b68a97b

File tree

5 files changed

+51
-37
lines changed

5 files changed

+51
-37
lines changed

pybind11/Finfo.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,24 @@ __Finfo__::__Finfo__(const ObjId& oid, const Finfo* f, const string& finfoType)
2929
{
3030
// cout << " __Finfo__ type " << finfoType << endl;
3131

32-
if(finfoType == "DestFinfo")
32+
if (finfoType == "DestFinfo")
3333
func_ = [oid, f, this](const py::object& key) {
3434
return getLookupValueFinfoItem(oid, f, key);
3535
};
36-
else if(finfoType == "FieldElementFinfo")
36+
else if (finfoType == "FieldElementFinfo")
3737
func_ = [oid, f, this](const py::object& index) {
3838
// this is essential of make this function static.
3939
return getElementFinfoItem(oid, f, py::cast<unsigned int>(index));
4040
};
41-
else if(finfoType == "LookupValueFinfo")
41+
else if (finfoType == "LookupValueFinfo")
4242
func_ = [oid, f, this](const py::object& key) {
4343
// Assigning is essential or make these functions static.
4444
return this->getLookupValueFinfoItem(oid, f, key);
4545
};
4646
else
4747
func_ = [this](const py::object& key) {
48-
throw runtime_error("Not supported for Finfo type '"+finfoType_+"'");
48+
throw runtime_error("Not supported for Finfo type '" + finfoType_ +
49+
"'");
4950
return py::none();
5051
};
5152
}
@@ -84,7 +85,8 @@ bool __Finfo__::setLookupValueFinfoItem(const ObjId& oid, const py::object& key,
8485
return true;
8586
}
8687

87-
py::object __Finfo__::getLookupValueFinfoItem(const ObjId& oid, const Finfo* f, const py::object& key)
88+
py::object __Finfo__::getLookupValueFinfoItem(const ObjId& oid, const Finfo* f,
89+
const py::object& key)
8890
{
8991
auto rttType = f->rttiType();
9092
auto fname = f->name();
@@ -130,8 +132,7 @@ py::cpp_function __Finfo__::getDestFinfoSetterFunc(const ObjId& oid,
130132
vector<string> types;
131133
moose::tokenize(rttType, ",", types);
132134

133-
if (types.size() == 1)
134-
return getDestFinfoSetterFunc1(oid, finfo, types[0]);
135+
if (types.size() == 1) return getDestFinfoSetterFunc1(oid, finfo, types[0]);
135136

136137
assert(types.size() == 2);
137138
return getDestFinfoSetterFunc2(oid, finfo, types[0], types[1]);
@@ -147,11 +148,18 @@ py::cpp_function __Finfo__::getDestFinfoSetterFunc2(const ObjId& oid,
147148
if (ftype1 == "double") {
148149
if (ftype2 == "unsigned int") {
149150
std::function<bool(double, unsigned int)> func = [oid, fname](
150-
const double a, const long b) {
151+
const double a, const unsigned int b) {
151152
return SetGet2<double, unsigned int>::set(oid, fname, a, b);
152153
};
153154
return func;
154155
}
156+
if (ftype2 == "long") {
157+
std::function<bool(double, long)> func = [oid, fname](
158+
const double a, const long b) {
159+
return SetGet2<double, long>::set(oid, fname, a, b);
160+
};
161+
return func;
162+
}
155163
}
156164
throw runtime_error("getFieldPropertyDestFinfo2::NotImplemented " + fname +
157165
" for rttType " + finfo->rttiType() + " for oid " +
@@ -251,10 +259,11 @@ py::list __Finfo__::getElementFinfo(const ObjId& objid, const Finfo* f)
251259
return py::cast(res);
252260
}
253261

254-
py::object __Finfo__::getElementFinfoItem(const ObjId& oid, const Finfo* f, unsigned int index)
262+
py::object __Finfo__::getElementFinfoItem(const ObjId& oid, const Finfo* f,
263+
unsigned int index)
255264
{
256265
// cout << "Fetching at index " << index << " " << getNumField() << endl ;
257-
if(index >= getNumFieldStatic(oid, f)) {
266+
if (index >= getNumFieldStatic(oid, f)) {
258267
throw py::index_error("Index " + to_string(index) + " out of range.");
259268
}
260269
auto o = ObjId(oid.path() + '/' + f->name());
@@ -268,18 +277,17 @@ string __Finfo__::type() const
268277

269278
// py::object __Finfo__::getAttr(const string& key)
270279
// {
271-
// std::cout << "Accessing " << key << std::endl;
280+
// std::cout << "Accessing " << key << std::endl;
272281
// }
273282

274-
unsigned int __Finfo__::getNumField()
283+
unsigned int __Finfo__::getNumField()
275284
{
276285
return __Finfo__::getNumFieldStatic(oid_, f_);
277286
}
278287

279-
unsigned int __Finfo__::getNumFieldStatic(const ObjId& oid, const Finfo* f)
288+
unsigned int __Finfo__::getNumFieldStatic(const ObjId& oid, const Finfo* f)
280289
{
281290
auto o = ObjId(oid.path() + '/' + f->name());
282291
return Field<unsigned int>::get(o, "numField");
283292
}
284293

285-

pybind11/MooseVec.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ ObjId MooseVec::getItem(const size_t i) const
6464

6565
void MooseVec::setAttrOneToAll(const string& name, const py::object& val)
6666
{
67-
setFieldGeneric(oid_, name, val);
67+
for(size_t i = 0; i < size(); i++)
68+
setFieldGeneric(getItem(i), name, val);
6869
}
6970

7071
void MooseVec::setAttrOneToOne(const string& name, const py::sequence& val)

shell/Shell.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ ObjId Shell::doAddMsg(const string& msgType, ObjId src, const string& srcField,
284284
}
285285

286286
const Msg* m = innerAddMsg(msgType, src, srcField, dest, destField, 0);
287-
cout << "Msg " << m << " mid:" << m->mid() << endl;
288287

289288
SetGet6<string, ObjId, string, ObjId, string, unsigned int>::set(
290289
ObjId(), // Apply command to Shell
@@ -387,9 +386,7 @@ void Shell::doMove(Id orig, ObjId newParent)
387386
warning(ss.str());
388387
return;
389388
}
390-
391389
SetGet2<Id, ObjId>::set(ObjId(), "move", orig, newParent);
392-
// innerMove( orig, newParent );
393390
}
394391

395392
bool extractIndex(const string& s, unsigned int& index)

tests/py_moose/test_GraupnerBrunel2012_STDPfromCaPlasticity.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ def test_GB2012_STDP():
3939
# ###########################################
4040

4141
## two neurons: index 0 will be presynaptic, 1 will be postsynaptic
42-
network = moose.vec(moose.LIF( 'network', 2 ))
42+
network = moose.LIF( 'network', 2 );
4343
moose.le( '/network' )
44-
print(network)
45-
network.Em = Vrest
46-
network.thresh = Vt_base
47-
network.refractoryPeriod = refrT
48-
network.Rm = R
49-
network.vReset = Vreset
50-
network.Cm = tau/R
51-
network.inject = 0.
52-
network.initVm = Vrest
44+
network.vec.Em = Vrest
45+
assert np.allclose(network.vec.Em, Vrest), (network.vec.Em, Vrest)
46+
network.vec.thresh = Vt_base
47+
network.vec.refractoryPeriod = refrT
48+
network.vec.Rm = R
49+
network.vec.vReset = Vreset
50+
network.vec.Cm = tau/R
51+
network.vec.inject = 0.
52+
network.vec.initVm = Vrest
5353

5454
tauCa = 20e-3
5555
tauSyn = 150.0
@@ -65,13 +65,11 @@ def test_GB2012_STDP():
6565
bistable = True
6666

6767
syn = moose.GraupnerBrunel2012CaPlasticitySynHandler( '/network/syn' )
68-
print(dir(syn))
6968
syn.numSynapses = 1
70-
assert syn.numSynapses == 1, syn.numSynapses
7169
moose.connect( syn, 'activationOut', network.vec[1], 'activation' )
7270

7371
# synapse from presynaptic neuron
74-
moose.connect( network.vec[0], 'spikeOut', syn.synapse[0], 'addSpike')
72+
moose.connect( network.vec[0],'spikeOut', syn.synapse[0], 'addSpike')
7573

7674
# post-synaptic spikes also needed for STDP
7775
moose.connect( network.vec[1], 'spikeOut', syn, 'addPostSpike')
@@ -100,9 +98,9 @@ def test_GB2012_STDP():
10098
# Setting up tables
10199
# ###########################################
102100

103-
Vms = moose.vec(moose.Table( '/plotVms', 2))
101+
Vms = moose.Table( '/plotVms', 2 )
104102
moose.connect( network, 'VmOut', Vms, 'input', 'OneToOne')
105-
spikes = moose.vec(moose.Table( '/plotSpikes', 2))
103+
spikes = moose.Table( '/plotSpikes', 2 )
106104
moose.connect( network, 'spikeOut', spikes, 'input', 'OneToOne')
107105
CaTable = moose.Table( '/plotCa', 1 )
108106
moose.connect( CaTable, 'requestOut', syn, 'getCa')
@@ -190,15 +188,15 @@ def make_neuron_spike(nrnidx,I=1e-7,duration=1e-3):
190188
print(('pre before post, dt = %1.3f s, dw/w = %1.3f'%(deltat,dw)))
191189
dwlist_pos.append(dw)
192190

193-
Vmseries0 = Vms[0].vector
191+
Vmseries0 = Vms.vec[0].vector
194192
numsteps = len(Vmseries0)
195193

196-
for t in spikes[0].vector:
194+
for t in spikes.vec[0].vector:
197195
Vmseries0[int(t/dt)-1] = 30e-3 # V
198196

199-
Vmseries1 = Vms[1].vector
197+
Vmseries1 = Vms.vec[1].vector
200198

201-
for t in spikes[1].vector:
199+
for t in spikes.vec[1].vector:
202200
Vmseries1[int(t/dt)-1] = 30e-3 # V
203201

204202
timeseries = np.linspace(0.,200*numsteps*dt,numsteps)

tests/py_moose/test_vec.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import moose
3+
import numpy as np
34

45
def test_vec():
56
foo = moose.Pool('/foo1', 500)
@@ -20,7 +21,16 @@ def test_vec2():
2021
assert iaf[5].Vm == 5, iaf[5].Vm
2122
print(iaf.Vm)
2223

24+
def test_vec3():
25+
print("test vec3")
26+
foo = moose.Pool('/foo1', 500)
27+
foo.vec.concInit = 0.123
28+
print(foo.vec)
29+
assert foo.concInit == 0.123, foo.concInit
30+
assert np.allclose(foo.vec.concInit, [0.123]*500)
31+
2332

2433
if __name__ == '__main__':
2534
test_vec()
2635
test_vec2()
36+
test_vec3()

0 commit comments

Comments
 (0)