Skip to content

Commit 516c841

Browse files
Merge pull request #746 from sanjayankur31/feat/show-neuroml-import-error
Show neuroml import error on failure, increase memory for jvm
2 parents 86cc427 + b553349 commit 516c841

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

netpyne_ui/helpers/neuroml.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import sys
33
import logging
44
from netpyne.specs import simConfig
5+
from packaging import version
56

7+
import pyneuroml
68
from pyneuroml import pynml
79
from pyneuroml.lems import generate_lems_file_for_neuroml
810
from pyneuroml.pynml import read_neuroml2_file
@@ -13,57 +15,67 @@
1315
def convertLEMSSimulation(lemsFileName, compileMod=True):
1416
"""Converts a LEMS Simulation file
1517
16-
Converts a LEMS Simulation file (https://docs.neuroml.org/Userdocs/LEMSSimulation.html)
17-
pointing to a NeuroML 2 file into the equivalent in NetPyNE
18+
Converts a LEMS Simulation file
19+
(https://docs.neuroml.org/Userdocs/LEMSSimulation.html) pointing to a
20+
NeuroML 2 file into the equivalent in NetPyNE
21+
1822
Returns:
1923
simConfig, netParams for the model in NetPyNE
2024
"""
2125
current_path = os.getcwd()
2226
try:
23-
27+
2428
fullLemsFileName = os.path.abspath(lemsFileName)
25-
tmp_path = os.path.dirname(fullLemsFileName)
29+
tmp_path = os.path.dirname(fullLemsFileName)
2630
if tmp_path:
2731
os.chdir(tmp_path)
2832
logging.info(
2933
"Importing LEMSSimulation with NeuroML 2 network from: %s"
3034
% fullLemsFileName
3135
)
3236

33-
result = pynml.run_lems_with_jneuroml_netpyne(
34-
lemsFileName, only_generate_json=True, exit_on_fail=False)
35-
36-
if result == False:
37-
raise Exception("Error loading lems file")
37+
# feature to return output added in 1.0.9
38+
if version.parse(pyneuroml.__version__) >= version.parse("1.0.9"):
39+
result, output_msg = pynml.run_lems_with_jneuroml_netpyne(
40+
lemsFileName, only_generate_json=True, exit_on_fail=False,
41+
return_string=True, max_memory="1G")
42+
43+
if result is False:
44+
raise Exception(f"Error loading lems file: {output_msg}")
45+
else:
46+
result = pynml.run_lems_with_jneuroml_netpyne(
47+
lemsFileName, only_generate_json=True, exit_on_fail=False,
48+
max_memory="1G")
49+
50+
if result is False:
51+
raise Exception("Error loading lems file")
52+
3853
lems = pynml.read_lems_file(lemsFileName)
3954

4055
np_json_fname = fullLemsFileName.replace('.xml','_netpyne_data.json')
41-
56+
4257
return np_json_fname
4358
finally:
4459
os.chdir(current_path)
4560

4661

47-
48-
4962
def convertNeuroML2(nml2FileName, compileMod=True):
5063
"""Loads a NeuroML 2 file into NetPyNE
5164
Loads a NeuroML 2 file into NetPyNE by creating a new LEMS Simulation
52-
file (https://docs.neuroml.org/Userdocs/LEMSSimulation.html) and using jNeuroML
53-
to convert it.
65+
file (https://docs.neuroml.org/Userdocs/LEMSSimulation.html) and using
66+
jNeuroML to convert it.
5467
5568
Returns:
5669
simConfig, netParams for the model in NetPyNE
5770
"""
5871
current_path = os.getcwd()
5972
try:
6073
fullNmlFileName = os.path.abspath(nml2FileName)
61-
work_path = os.path.dirname(fullNmlFileName)
74+
work_path = os.path.dirname(fullNmlFileName)
6275
if not os.path.exists(work_path):
6376
os.makedirs(work_path)
6477
os.chdir(work_path)
6578
sys.path.append(work_path)
66-
6779

6880
logging.info(
6981
"Importing NeuroML 2 network from: %s"

0 commit comments

Comments
 (0)