Skip to content

Commit 7757643

Browse files
author
Dilawar Singh
committed
test commit [skip ci]
1 parent cb8a970 commit 7757643

File tree

6 files changed

+118
-60
lines changed

6 files changed

+118
-60
lines changed

basecode/Cinfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class Cinfo {
2020
/**
2121
* The Cinfo intializer is used for static initialization
2222
* of all the MOOSE Cinfos. Each MOOSE class must set up
23-
* a function to build its Cinfo. This function must be * called statically in the MOOSE class .cpp file.
23+
* a function to build its Cinfo. This function must be
24+
* called statically in the MOOSE class .cpp file.
2425
* Note how it takes the base *Cinfo as an argument. This
2526
* lets us call the base Cinfo initializer when making
2627
* each Cinfo class, thus ensuring the correct static

pybind11/helper.cpp

Lines changed: 84 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,31 @@
1414
//
1515
// =====================================================================================
1616

17-
#include <stdexcept>
1817
#include <memory>
18+
#include <stdexcept>
1919

20+
#include "../external/pybind11/include/pybind11/functional.h"
21+
#include "../external/pybind11/include/pybind11/numpy.h"
2022
#include "../external/pybind11/include/pybind11/pybind11.h"
2123
#include "../external/pybind11/include/pybind11/stl.h"
22-
#include "../external/pybind11/include/pybind11/numpy.h"
23-
#include "../external/pybind11/include/pybind11/functional.h"
2424

2525
// See
2626
// https://pybind11.readthedocs.io/en/stable/advanced/cast/stl.html#binding-stl-containers
2727
// #include "../external/pybind11/include/pybind11/stl_bind.h"
2828

29-
#include "../basecode/header.h"
30-
#include "../basecode/global.h"
31-
#include "../basecode/Cinfo.h"
29+
#include "../randnum/randnum.h"
3230

31+
#include "../basecode/Cinfo.h"
32+
#include "../builtins/Variable.h"
33+
#include "../mpi/PostMaster.h"
34+
#include "../scheduling/Clock.h"
35+
#include "../shell/Neutral.h"
3336
#include "../shell/Shell.h"
3437
#include "../shell/Wildcard.h"
35-
#include "../shell/Neutral.h"
36-
37-
#include "../scheduling/Clock.h"
38-
#include "../mpi/PostMaster.h"
39-
40-
#include "../builtins/Variable.h"
41-
4238
#include "../utility/strutil.h"
4339

44-
#include "helper.h"
4540
#include "Finfo.h"
41+
#include "helper.h"
4642
#include "pymoose.h"
4743

4844
using namespace std;
@@ -109,7 +105,8 @@ ObjId createIdFromPath(string path, string type, unsigned int numData)
109105
if (pos != string::npos) {
110106
name = trimmed_path.substr(pos + 1);
111107
parent_path = trimmed_path.substr(0, pos);
112-
} else {
108+
}
109+
else {
113110
name = trimmed_path;
114111
}
115112
// handle relative path
@@ -119,7 +116,8 @@ ObjId createIdFromPath(string path, string type, unsigned int numData)
119116
parent_path = current_path + "/" + parent_path;
120117
else
121118
parent_path = current_path + parent_path;
122-
} else if (parent_path.empty())
119+
}
120+
else if (parent_path.empty())
123121
parent_path = "/";
124122

125123
ObjId parent_id(parent_path);
@@ -168,7 +166,8 @@ ObjId loadModelInternal(const string& fname, const string& modelpath,
168166
Id model;
169167
if (solverclass.empty()) {
170168
model = getShellPtr()->doLoadModel(fname, modelpath);
171-
} else {
169+
}
170+
else {
172171
model = getShellPtr()->doLoadModel(fname, modelpath, solverclass);
173172
}
174173

@@ -205,8 +204,8 @@ ObjId getElementFieldItem(const ObjId& objid, const string& fname,
205204
index += len;
206205
}
207206
if (index < 0) {
208-
throw runtime_error("ElementField.getItem: invalid index: " +
209-
to_string(index) + ".");
207+
throw runtime_error(
208+
"ElementField.getItem: invalid index: " + to_string(index) + ".");
210209
return ObjId();
211210
}
212211
return ObjId(oid.id, oid.dataIndex, index);
@@ -230,20 +229,14 @@ ObjId shellConnect(const ObjId& src, const string& srcField, const ObjId& tgt,
230229
// // return src.connect(srcField, tgt, tgtField, msgType);
231230
//}
232231

233-
bool mooseDelete(const ObjId& oid)
234-
{
235-
return getShellPtr()->doDelete(oid);
236-
}
232+
bool mooseDelete(const ObjId& oid) { return getShellPtr()->doDelete(oid); }
237233

238234
bool mooseDelete(const string& path)
239235
{
240236
return getShellPtr()->doDelete(ObjId(path));
241237
}
242238

243-
void mooseMoveId(const Id& a, const ObjId& b)
244-
{
245-
getShellPtr()->doMove(a, b);
246-
}
239+
void mooseMoveId(const Id& a, const ObjId& b) { getShellPtr()->doMove(a, b); }
247240

248241
void mooseMoveObjId(const ObjId& a, const ObjId& b)
249242
{
@@ -254,7 +247,7 @@ ObjId mooseCreate(const string type, const string& path, unsigned int numdata)
254247
{
255248
auto newpath = moose::normalizePath(path);
256249
auto p = moose::splitPath(newpath);
257-
if( ! mooseExists(p.first))
250+
if (!mooseExists(p.first))
258251
throw runtime_error("Parent path " + p.first + " does not exists.");
259252
return getShellPtr()->doCreate2(type, ObjId(p.first), p.second, numdata);
260253
}
@@ -276,10 +269,7 @@ void mooseUseClock(size_t tick, const string& path, const string& field)
276269
* @Returns cwe.
277270
*/
278271
/* ----------------------------------------------------------------------------*/
279-
py::object mooseGetCwe()
280-
{
281-
return py::cast(getShellPtr()->getCwe());
282-
}
272+
py::object mooseGetCwe() { return py::cast(getShellPtr()->getCwe()); }
283273

284274
map<string, string> mooseGetFieldDict(const string& className,
285275
const string& finfoType = "")
@@ -304,28 +294,33 @@ map<string, string> mooseGetFieldDict(const string& className,
304294
auto* finfo = cinfo->getValueFinfo(ii);
305295
fieldDict[finfo->name()] = finfo->rttiType();
306296
}
307-
} else if (finfoType == "srcFinfo" || finfoType == "src") {
297+
}
298+
else if (finfoType == "srcFinfo" || finfoType == "src") {
308299
for (unsigned int ii = 0; ii < cinfo->getNumSrcFinfo(); ++ii) {
309300
auto* finfo = cinfo->getSrcFinfo(ii);
310301
fieldDict[finfo->name()] = finfo->rttiType();
311302
}
312-
} else if (finfoType == "destFinfo" || finfoType == "dest") {
303+
}
304+
else if (finfoType == "destFinfo" || finfoType == "dest") {
313305
for (unsigned int ii = 0; ii < cinfo->getNumDestFinfo(); ++ii) {
314306
auto* finfo = cinfo->getDestFinfo(ii);
315307
fieldDict[finfo->name()] = finfo->rttiType();
316308
}
317-
} else if (finfoType == "lookupFinfo" || finfoType == "lookup") {
309+
}
310+
else if (finfoType == "lookupFinfo" || finfoType == "lookup") {
318311
for (unsigned int ii = 0; ii < cinfo->getNumLookupFinfo(); ++ii) {
319312
auto* finfo = cinfo->getLookupFinfo(ii);
320313
fieldDict[finfo->name()] = finfo->rttiType();
321314
}
322-
} else if (finfoType == "sharedFinfo" || finfoType == "shared") {
315+
}
316+
else if (finfoType == "sharedFinfo" || finfoType == "shared") {
323317
for (unsigned int ii = 0; ii < cinfo->getNumSrcFinfo(); ++ii) {
324318
auto* finfo = cinfo->getSrcFinfo(ii);
325319
fieldDict[finfo->name()] = finfo->rttiType();
326320
}
327-
} else if (finfoType == "fieldElementFinfo" || finfoType == "field" ||
328-
finfoType == "fieldElement") {
321+
}
322+
else if (finfoType == "fieldElementFinfo" || finfoType == "field" ||
323+
finfoType == "fieldElement") {
329324
for (unsigned int ii = 0; ii < cinfo->getNumFieldElementFinfo(); ++ii) {
330325
auto* finfo = cinfo->getFieldElementFinfo(ii);
331326
fieldDict[finfo->name()] = finfo->rttiType();
@@ -334,10 +329,7 @@ map<string, string> mooseGetFieldDict(const string& className,
334329
return fieldDict;
335330
}
336331

337-
void mooseReinit()
338-
{
339-
getShellPtr()->doReinit();
340-
}
332+
void mooseReinit() { getShellPtr()->doReinit(); }
341333

342334
void mooseStart(double runtime, bool notify = false)
343335
{
@@ -353,3 +345,53 @@ ObjId mooseCopy(const py::object& elem, ObjId newParent, string newName,
353345
copyExtMsgs));
354346
}
355347

348+
/**
349+
Return a vector of field names of specified finfo type. This is from Subha.
350+
*/
351+
vector<string> mooseGetFieldNames(string className, string finfoType)
352+
{
353+
vector<string> ret;
354+
const Cinfo* cinfo = Cinfo::find(className);
355+
if (cinfo == NULL) {
356+
cerr << "Invalid class name." << endl;
357+
return ret;
358+
}
359+
360+
if (finfoType == "valueFinfo" || finfoType == "value") {
361+
for (unsigned int ii = 0; ii < cinfo->getNumValueFinfo(); ++ii) {
362+
Finfo* finfo = cinfo->getValueFinfo(ii);
363+
ret.push_back(finfo->name());
364+
}
365+
}
366+
else if (finfoType == "srcFinfo" || finfoType == "src") {
367+
for (unsigned int ii = 0; ii < cinfo->getNumSrcFinfo(); ++ii) {
368+
Finfo* finfo = cinfo->getSrcFinfo(ii);
369+
ret.push_back(finfo->name());
370+
}
371+
}
372+
else if (finfoType == "destFinfo" || finfoType == "dest") {
373+
for (unsigned int ii = 0; ii < cinfo->getNumDestFinfo(); ++ii) {
374+
Finfo* finfo = cinfo->getDestFinfo(ii);
375+
ret.push_back(finfo->name());
376+
}
377+
}
378+
else if (finfoType == "lookupFinfo" || finfoType == "lookup") {
379+
for (unsigned int ii = 0; ii < cinfo->getNumLookupFinfo(); ++ii) {
380+
Finfo* finfo = cinfo->getLookupFinfo(ii);
381+
ret.push_back(finfo->name());
382+
}
383+
}
384+
else if (finfoType == "sharedFinfo" || finfoType == "shared") {
385+
for (unsigned int ii = 0; ii < cinfo->getNumSrcFinfo(); ++ii) {
386+
Finfo* finfo = cinfo->getSrcFinfo(ii);
387+
ret.push_back(finfo->name());
388+
}
389+
}
390+
else if (finfoType == "fieldElementFinfo" || finfoType == "fieldElement") {
391+
for (unsigned int ii = 0; ii < cinfo->getNumFieldElementFinfo(); ++ii) {
392+
Finfo* finfo = cinfo->getFieldElementFinfo(ii);
393+
ret.push_back(finfo->name());
394+
}
395+
}
396+
return ret;
397+
}

pybind11/helper.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ ObjId shellConnect(const ObjId& src, const string& srcField, const ObjId& tgt,
5050
bool mooseDelete(const ObjId& oid);
5151
bool mooseDelete(const string& path);
5252

53-
ObjId mooseCreate(const string type, const string& path, unsigned int numdata = 1);
53+
ObjId mooseCreate(const string type, const string& path,
54+
unsigned int numdata = 1);
5455

5556
ObjId mooseCopy(const py::object& orig, ObjId newParent, string newName,
5657
unsigned int n, bool toGlobal, bool copyExtMsgs);
@@ -61,6 +62,9 @@ void mooseSetClock(const unsigned int clockId, double dt);
6162

6263
void mooseUseClock(size_t tick, const string& path, const string& field);
6364

65+
vector<string> mooseGetFieldNames(const string& className,
66+
const string& finfoType);
67+
6468
map<string, string> mooseGetFieldDict(const string& className,
6569
const string& finfoType);
6670

pybind11/pymoose.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ PYBIND11_MODULE(_cmoose, m)
331331
m.def("setClock", &mooseSetClock);
332332
m.def("useClock", &mooseUseClock);
333333
m.def("loadModelInternal", &loadModelInternal);
334+
m.def("getFieldNames", &mooseGetFieldNames);
334335
m.def("getField",
335336
[](const ObjId &oid, const string &fieldName, const string &ftype) {
336337
// ftype is not needed anymore.

tests/py_moose/test_moose_attribs.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@
1616
attribs = ['AdExIF', 'AdThreshIF', 'Adaptor', 'Annotator', 'Arith', 'BufPool',
1717
'CaConc', 'CaConcBase', 'ChanBase', 'ChemCompt', 'Cinfo', 'Clock',
1818
'Compartment', 'CompartmentBase', 'ConcChan', 'CplxEnzBase', 'CubeMesh',
19-
'CylMesh', 'DestField', 'DiagonalMsg', 'DifBuffer', 'DifBufferBase',
20-
'DifShell', 'DifShellBase', 'DiffAmp', 'Dsolve', 'ElementField',
21-
'EndoMesh', 'Enz', 'EnzBase', 'ExIF', 'Finfo', 'Function',
19+
'CylMesh'
20+
# , 'DestField'
21+
, 'DiagonalMsg', 'DifBuffer', 'DifBufferBase',
22+
'DifShell', 'DifShellBase', 'DiffAmp', 'Dsolve'
23+
# , 'ElementField'
24+
, 'EndoMesh', 'Enz', 'EnzBase', 'ExIF', 'Finfo', 'Function',
2225
'GapJunction', 'GraupnerBrunel2012CaPlasticitySynHandler', 'Group',
2326
'Gsolve', 'HHChannel', 'HHChannel2D', 'HHChannelBase', 'HHGate',
24-
'HHGate2D', 'HSolve', 'INFINITE', 'IntFire', 'IntFireBase', 'Interpol',
25-
'Interpol2D', 'IzhIF', 'IzhikevichNrn', 'Ksolve', 'LIF', 'Leakage',
26-
'LookupField', 'MMPump', 'MMenz', 'MarkovChannel' ,
27+
'HHGate2D', 'HSolve'
28+
# , 'INFINITE'
29+
, 'IntFire', 'IntFireBase', 'Interpol',
30+
'Interpol2D', 'IzhIF', 'IzhikevichNrn', 'Ksolve', 'LIF', 'Leakage'
31+
#, 'LookupField'
32+
, 'MMPump', 'MMenz', 'MarkovChannel' ,
2733
'MarkovOdeSolver',
2834
'MarkovRateTable', 'MarkovSolver', 'MarkovSolverBase', 'MeshEntry',
2935
'MgBlock', 'Msg', 'Mstring', 'NMDAChan', 'Nernst', 'NeuroMesh',
@@ -35,21 +41,25 @@
3541
'Species', 'SpikeGen', 'SpikeStats', 'Spine', 'SpineMesh', 'Stats',
3642
'SteadyState', 'StimulusTable', 'Stoich', 'Streamer',
3743
'SymCompartment', 'SynChan', 'SynHandlerBase', 'Synapse', 'Table',
38-
'Table2', 'TableBase', 'TimeTable', 'VClamp', 'VERSION', 'Variable',
44+
'Table2', 'TableBase', 'TimeTable', 'VClamp', '__version__', 'Variable',
3945
'VectorTable', 'ZombieBufPool', 'ZombieCaConc', 'ZombieCompartment',
4046
'ZombieEnz', 'ZombieFunction', 'ZombieHHChannel', 'ZombieMMenz',
41-
'ZombiePool', 'ZombieReac', '_moose',
42-
'ce', 'chemMerge',
43-
'chemUtil', 'closing', 'connect', 'copy', 'delete', 'division', 'doc',
47+
'ZombiePool', 'ZombieReac', '_cmoose',
48+
'chemMerge',
49+
'chemUtil', 'connect', 'copy', 'delete', 'division', 'doc',
4450
'element', 'exists', 'finfotypes', 'fixXreacs', 'genesis', 'getCwe',
45-
'getField', 'getFieldDict', 'getFieldNames', 'getFieldDoc', 'isRunning',
46-
'le', 'listmsg', 'loadModelInternal', 'melement',
47-
'mergeChemModel', 'moose',
51+
'getField', 'getFieldDict'
52+
, 'getFieldNames'
53+
, 'getFieldDoc'
54+
#, 'isRunning',
55+
, 'le', 'listmsg', 'loadModelInternal'
56+
# , 'melement'
57+
, 'mergeChemModel', 'moose',
4858
'mooseAddChemSolver', 'mooseDeleteChemSolver', 'mooseReadNML2',
4959
'mooseReadSBML', 'mooseWriteKkit', 'mooseWriteNML2', 'mooseWriteSBML',
5060
'moose_constants', 'moose_test', 'move', 'nml2Import_', 'print_utils',
5161
'pwe', 'pydoc', 'rand', 'reinit',
52-
'seed', 'setClock', 'setCwe', 'showfield',
62+
'seed', 'setClock' , 'setCwe', 'showfield',
5363
'showfields', 'showmsg', 'start', 'stop', 'syncDataHandler',
5464
'test', 'testSched', 'useClock', 'utils', 'vec', 'version',
5565
'warnings', 'wildcardFind']
@@ -58,7 +68,7 @@ def test_attribs():
5868
global attribs
5969
for at in attribs:
6070
print( "\tTesting for attrib %s" % at )
61-
assert hasattr( moose, at ), 'Attrib %s not found' % at
71+
assert hasattr( moose, at ), '%s not found' % at
6272

6373
if __name__ == '__main__':
6474
test_attribs()

tests/support/test_sbml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_sbml():
3131
moose.start(200)
3232
# TODO: Add more tests here.
3333
p = moose.wildcardFind( '/sbml/##' )
34-
assert len(p) == 8
34+
assert len(p) == 8, p
3535
names = ['compartment', 'mesh', 'S1', 'info', 'S2', 'info', 'reaction1']
3636
for x in p:
3737
assert x.name in names

0 commit comments

Comments
 (0)