Skip to content

Commit

Permalink
Remove SynapseReader.mod and SynReaderNRN (#122)
Browse files Browse the repository at this point in the history
## Context
After removing BlueConfig, we only support SONATA edges files loaded via
`libsonata` API. This PR removes the synpase loaders that were used to
support non-SONATA files.

## Scope
Remove `SynapseReader.mod`. 
In `synapse_reader.py`, remove class `SynReaderNRN` which was used to
load non-SONATA .h5 files via `HDF5Reader`.

## Testing
Remove the test for `SynReaderNRN`

## Review
* [x] PR description is complete
* [x] Coding style (imports, function length, New functions, classes or
files) are good
* [ ] Unit/Scientific test added
* [x] Updated Readme, in-code, developer documentation
  • Loading branch information
WeinaJi authored Feb 9, 2024
1 parent 9113be2 commit 6bb2fa7
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 267 deletions.
79 changes: 0 additions & 79 deletions core/mod/SynapseReader.mod

This file was deleted.

1 change: 0 additions & 1 deletion core/mod/coreneuron_modlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ netstim_inhpoisson.mod
SonataReportHelper.mod
SonataReports.mod
SpikeWriter.mod
SynapseReader.mod
VecStim.mod
3 changes: 1 addition & 2 deletions docs/api/subpackages/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ neurodamus.io.synapse\_reader
.. autosummary::
SynapseParameters
SynapseReader
SynReaderNRN

SonataReader

.. rubric:: Exceptions

Expand Down
23 changes: 9 additions & 14 deletions neurodamus/connection_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .core import run_only_rank0
from .core.configuration import GlobalConfig, SimConfig, ConfigurationError, find_input_file
from .connection import Connection, ReplayMode
from .io.sonata_config import ConnectionTypes
from .io.synapse_reader import SynapseReader
from .target_manager import TargetManager, TargetSpec
from .utils import compat, bin_search, dict_filter_map
Expand Down Expand Up @@ -286,18 +287,16 @@ def __str__(self):
def open_edge_location(self, syn_source, circuit_conf, **kw):
edge_file, *pop = syn_source.split(":")
pop_name = pop[0] if pop else None
n_files = circuit_conf.get("NumSynapseFiles")
src_pop_id = _get_projection_population_id(circuit_conf)
return self.open_synapse_file(edge_file, pop_name, n_files, src_pop_id=src_pop_id, **kw)
return self.open_synapse_file(edge_file, pop_name, src_pop_id=src_pop_id, **kw)

def open_synapse_file(self, synapse_file, edge_population, n_files=1, *,
src_pop_id=None, src_name=None, **_kw):
def open_synapse_file(self, synapse_file, edge_population, *, src_pop_id=None, src_name=None,
**_kw):
"""Initializes a reader for Synapses config objects and associated population
Args:
synapse_file: The nrn/edge file. For old nrn files it may be a dir.
edge_population: The population of the edges
n_files: (nrn only) the number of nrn files in the directory (without nrn.h5)
src_pop_id: (compat) Allow overriding the src population ID
src_name: The source pop name, normally matching that of the source cell manager
"""
Expand All @@ -307,11 +306,9 @@ def open_synapse_file(self, synapse_file, edge_population, n_files=1, *,
if not ospath.exists(synapse_file):
raise ConfigurationError("Connectivity (Edge) file not found: {}".format(synapse_file))
if ospath.isdir(synapse_file):
logging.warning("Edges source is a directory (legacy nrn.h5 only)")
if ospath.isfile(ospath.join(synapse_file, "nrn.h5")):
n_files = 1
raise ConfigurationError("Edges source is a directory")

self._synapse_reader = self._open_synapse_file(synapse_file, edge_population, n_files)
self._synapse_reader = self._open_synapse_file(synapse_file, edge_population)
if self._load_offsets:
if not self._synapse_reader.has_property("synapse_index"):
raise Exception("Synapse offsets required but not available. "
Expand All @@ -322,12 +319,10 @@ def open_synapse_file(self, synapse_file, edge_population, n_files=1, *,
return synapse_file

# - override if needed
def _open_synapse_file(self, synapse_file, pop_name, n_nrn_files=None):
def _open_synapse_file(self, synapse_file, pop_name):
logging.debug("Opening Synapse file %s, population: %s", synapse_file, pop_name)
return self.SynapseReader.create(
synapse_file, self.CONNECTIONS_TYPE, pop_name,
n_nrn_files, self._raw_gids, # Used eventually by NRN reader
extracellular_calcium=SimConfig.extracellular_calcium
synapse_file, pop_name, extracellular_calcium=SimConfig.extracellular_calcium
)

def _init_conn_population(self, src_pop_name, pop_id_override):
Expand Down Expand Up @@ -1202,7 +1197,7 @@ class SynapseRuleManager(ConnectionManagerBase):
created.
"""

CONNECTIONS_TYPE = SynapseReader.SYNAPSES
CONNECTIONS_TYPE = ConnectionTypes.Synaptic

def __init__(self, circuit_conf, target_manager, cell_manager, src_cell_manager=None, **kw):
"""Initializes a Connection/Edge manager for standard METype synapses
Expand Down
30 changes: 4 additions & 26 deletions neurodamus/gap_junction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
Main module for handling and instantiating synaptical connections
"""
from __future__ import absolute_import
import logging
import numpy as np
from os import path as ospath

from .connection_manager import ConnectionManagerBase
from .core.configuration import ConfigurationError
from .io.synapse_reader import SynapseReader, SynReaderNRN, SonataReader, SynapseParameters, \
FormatNotSupported
from .io.sonata_config import ConnectionTypes
from .io.synapse_reader import SonataReader, SynapseParameters
from .utils import compat
from .utils.logging import log_verbose

Expand All @@ -25,28 +24,7 @@ def create_array(cls, length):
return npa


class GapJunctionSynapseReader(SynapseReader):
""" Derived from SynapseReader, used for reading GapJunction synapses.
Factory create() will attempt to instantiate GapJunctionSynToolReader,
followed by SynReaderNRN.
"""

@classmethod
def create(cls, syn_src, conn_type, population=None, *args, **kw):
"""Instantiates a synapse reader, giving preference to GapJunctionSynToolReader
"""
if fn := cls._get_sonata_circuit(syn_src):
log_verbose("[SynReader] Using SonataReader.")
return GapJunctionSonataReader(fn, conn_type, population, **kw)

# Syn2 support dropped (July 2023)
if not ospath.isdir(syn_src) and not syn_src.endswith(".h5"):
raise FormatNotSupported("File: {syn_src}")
logging.info("[GapJunctionSynReader] Attempting legacy hdf5 reader.")
return SynReaderNRN(syn_src, conn_type, None, *args, **kw)


class GapJunctionSonataReader(SonataReader):
class GapJunctionSynapseReader(SonataReader):
Parameters = GapJunctionConnParameters
parameter_mapping = {
"weight": "conductance",
Expand All @@ -64,7 +42,7 @@ class GapJunctionManager(ConnectionManagerBase):
The user will have the capacity to scale the conductance weights.
"""

CONNECTIONS_TYPE = SynapseReader.GAP_JUNCTIONS
CONNECTIONS_TYPE = ConnectionTypes.GapJunction
_gj_offsets = None
SynapseReader = GapJunctionSynapseReader

Expand Down
23 changes: 16 additions & 7 deletions neurodamus/io/sonata_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
import libsonata
import logging
import os.path
from enum import StrEnum


class ConnectionTypes(StrEnum):
Synaptic = "Synaptic"
GapJunction = "GapJunction"
NeuroModulation = "NeuroModulation"
NeuroGlial = "NeuroGlial"
GlioVascular = "GlioVascular"


class SonataConfig:
Expand Down Expand Up @@ -289,11 +298,11 @@ def make_circuit(nodes_file, node_pop_name, population_info):
@property
def parsedProjections(self):
projection_type_convert = dict(
chemical="Synaptic",
electrical="GapJunction",
synapse_astrocyte="NeuroGlial",
endfoot="GlioVascular",
neuromodulatory="NeuroModulation"
chemical=ConnectionTypes.Synaptic,
electrical=ConnectionTypes.GapJunction,
synapse_astrocyte=ConnectionTypes.NeuroGlial,
endfoot=ConnectionTypes.GlioVascular,
neuromodulatory=ConnectionTypes.NeuroModulation
)
internal_edge_pops = set(c_conf["nrnPath"] for c_conf in self._bc_circuits.values())
projections = {}
Expand Down Expand Up @@ -323,10 +332,10 @@ def parsedProjections(self):
Type=projection_type_convert.get(pop_type)
)
# Reverse projection direction for Astrocyte projection: from neurons to astrocytes
if projection.get("Type") == "NeuroGlial":
if projection.get("Type") == ConnectionTypes.NeuroGlial:
projection["Source"], projection["Destination"] = projection["Destination"], \
projection["Source"]
if projection.get("Type") == "GlioVascular":
if projection.get("Type") == ConnectionTypes.GlioVascular:
for node_file_info in self._circuit_networks["nodes"]:
for _, pop_info in node_file_info["populations"].items():
if pop_info.get("type") == "vasculature":
Expand Down
Loading

0 comments on commit 6bb2fa7

Please sign in to comment.