Skip to content

Commit

Permalink
fix docs, remove Cell_V5
Browse files Browse the repository at this point in the history
  • Loading branch information
WeinaJi committed Feb 1, 2024
1 parent fea86c6 commit b33c0ef
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 148 deletions.
5 changes: 1 addition & 4 deletions docs/api/subpackages/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ neurodamus.io.cell\_readers

.. autosummary::

load_mvd3
load_ncs
load_nodes_mvd3
load_combo_metypes
load_sonata
split_round_robin

.. rubric:: Exceptions
Expand Down
4 changes: 2 additions & 2 deletions docs/architecture.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ BBP v6 circuits would define its own cell hoc templates (/classes, one for each
based on Cell.hoc.

Morphologically detailed neurons are the heart of a Neuron simulation. Neurodamus will read the
cells metadata from a node file (start.ncs, circuit.mvd3 or nodes.h5 sonata) and instantiate each
cells metadata from a node file in SONATA format and instantiate each
individual cell by:

- loading the morphology and instantiate the respective sections
Expand Down Expand Up @@ -138,7 +138,7 @@ Due to extensively different logic, both these cell types inherit directly from
must be handled by their own cell manager classes. To these modules implementing a new `Cell`,
`CellManagers` and eventually `ConnectionManager` types we call **Engine** - more on this later.

For the record, `Cell_V5/V6` and the corresponding `CellDistributor` and `SynapseRuleManager`
For the record, `Cell_V6` and the corresponding `CellDistributor` and `SynapseRuleManager`
were also made components of a special engine: the `METypeEngine`, obviously built-in (find it
in node.py).

Expand Down
2 changes: 1 addition & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Dry run mode
~~~~~~~~~~~~
In order to obtain a more accurate estimation of the resources needed for a simulation,
users can also run Neurodamus in dry run mode. This functionality is only available
for libsonata circuits. MVD3 circuits are not supported.
for SONATA circuits.

This mode will partially instantiate cells and synapses to get a statistical overview
of the memory used but won't run the actual simulation.
Expand Down
6 changes: 2 additions & 4 deletions neurodamus/cell_distributor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from .core.nodeset import NodeSet
from .io import cell_readers
from .lfp_manager import LFPManager
from .metype import Cell_V5, Cell_V6, EmptyCell
from .metype import Cell_V6, EmptyCell
from .target_manager import TargetSpec
from .utils import compat
from .utils.logging import log_verbose, log_all
Expand Down Expand Up @@ -523,8 +523,6 @@ def _init_config(self, circuit_conf, _pop):
if not circuit_conf.CellLibraryFile:
raise ConfigurationError("CellLibraryFile not set")

# self._is_v5_circuit alwaysFalse for sonata

super()._init_config(circuit_conf, _pop)

def load_nodes(self, load_balancer=None, **kw):
Expand Down Expand Up @@ -553,7 +551,7 @@ def _instantiate_cells(self, dry_run_stats_obj: DryRunStats = None, **opts):
if self.CellType is not NotImplemented:
return super()._instantiate_cells(self.CellType)
conf = self._circuit_conf
CellType = Cell_V5 if self._is_v5_circuit else Cell_V6
CellType = Cell_V6
if conf.MorphologyType:
CellType.morpho_extension = conf.MorphologyType

Expand Down
56 changes: 2 additions & 54 deletions neurodamus/io/cell_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from os import path as ospath

from ..core import NeurodamusCore as Nd
from ..core.configuration import ConfigurationError, SimConfig
from ..core.configuration import SimConfig
from ..core import run_only_rank0
from ..metype import METypeManager, METypeItem
from ..metype import METypeManager
from ..utils.logging import log_verbose

EMPTY_GIDVEC = np.empty(0, dtype="uint32")
Expand Down Expand Up @@ -198,58 +198,6 @@ def validate_property(prop_name):
return gidvec, meinfos, fullsize


def load_combo_metypes(combo_file, gidvec, combo_list, morph_list):
""" Read file with mecombo info, retaining only those that are local to this node
Args:
combo_file: Path to the combo file to read metype info from
gidvec: local gids to load info about
combo_list: comboList Combos corresponding to local gids
morph_list: morphList Morpholgies corresponding to local gids
"""
if not combo_file:
logging.error("Missing BlueConfig field 'MEComboInfoFile' which has gid:mtype:emodel.")
raise ConfigurationError("MEComboInfoFile not specified")

# Optimization: index combos
combo_ids = defaultdict(list)
for i, c in enumerate(combo_list):
combo_ids[c].append(i)

log_verbose("Loading emodel+additional info from Combo f %s", combo_file)
f = open(combo_file)
next(f) # Skip Header

me_manager = METypeManager()
for tstr in f:
vals = tstr.strip().split()
if len(vals) not in (6, 8):
wmsg = ("Could not parse line %s from MEComboInfoFile %s."
"Expecting 6 (hippocampus) or 8 (somatosensory) fields")
logging.warning(wmsg, tstr, combo_file)

# metypes may be reused by several cells
# We create a single item and later assign to each matching gid
meitem = METypeItem(*vals)
for i in combo_ids[meitem.combo_name]:
if morph_list[i] == meitem.morph_name:
me_manager[int(gidvec[i])] = meitem

# confirm that all gids have been matched.
# Otherwise, print combo + morph info to help finding issues
nerr = 0
for gid in gidvec:
gid = int(gid)
if gid not in me_manager:
logging.error("MEComboInfoFile: No MEInfo for gid %d", gid)
nerr += 1
if nerr > 0:
logging.error("gidvec: " + str(gidvec))
logging.error("Memap: " + str(me_manager.gids))
raise CellReaderError("Errors found during processing of mecombo file. See log")

return me_manager


def _getNeededAttributes(node_reader, etype_path, emodels, gidvec):
"""
Read additional attributes required by emodel templates global var <emodel>__NeededAttributes
Expand Down
81 changes: 0 additions & 81 deletions neurodamus/metype.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,87 +195,6 @@ def __getattr__(self, item):
return prop


class Cell_V5(METype):
__slots__ = ('_rng_list',)

def __init__(self, gid, meinfo, circuit_conf):
# In NCS, meinfo is simply the metype filename (string)
mepath = circuit_conf.METypePath
morpho_path = circuit_conf.MorphologyPath
if isinstance(meinfo, METypeItem):
meinfo = meinfo.emodel_tpl # Compat with loading V5 cells from Sonata Nodes
melabel = self._load_template(meinfo, mepath)
super().__init__(gid, mepath, melabel, morpho_path)

def _instantiate_cell(self, gid, _etype_path, emodel, morpho_path, _meinfos, _axon):
"""Instantiates a cell v5 or older. Assumes emodel hoc templates are loaded
"""
EModel = getattr(Nd, emodel)
logging.debug("Loading Gid %d: emodel: %s", gid, emodel)
try:
# For this step, do not call mpi_abort in neuron and let neurodamus handle and abort,
# NB: Do not re-raise as ConfigurationError, neurodamus doesn't call mpi_abort so hangs
old_flag = Nd.pc.mpiabort_on_error(0)
self._ccell = ccell = EModel(gid, morpho_path)
Nd.pc.mpiabort_on_error(old_flag)
except Exception as e:
raise Exception("Error when loading Gid %d: emodel: %s, morpho_path: %s"
% (gid, emodel, morpho_path)) from e
self._cellref = ccell.CellRef
self._synapses = ccell.CellRef.synlist
self._syn_helper_list = ccell.CellRef.synHelperList
self._threshold_current = ccell.getThreshold()
try:
self._hypAmp_current = ccell.getHypAmp()
except Exception:
pass

def re_init_rng(self, ion_seed):
if not hasattr(self._ccell, "re_init_rng"):
return # dont apply on cells without re_init_rng func
rng = SimConfig.rng_info
rng_mode = rng.getRNGMode()

if rng_mode == rng.COMPATIBILITY:
return super().re_init_rng(ion_seed)
if rng_mode == rng.RANDOM123:
Nd.rng123ForStochKvInit(self._ccell)
return
# otherwise rng_mode is mcellran4
self._rng_list = Nd.rngForStochKvInit(self._ccell)
gid = self._cellref.gid
if gid > 400000:
logging.warning("mcellran4 cannot initialize properly with large gids: %d", gid)

@staticmethod
def _load_template(tpl_filename, tpl_location=None):
"""Helper function which loads the template into NEURON and returns its name.
The actual template name will have any hyphens (e.g.: R-C261296A-P1_repaired)
replaced with underscores as hyphens must not appear in template names.
Args:
tpl_filename: the template file to load
tpl_location: (Optional) path for the templates
Returns:
The name of the template as it appears inside the file (sans hyphens)
"""
# start.ncs gives metype names with hyphens, but the templates themselves
# have those hyphens replaced with underscores.
tpl_path = ospath.join(tpl_location, tpl_filename) \
if tpl_location else tpl_filename

# first open the file manually to get the hoc template name
tpl_name = None
with open(tpl_path + ".hoc", "r") as templateReader:
for line in templateReader:
line = line.strip()
if line.startswith("begintemplate"):
tpl_name = line.split()[1]
break
Nd.load_hoc(tpl_path)
return tpl_name


class EmptyCell(BaseCell):
"""
Class representing an empty cell, e.g. an artificial cell
Expand Down
2 changes: 0 additions & 2 deletions tests/scientific/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

assert os.environ.get("NEURODAMUS_NEOCORTEX_ROOT"), \
"Test requires loading a neocortex model to run"
assert os.path.isfile("/gpfs/bbp.cscs.ch/project/proj83/circuits/Bio_M/20200805/circuit.mvd3"), \
"Circuit file not available"

pytestmark = [
pytest.mark.forked,
Expand Down

0 comments on commit b33c0ef

Please sign in to comment.