Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Load mod files after compile #20

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions emodel_generalisation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,10 @@
# pylint: disable=line-too-long
import logging
import os
from pathlib import Path

os.environ["NEURON_MODULE_OPTIONS"] = "-nogui"
logger = logging.getLogger(__name__)

_TMPDIR = os.environ.get("TMPDIR", None)
if _TMPDIR is not None:
try:
import neuron

if (Path(_TMPDIR) / "x86_64").exists():
if not neuron.load_mechanisms(_TMPDIR):
raise Exception("Could not load mod files")
except Exception as exc: # pylint: disable=broad-exception-caught
logger.debug("Could not load mod files from %s because of %s", _TMPDIR, exc)
os.environ["DASK_TEMPORARY_DIRECTORY"] = _TMPDIR


PARAM_LABELS = {
# passive
Expand Down
16 changes: 16 additions & 0 deletions emodel_generalisation/model/nexus_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from copy import copy
from pathlib import Path

import neuron
from tqdm import tqdm

L = logging.getLogger(__name__)
Expand Down Expand Up @@ -197,6 +198,19 @@ def convert_all_config(config_path, out_config_folder="config", mech_path="mecha
json.dump(final, final_file, indent=4)


def load_mechanisms():
"""Load mechanisms if present in TMPDIR."""
_TMPDIR = os.environ.get("TMPDIR", None)
if _TMPDIR is not None:
try:
if (Path(_TMPDIR) / "x86_64").exists():
if not neuron.load_mechanisms(_TMPDIR):
raise Exception("Could not load mod files")
except Exception as exc: # pylint: disable=broad-exception-caught
L.debug("Could not load mod files from %s because of %s", _TMPDIR, exc)
os.environ["DASK_TEMPORARY_DIRECTORY"] = _TMPDIR


def compile_mechanisms(mech_path="mechanisms", compiled_mech_path=None):
"""Compile mechanisms in custom location."""
if compiled_mech_path is None:
Expand All @@ -208,3 +222,5 @@ def compile_mechanisms(mech_path="mechanisms", compiled_mech_path=None):
os.chdir(compiled_mech_path)
subprocess.run(f"nrnivmodl {mech_path}", shell=True, check=True)
os.chdir(cwd)
# load mechs after compile
load_mechanisms()