Skip to content

Commit c3fb9cd

Browse files
runmodels: add --norun option (#32)
* compile and link only
1 parent f0fae7d commit c3fb9cd

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

modeldb/commands.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def runmodels(args=None):
3535
--gout Include gout into the report. Note that gout data can be very big, so disabled by default.
3636
--virtual Run in headless mode. You need a back-end like Xvfb.
3737
--clean Auto-clean model working directory before running (useful for consecutive runs and failsafe)
38+
--norun Compile and link only (nrnivmodl).
3839
3940
Examples
4041
runmodels --workdir=/path/to/workdir # run all models
@@ -46,6 +47,7 @@ def runmodels(args=None):
4647
gout = options.pop("--gout", False)
4748
virtual = options.pop("--virtual", False)
4849
clean = options.pop("--clean", False)
50+
norun = options.pop("--norun", False)
4951

5052
if os.path.abspath(working_dir) == ROOT_DIR:
5153
print("Cannot run models directly into nrn-modeldb-ci ROOT_DIR -> {}".format(ROOT_DIR))
@@ -56,7 +58,7 @@ def runmodels(args=None):
5658
print("\tre-run with --clean if you wish to overwrite model runs!")
5759
sys.exit(1)
5860

59-
mrm = ModelRunManager(working_dir, gout=gout, clean=clean)
61+
mrm = ModelRunManager(working_dir, gout=gout, clean=clean, norun=norun)
6062
model_list = model_ids if model_ids else None
6163

6264
if virtual:

modeldb/modelrun.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def is_dir_non_empty(directory):
3232

3333

3434
class ModelRun(dict):
35-
def __init__(self, model, working_dir, clean=False):
35+
def __init__(self, model, working_dir, clean=False, norun=False):
3636
self._model = model
3737
self._working_dir = os.path.abspath(working_dir)
3838
self._logs = []
@@ -43,6 +43,7 @@ def __init__(self, model, working_dir, clean=False):
4343
self._run_time = 0
4444
self._run_py = False
4545
self._clean = clean
46+
self._norun = norun
4647

4748
self["run_info"] = {}
4849

@@ -63,6 +64,9 @@ def _fetch_model(self):
6364
else:
6465
self["run"] = ["verify_graph_()"]
6566

67+
if self._norun:
68+
self["norun"] = True
69+
6670
run_info = property(lambda self: self["run_info"])
6771

6872
logs = property(lambda self: self._logs)
@@ -244,21 +248,26 @@ def run_model(model):
244248
append_log(model, model.logs, traceback.format_exc())
245249

246250
# run NEURON
247-
try:
248-
nrn_exe = "./x86_64/special" if mods is not None and len(mods) else "nrniv"
249-
# '-nogui' creates segfault
250-
model_run_cmds = [nrn_exe, '-nobanner']
251-
if model.run_py:
252-
model_run_cmds.append('-python')
253-
model_run_cmds += [model.run_info["init"], model.run_info["driver"]]
254-
append_log(model, model.nrn_run, "RUNNING -> {}".format(" ".join(model_run_cmds)))
255-
run_neuron_cmds(model, model_run_cmds)
256-
if os.path.isfile(os.path.join(model.model_dir, "gout")):
257-
with open(os.path.join(model.model_dir, "gout"), 'r') as gout:
258-
model._gout = gout.readlines()
259-
except Exception: # noqa
260-
append_log(model, model.nrn_run, traceback.format_exc())
261-
model._nrn_run_error = True
251+
if "norun" in model:
252+
append_log(model, model.logs,
253+
"Model is not run due to --norun option"
254+
)
255+
else:
256+
try:
257+
nrn_exe = "./x86_64/special" if mods is not None and len(mods) else "nrniv"
258+
# '-nogui' creates segfault
259+
model_run_cmds = [nrn_exe, '-nobanner']
260+
if model.run_py:
261+
model_run_cmds.append('-python')
262+
model_run_cmds += [model.run_info["init"], model.run_info["driver"]]
263+
append_log(model, model.nrn_run, "RUNNING -> {}".format(" ".join(model_run_cmds)))
264+
run_neuron_cmds(model, model_run_cmds)
265+
if os.path.isfile(os.path.join(model.model_dir, "gout")):
266+
with open(os.path.join(model.model_dir, "gout"), 'r') as gout:
267+
model._gout = gout.readlines()
268+
except Exception: # noqa
269+
append_log(model, model.nrn_run, traceback.format_exc())
270+
model._nrn_run_error = True
262271

263272
stop_time = time.perf_counter()
264273

@@ -268,7 +277,7 @@ def run_model(model):
268277

269278

270279
class ModelRunManager(object):
271-
def __init__(self, master_dir, gout=False, clean=False):
280+
def __init__(self, master_dir, gout=False, clean=False, norun=False):
272281
self.master_dir = master_dir
273282
self.logfile = str(master_dir) + ".log"
274283
self.dumpfile = str(master_dir) + ".json"
@@ -279,6 +288,7 @@ def __init__(self, master_dir, gout=False, clean=False):
279288
self.run_logs = {}
280289
self._gout = gout
281290
self._clean = clean
291+
self._norun = norun
282292

283293
def _setup_logging(self):
284294
self.logger = logging.getLogger("dev")
@@ -400,7 +410,7 @@ def run_models(self, model_list=None):
400410

401411
# prepare ModelRun objects
402412
models_to_run = (
403-
ModelRun(mdl, self.master_dir, self._clean) for mdl in models_selected
413+
ModelRun(mdl, self.master_dir, self._clean, self._norun) for mdl in models_selected
404414
)
405415

406416
# number of models

0 commit comments

Comments
 (0)