Skip to content

Commit

Permalink
Merge pull request #8 from SpiNNakerManchester/test_base
Browse files Browse the repository at this point in the history
Moved Integeration tests out of Spynakker
  • Loading branch information
rowleya authored Feb 23, 2021
2 parents 9e5caa4 + 942dbe0 commit 7e2ff0d
Show file tree
Hide file tree
Showing 14 changed files with 261 additions and 221 deletions.
89 changes: 85 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,95 @@
# Cortical microcircuit simulation: PyNN version
_Stored for easy access for people within the organisation_

**Contributors:**
Sacha van Albada ([email protected])
Maximilian Schmidt
Jannis Schücker
**Contributors:**
Sacha van Albada ([email protected])
Maximilian Schmidt
Jannis Schücker
Andrew Rowley
Alan Stokes

This is an implementation of the multi-layer microcircuit model of early
sensory cortex published by Potjans and Diesmann (2014) _The cell-type specific
cortical microcircuit: relating structure and activity in a full-scale spiking
network model_. Cerebral Cortex 24 (3): 785-806, [doi:10.1093/cercor/bhs358](https://doi.org/10.1093/cercor/bhs358)

It has been run on three different back-ends: NEST, SpiNNaker, and the ESS (emulator of HMF)

# Instructions

1. Ensure you have the desired back-end.

For SpiNNaker see https://spinnakermanchester.github.io/latest/spynnaker.html

For NEST see http://www.nest-initiative.org/index.php/Software:Download
and to enable full-scale simulation, compile it with MPI support
(use the --with-mpi option when configuring) according to the instructions on
http://www.nest-initiative.org/index.php/Software:Installation

2. Install PyNN according to the instructions on
http://neuralensemble.org/docs/PyNN/installation.html

3. Run the simulation by typing ```python run_microcircuit.py <simulator>``` in
your terminal in the folder containing this file, where ```<simulator>``` is one
of ```nest``` or ```spinnaker``` (by default ```spinnaker is selected```). There
are several potential arguments which can be seen by typing
```python run_microcircuit.py <simulator> -h```. A few useful ones include:

- --sim_duration - The simulation duration in milliseconds (default 1000)
- --output_path - Where output files should be written (default results)

6. Output files and basic analysis:

- Spikes are written to .txt files containing IDs of the recorded neurons
and corresponding spike times in ms.
Separate files are written out for each population and virtual process.
File names are formed as 'spikes'+ layer + population + MPI process + .txt
- Voltages are written to .dat files containing GIDs, times in ms, and the
corresponding membrane potentials in mV. File names are formed as
voltmeter label + layer index + population index + spike detector GID +
virtual process + .dat

- If 'plot_spiking_activity' is set to True, a raster plot and bar plot
of the firing rates are created and saved as 'spiking_activity.png'


The simulation was successfully tested with NEST revision 10711 and MPI 1.4.3.
Plotting works with Python 2.6.6 including packages numpy 1.3.0,
matplotlib 0.99.1.1, and glob.

## Known issues:

- At least with PyNN 0.7.5 and NEST revision 10711, ConnectWithoutMultapses
works correctly on a single process, but not with multiple MPI processes.

- When saving connections to file, ensure that pyNN does not create problems
with single or nonexistent connections, for instance by adjusting
lib/python2.6/site-packages/pyNN/nest/__init__.py from line 365 as follows:

if numpy.size(lines) != 0:
if numpy.shape(numpy.shape(lines))[0] == 1:
lines = numpy.array([lines])
lines[:,2] *= 0.001
if compatible_output:
lines[:,0] = self.pre.id_to_index(lines[:,0])
lines[:,1] = self.post.id_to_index(lines[:,1])
file.write(lines, {'pre' : self.pre.label, 'post' : self.post.label})

- To use saveConnections in parallel simulations, additionally ensure that
pyNN does not cause a race condition where the directory is created by one
process between the if statement and makedirs on another process: In
lib/python2.6/site-packages/pyNN/recording/files.py for instance replace

os.makedirs(dir)

by

try:
os.makedirs(dir)
except OSError, e:
if e.errno != 17:
raise
pass

Reinstall pyNN after making these adjustments, so that they take effect
in your pyNN installation directory.
3 changes: 3 additions & 0 deletions integration_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
These tests depend on https://github.com/SpiNNakerManchester/TestBase

This is not added automatically by setup.py
14 changes: 14 additions & 0 deletions integration_tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2017-2020 The University of Manchester
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
37 changes: 37 additions & 0 deletions integration_tests/test_microcircuit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2017-2021 The University of Manchester
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from spinnaker_testbase import ScriptChecker
import os
import sys
import stat


class TestMicrocircuit(ScriptChecker):

def test_microcircuit(self):
self.runsafe(self.microcircuit)

def microcircuit(self):
self.check_script("run_microcircuit.py")
for result_file in [
"spikes_L23E.pkl", "spikes_L23I.pkl",
"spikes_L4E.pkl", "spikes_L4I.pkl",
"spikes_L5E.pkl", "spikes_L5I.pkl",
"spikes_L6E.pkl", "spikes_L6I.pkl",
"spiking_activity.png"]:
result_path = os.path.join("results", result_file)
assert(os.path.exists(result_path))
assert(os.stat(result_path)[stat.ST_SIZE])
161 changes: 0 additions & 161 deletions microcircuit/README.txt

This file was deleted.

Empty file added microcircuit/__init__.py
Empty file.
34 changes: 23 additions & 11 deletions microcircuit/nest_specific_info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os

from past.builtins import xrange
from sim_params import NestParams
from constants import DC, NEST_NEURON_MODEL, CONN_ROUTINE
from .sim_params import NestParams
from .constants import DC, NEST_NEURON_MODEL, CONN_ROUTINE
import numpy


Expand Down Expand Up @@ -84,15 +84,27 @@ class NestSimulatorInfo(NestParams):
]

def __init__(
self, parallel_safe=True, n_scaling=1.0, k_scaling=1.0,
neuron_model=NEST_NEURON_MODEL, conn_routine=CONN_ROUTINE,
save_connections=False, voltage_input_type='random',
delay_dist_type='normal', input_type=DC, record_fraction=True,
n_record=100, frac_record_spikes=1.0, record_v=False,
n_record_v=20, frac_record_v=0.1, record_corr=False,
pyseed=2563297, master_seed=124678,
tau_syn_name='tau_syn_ex'):
super(NestSimulatorInfo, self).__init__()
self, timestep=0.1, sim_duration=10000.0, min_delay=0.1,
max_delay=100.0, n_nodes=1, outfile='output.txt',
errfile='errors.txt', output_path='results', output_format='pkl',
conn_dir='connectivity', n_procs_per_node=24, wall_time='8:0:0',
memory='4gb',
mpi_path=(
'/usr/local/mpi/openmpi/1.4.3/gcc64/bin/'
'mpivars_openmpi-1.4.3_gcc64.sh'),
backend_path='/path/to/backend', pynn_path='/path/to/pyNN',
parallel_safe=True, n_scaling=1.0,
k_scaling=1.0, neuron_model=NEST_NEURON_MODEL,
conn_routine=CONN_ROUTINE, save_connections=False,
voltage_input_type='random', delay_dist_type='normal',
input_type=DC, record_fraction=True, n_record=100,
frac_record_spikes=1.0, record_v=False, n_record_v=20,
frac_record_v=0.1, record_corr=False, pyseed=2563297,
master_seed=124678, tau_syn_name='tau_syn_ex'):
super(NestSimulatorInfo, self).__init__(
timestep, sim_duration, min_delay, max_delay, n_nodes, outfile,
errfile, output_path, output_format, conn_dir, n_procs_per_node,
wall_time, memory, mpi_path, backend_path, pynn_path)
self.parallel_safe = parallel_safe
self.n_scaling = n_scaling
self.k_scaling = k_scaling
Expand Down
Loading

0 comments on commit 7e2ff0d

Please sign in to comment.