Skip to content

Commit

Permalink
Merge pull request #100 from NeuralEnsemble/development
Browse files Browse the repository at this point in the history
For NML v2.1 release
  • Loading branch information
pgleeson committed Mar 22, 2021
2 parents 09f751f + dba03cf commit fc73ff0
Show file tree
Hide file tree
Showing 34 changed files with 5,453 additions and 1,232 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build

on:
push:
branches: [ master, development ]
pull_request:
branches: [ master, development ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.3.0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Build package
run: |
pip install .[full]
- name: Test with pytest
run: |
pytest
- name: Run examples
run: |
cd ./neuroml/examples && python run_all.py
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ neuroml/test/*.h5
/neuroml/examples/report.txt
/neuroml/examples/test_files/report.txt
/tests.log
/notebooks/.ipynb_checkpoints
/mongoo

.venv
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ addons:

matrix:
include:
- python: 3.7
dist: xenial
sudo: true
- python: 3.6
- python: 3.5
- python: 2.7
- python: 3.7
- python: 3.8
- python: 3.9

# command to install dependencies
install:
Expand All @@ -22,7 +20,7 @@ install:

# command to run tests and examples, e.g. python setup.py test
script:
- cd ./neuroml/test && nosetests -vs
- cd ./neuroml/test && pytest -v --strict -W all
- cd ../examples && python run_all.py

services: mongodb
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## Introduction

[![Travis CI](https://travis-ci.org/NeuralEnsemble/libNeuroML.svg?branch=master)](https://travis-ci.org/NeuralEnsemble/libNeuroML)
[![PyPI](https://img.shields.io/pypi/v/libNeuroML)](https://pypi.org/project/libNeuroML/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/libNeuroML)](https://pypi.org/project/libNeuroML/)
[![GitHub](https://img.shields.io/github/license/NeuralEnsemble/libNeuroML)](https://github.com/NeuralEnsemble/libNeuroML/blob/master/LICENSE)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/NeuralEnsemble/libNeuroML)](https://github.com/NeuralEnsemble/libNeuroML/pulls)
[![GitHub issues](https://img.shields.io/github/issues/NeuralEnsemble/libNeuroML)](https://github.com/NeuralEnsemble/libNeuroML/issues)
[![GitHub Org's stars](https://img.shields.io/github/stars/NeuralEnsemble?style=social)](https://github.com/NeuralEnsemble)
[![Twitter Follow](https://img.shields.io/twitter/follow/NeuroML?style=social)](https://twitter.com/NeuroML)

This package provides Python libNeuroML, for working with neuronal models specified in [NeuroML 2](http://neuroml.org/neuromlv2).

For more about libNeuroML see:
Expand Down Expand Up @@ -29,8 +38,11 @@ Most of the work happens in the [development branch](https://github.com/NeuralEn

## Changelog

### version 0.2.50
- Updated to use the final stable Schema for NeuroML v2.0
### version 0.2.54
- Using Schema for NeuroML v2.1. Better compatibility with Python 3

### version 0.2.50
- Updated to use the final stable Schema for NeuroML v2.0

### version 0.2.47
- Updated to use the final stable Schema for NeuroML v2beta5
Expand All @@ -44,7 +56,7 @@ Most of the work happens in the [development branch](https://github.com/NeuralEn

### version 0.2.2
- Updated to use the Schema for NeuroML v2beta3
- Ensures numpy & pytables are only required when using non-XML loaders/writers
- Ensures numpy & pytables are only required when using non-XML loaders/writers

### version 0.2.0
- Updated to use the Schema for NeuroML v2beta2
Expand All @@ -69,4 +81,3 @@ Most of the work happens in the [development branch](https://github.com/NeuralEn


[![Build Status](https://api.travis-ci.org/NeuralEnsemble/libNeuroML.png)](https://travis-ci.org/NeuralEnsemble/libNeuroML)

11 changes: 9 additions & 2 deletions doc/install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ If everything worked your output should look something like this:

OK

Alternatively install and use nosetests:
Alternatively install and use pytest:

::

nosetests -v
pytest -v --strict -W all


To ignore some tests, like the mongodb test which requres a mongodb setup, run:

::

pytest -v -k "not mongodb" --strict -W all
4 changes: 2 additions & 2 deletions neuroml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .nml.nml import * # allows importation of all neuroml classes

__version__ = '0.2.50'
__version__ = '0.2.55'
__version_info__ = tuple(int(i) for i in __version__.split('.'))


current_neuroml_version = "v2.0"
current_neuroml_version = "v2.1"
46 changes: 22 additions & 24 deletions neuroml/arraymorph.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
Prototype for object model backend for the libNeuroML project
"""

import math
import numpy as np
import numpy.ma as ma
import neuroml


class ArrayMorphology(neuroml.Morphology):
"""Core of the array-based object model backend.
Provides the core arrays - vertices,connectivity etc.
node_types.
node_types.
The connectivity array is a list of indices pointing to which
other element an element is attached. So for instance,
Expand All @@ -21,7 +19,7 @@ class ArrayMorphology(neuroml.Morphology):
- EXAMPLE:
Vertices[3] and connectivity[3] refer to the vertex
Vertices[3] and connectivity[3] refer to the vertex
and connectivity of the same node.
.. note::
Expand All @@ -43,7 +41,7 @@ def __init__(self,

self.connectivity = np.array(connectivity)
self.vertices = np.array(vertices)

self.id = id

if np.any(physical_mask):
Expand Down Expand Up @@ -94,8 +92,8 @@ def valid_ids(self):
valid_flag = (internal_id == external_id) * valid_flag

return valid_flag


@property
def __all_nodes_satisfied(self):
m = self.vertices.shape[0]
Expand All @@ -104,14 +102,14 @@ def __all_nodes_satisfied(self):

all_nodes_satisfied = (m == n == p)
return all_nodes_satisfied

@property
def root_index(self):
return np.where(self.connectivity == -1)[0][0]
return np.where(self.connectivity == -1)[0][0]

@property
def root_vertex(self):
return self.vertices[self.root_index]
return self.vertices[self.root_index]

@property
def num_vertices(self):
Expand All @@ -122,7 +120,7 @@ def physical_indices(self):
"""returns indices of vertices which are physical"""
physical_indices = np.where(self.physical_mask == 0)[0]
return physical_indices

def children(self,index):
"""Returns an array with indexes of children"""
return np.where(self.connectivity == index)
Expand All @@ -134,7 +132,7 @@ def to_root(self,index):
"""

old_root_index = self.root_index
new_root_index = index
new_root_index = index
#do a tree traversal:
parent_index = self.connectivity[index]
grandparent_index=self.connectivity[parent_index]
Expand All @@ -155,13 +153,13 @@ def vertex(self,index):

def __len__(self):
return len(self.connectivity)

def pop(self,index):
"""
TODO:This is failing tests (understandably) - need to fix!
Deletes a node from the morphology, its children become
children of the deleted node's parent.
"""
"""

self.vertices = np.delete(self.vertices,index)
self.node_types = np.delete(self.node_types,index)
Expand All @@ -188,16 +186,16 @@ def to_neuroml_morphology(self,id=""):

def segment_from_vertex_index(self,index):
parent_index = self.connectivity[index]

node_x = self.vertices[index][0]
node_y = self.vertices[index][1]
node_z = self.vertices[index][2]
node_d = self.vertices[index][3]

parent_x = self.vertices[parent_index][0]
parent_y = self.vertices[parent_index][1]
parent_z = self.vertices[parent_index][2]
parent_d = self.vertices[parent_index][3]
parent_d = self.vertices[parent_index][3]

p = neuroml.Point3DWithDiam(x=node_x,
y=node_y,
Expand All @@ -209,7 +207,7 @@ def segment_from_vertex_index(self,index):
z=parent_z,
diameter=parent_d)


seg = neuroml.Segment(proximal=p,
distal=d,
id=index)
Expand All @@ -218,7 +216,7 @@ def segment_from_vertex_index(self,index):
seg.parent = parent

return seg

class SegmentList(object):
"""
This class is a proxy, it returns a segment either
Expand Down Expand Up @@ -249,7 +247,7 @@ def __len__(self):
segments which is number of vertices - 1 and minus all
floating segments.
"""

num_vertices = self.arraymorph.num_vertices
num_floating = np.sum(self.arraymorph.physical_mask)
num_segments = num_vertices - num_floating -1
Expand Down Expand Up @@ -285,7 +283,7 @@ def append(self,segment):
"""
dist_vertex_index = len(self.arraymorph.vertices)
prox_vertex_index = dist_vertex_index + 1

prox_x = segment.proximal.x
prox_y = segment.proximal.y
prox_z = segment.proximal.z
Expand All @@ -295,7 +293,7 @@ def append(self,segment):
dist_y = segment.distal.y
dist_z = segment.distal.z
distal_diam = segment.distal.diameter

prox_vertex = [prox_x,prox_y,prox_z,prox_diam]
dist_vertex = [dist_x,dist_y,dist_z,distal_diam]

Expand All @@ -305,11 +303,11 @@ def append(self,segment):
self.arraymorph.vertices = np.array([dist_vertex,prox_vertex])

self.arraymorph.connectivity = np.append(self.arraymorph.connectivity,[-1,dist_vertex_index])

if len(self.arraymorph.physical_mask) == 0:
self.arraymorph.physical_mask = np.array([0,0])
else:
self.arraymorph.physical_mask = np.append(self.arraymorph.physical_mask,[1,0])

segment_index = len(self) - 1
self.instantiated_segments[segment_index] = segment
7 changes: 6 additions & 1 deletion neuroml/arraymorph_load_time_benchmark.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import numpy as np
import neuroml
import neuroml.arraymorph as am


class Benchmark:
def __init__(num_segments):
def __init__(self, num_segments):
self.num_segments = num_segments

def set_up(self):
Expand Down

0 comments on commit fc73ff0

Please sign in to comment.