Skip to content

Commit

Permalink
Removed dependence on CSA (#123)
Browse files Browse the repository at this point in the history
* new functions to create random connectivy matrices

* removed csa dependence

* travisCI not ready for 3.7....

* removed some commented out code
  • Loading branch information
espenhgn committed Feb 18, 2019
1 parent 2f49577 commit 8a4eb45
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
58 changes: 27 additions & 31 deletions LFPy/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
import numpy as np
import os
import scipy.stats as stats
import json
import h5py
from mpi4py import MPI
import neuron
from .templatecell import TemplateCell
import csa
import scipy.sparse as ss

# set up MPI environment
Expand Down Expand Up @@ -622,16 +620,12 @@ class defining a Cell-like object, see class NetworkCell
def get_connectivity_rand(self, pre='L5PC', post='L5PC', connprob = 0.2):
"""
Dummy function creating a (boolean) cell to cell connectivity matrix
between pre and postsynaptic populations relying on the use of the
'Connection Set Algebra (CSA)' implementation in Python; see
https://github.com/INCF/csa, Mikael Djurfeldt (2012) "The Connection-set
Algebra---A Novel Formalism for the Representation of Connectivity
Structure in Neuronal Network Models" Neuroinformatics 10(3), 1539-2791,
http://dx.doi.org/10.1007/s12021-012-9146-1
between pre and postsynaptic populations.
Connections are drawn randomly between presynaptic cell gids in
population 'pre' and postsynaptic cell gids in 'post' on this RANK with
a fixed connection probability.
a fixed connection probability. self-connections are disabled if
presynaptic and postsynaptic populations are the same.
Parameters
----------
Expand All @@ -650,30 +644,35 @@ def get_connectivity_rand(self, pre='L5PC', post='L5PC', connprob = 0.2):
with True denotes a connection.
"""
n_pre = self.populations[pre].POP_SIZE
n_post = self.populations[post].POP_SIZE

first_gid = self.populations[post].first_gid
gids = np.array(self.populations[post].gids).astype(int)

# first check if there are any postsyn cells on this RANK
if gids.size > 0:
# define incoming connections for cells on this RANK
C = np.random.rand(n_pre, gids.size) < connprob
if pre == post:
# avoid self connections
c = np.array([x for x in csa.cross(range(n_pre), range(gids.size)) *
(csa.random(connprob) - csa.oneToOne)])
else:
c = np.array([x for x in csa.cross(range(n_pre), range(gids.size)) *
csa.random(connprob)])
if c.ndim == 2:
# construct sparse boolean array
C = ss.csr_matrix((np.ones(c.shape[0], dtype=bool), (c[:, 0], c[:, 1])),
shape=(n_pre, gids.size), dtype=bool)
# avoid self connections.
gids_pre, gids_post = np.where(C)
gids_pre += self.populations[pre].first_gid
gids_post *= SIZE # asssume round-robin distribution of gids
gids_post += self.populations[post].gids[0]
inds = gids_pre == gids_post
gids_pre = gids_pre[inds == False]
gids_pre -= self.populations[pre].first_gid
gids_post = gids_post[inds == False]
gids_post -= self.populations[post].gids[0]
gids_post //= SIZE
c = np.c_[gids_pre, gids_post]
# create boolean matrix
C = ss.csr_matrix((np.ones(gids_pre.shape[0], dtype=bool),
(c[:, 0], c[:, 1])),
shape=(n_pre, gids.size), dtype=bool)
return C.toarray()
else:
return np.zeros((n_pre, gids.size), dtype=bool)
return C
else:
return np.zeros((n_pre, 0), dtype=bool)


def connect(self, pre, post, connectivity,
syntype=neuron.h.ExpSyn,
Expand Down Expand Up @@ -747,10 +746,6 @@ def connect(self, pre, post, connectivity,
# gids of presynaptic neurons:
pre_gids = np.arange(n0, n0 + self.populations[pre].POP_SIZE)

# global population sizes
n_pre = self.populations[pre].POP_SIZE
n_post = self.populations[post].POP_SIZE

# count connections and synapses made on this RANK
conncount = connectivity.astype(int).sum()
syncount = 0
Expand All @@ -763,6 +758,10 @@ def connect(self, pre, post, connectivity,
for i, (post_gid, cell) in enumerate(zip(self.populations[post].gids, self.populations[post].cells)):
# do NOT iterate over all possible presynaptic neurons
for pre_gid in pre_gids[connectivity[:, i]]:
# throw a warning if sender neuron is identical to receiving neuron
if post_gid == pre_gid:
print('connecting cell w. gid {} to itself (RANK {})'.format(post_gid, RANK))

# assess number of synapses
if multapsefun is None:
nidx = 1
Expand All @@ -775,8 +774,6 @@ def connect(self, pre, post, connectivity,
if j == 1000:
raise Exception('change multapseargs as no positive synapse count was found in 1000 trials')

# print('connecting cell {} to cell {} with {} synapses on RANK {}'.format(pre_gid, post_gid, nidx, RANK))

# find synapse locations and corresponding section names
idxs = cell.get_rand_idx_area_and_distribution_norm(nidx=nidx, **syn_pos_args)
secs = cell.get_idx_name(idxs)
Expand Down Expand Up @@ -857,7 +854,6 @@ def connect(self, pre, post, connectivity,
return COMM.bcast([conncount, syncount])



def simulate(self, electrode=None, rec_imem=False, rec_vmem=False,
rec_ipas=False, rec_icap=False,
rec_isyn=False, rec_vmemsyn=False, rec_istim=False,
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Cython>=0.20
h5py>=2.5
mpi4py>=1.2
matplotlib>=2.0
csa >= 0.1.8
# essential, not automatically installable:
# neuron>=7.6.4
# optional, for running tests:
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
'Cython>=0.20',
'h5py>=2.5',
'mpi4py>=1.2',
'csa>=0.1.8',
],
extras_require = {'tests': ['nose>=1.3.3']},
dependency_links = [],
Expand Down

0 comments on commit 8a4eb45

Please sign in to comment.