Skip to content

Commit

Permalink
Potential fix related to: NEURON_MODULE_OPTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Jan 21, 2025
1 parent a583feb commit c67bad5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
18 changes: 13 additions & 5 deletions main_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ def __init__(self, tstop=100, dt=0.005, activity_file=None, verbose=True):
#from LEMS_c302_C1_Full_nrn import NeuronSimulation
#from LEMS_c302_nrn import NeuronSimulation

#import neuron
#self.h = neuron.h
print('Initialising C302NRNSimulation...')

self.tstop = tstop
self.verbose = verbose
Expand All @@ -164,14 +163,23 @@ def __init__(self, tstop=100, dt=0.005, activity_file=None, verbose=True):
#print_("Initialised C302NRNSimulation of length %s ms and dt = %s ms..."%(tstop,dt))

def set_timestep(self, dt):

print('Setting timestep...')

dt = float('{:0.1e}'.format(dt)) * 1000.0 # memory issue fix
from LEMS_c302_nrn import NeuronSimulation
import neuron
self.h = neuron.h

try:
from LEMS_c302_nrn import NeuronSimulation
import neuron
self.h = neuron.h
except Exception as e:
return 'Python import error: %s..'%e

self.ns = NeuronSimulation(self.tstop, dt)
print_("Initialised C302NRNSimulation of length %s ms and dt = %s ms..."%(self.tstop,dt))

return 'Success...' # for debugging...


def save_results(self):

Expand Down
3 changes: 2 additions & 1 deletion sibernetic_c302.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ def run(a=None,**kwargs):

env = { "DISPLAY": os.environ.get('DISPLAY') if os.environ.get('DISPLAY') is not None else '',
"XAUTHORITY": os.environ.get('XAUTHORITY') if os.environ.get('XAUTHORITY') is not None else '',
"PYTHONPATH": ".:%s:%s" % (os.environ.get('PYTHONPATH', '.'), os.path.abspath(sim_dir))}
"PYTHONPATH": ".:%s:%s" % (os.environ.get('PYTHONPATH', '.'), os.path.abspath(sim_dir)),
"NEURON_MODULE_OPTIONS": "-nogui"}

sim_start = time.time()

Expand Down
41 changes: 33 additions & 8 deletions src/owSignalSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,37 +80,62 @@ SignalSimulator::SignalSimulator(const std::string &simFileName,

// Import the file as a Python module.
pModule = PyImport_Import(pName);
std::cout << "1111" << std::endl;
std::cout << "1) Py module "<< s <<" imported..." << std::endl;
if (PyErr_Occurred())
PyErr_Print();

std::cout << "222" << std::endl;
PyObject *pModule2 = PyImport_Import(PyUnicode_FromString("sys"));
if (PyErr_Occurred())
PyErr_Print();


std::cout << "2) all good" << std::endl;
// Build the name of a callable class
if (pModule != nullptr) {
std::cout << "333" << std::endl;
std::cout << "3) class: " << simClassName << std::endl;
pClass = PyObject_GetAttrString(pModule, simClassName.c_str());
if (PyErr_Occurred())
PyErr_Print();
} else {

std::cout << "444" << std::endl;
std::cout << "4) Good..." << std::endl;
throw std::runtime_error("Python module not loaded, have you set "
"PYTHONPATH?\nTry: \n\n export "
"PYTHONPATH=$PYTHONPATH:./src\n");
}
std::cout << "555" << std::endl;
std::cout << "5) pClass: " << pClass << std::endl;
// Create an instance of the class
if (PyCallable_Check(pClass)) {
std::cout << "666" << std::endl;
std::cout << "6) callable.." << std::endl;

try {
pInstance = PyObject_CallObject(pClass, nullptr);
} catch (const std::exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
std::cout << "7) No error" << std::endl;
if (PyErr_Occurred())
{
std::cout << "errrr" << std::endl;
PyErr_Print();

}
PyObject *dt = Py_BuildValue("f", timeStep); // Create tuple of arguments for initialization
PyObject *pFuncName = Py_BuildValue("s", "set_timestep");
std::cout << "Calling " << pFuncName << std::endl;
//pInstance = PyObject_CallMethod(pInstance, "set_timestep", "(f)", timeStep);
PyObject_CallMethodObjArgs(pInstance, pFuncName, dt, nullptr);

std::cout << "777" << std::endl;
try {
PyObject *output = PyObject_CallMethodObjArgs(pInstance, pFuncName, dt, nullptr);
std::cout << "Here's the output: " << output << std::endl;

} catch (const std::exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}

std::cout << "8) Good..." << std::endl;
if (PyErr_Occurred())
PyErr_Print();
Py_DECREF(dt);
Expand Down

0 comments on commit c67bad5

Please sign in to comment.