Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ include pyNN/nest/extensions/*.cpp
include pyNN/nest/extensions/CMakeLists.txt
include pyNN/nest/extensions/sli/*
include pyNN/descriptions/templates/*/*.txt
include test/parameters/*
include test/system/*.py
include test/system/scenarios/*.py
include test/unittests/*.py
Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class MockNESTModule(mock.Mock):
# built documents.
#
# The short X.Y version.
version = '0.10'
version = '0.11'
# The full version, including alpha/beta/rc tags.
release = '0.10.2.dev'
release = '0.11.0.dev'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
35 changes: 9 additions & 26 deletions doc/developers/contributing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ To work on the development version::

$ git checkout master

To work on the latest stable release (for bug-fixes)::

$ git checkout --track origin/0.8

To keep your PyNN repository up-to-date with respect to the official
repository, add it as a remote::

Expand All @@ -62,12 +58,7 @@ To get PyNN onto your :envvar:`PYTHONPATH` there are many options, such as:
* pip editable mode (`pip install -e /path/to/PyNN`)
* creating a symbolic link named :file:`pyNN` from somewhere that is already
on your :envvar:`PYTHONPATH`, such as the :file:`site-packages` directory,
to the :file:`pyNN_trunk/pyNN` directory.

If you are developing with NEURON, don't forget to compile the NMODL files in
:file:`pyNN/neuron/nmodl` by running :command:`nrnivmodl`, and to recompile any time
you modify any of them.

to the :file:`pyNN_dev/pyNN` directory.

Coding style
============
Expand All @@ -80,7 +71,7 @@ We try to stay fairly close to PEP8_. Please note in particular:
- some function/method names in PyNN use ``mixedCase``, but these will
gradually be deprecated and replaced with ``lower_case_with_underscores``.
Any new functions or methods should use the latter.
- we currently target versions 2.7 and 3.6+
- we currently target versions 3.8+


Testing
Expand Down Expand Up @@ -190,16 +181,16 @@ last time:
you should do this on at least two Linux systems and one Mac OS X system.
* does the documentation build without errors? You should then at least skim
the generated HTML pages to check for obvious problems.
* have you updated the version numbers in :file:`setup.py`, :file:`pyNN/__init__.py`,
* have you updated the version numbers in :file:`pyproject.toml`, :file:`pyNN/__init__.py`,
:file:`doc/conf.py` and :file:`doc/installation.txt`?
* have you updated the changelog?

Once you've confirmed all the above, create a source package using::
Once you've confirmed all the above, create source and wheel packages using::

$ python setup.py sdist
$ python -m build

and check that it installs properly (you will find it in the :file:`dist`
subdirectory.
and check that they install properly (you will find them in the :file:`dist`
subdirectory).

Now you should commit any changes, then tag with the release number as follows::

Expand All @@ -213,24 +204,16 @@ to http://neuralensemble.org/docs/PyNN/ by running::
in the :file:`doc` directory, and then unpacking the resulting archive on the
NeuralEnsemble server.

If this is a development release (i.e. an *alpha* or *beta*), the final step is
to upload the source package to the INCF Software Center.
Do **not** upload development releases to PyPI.

To upload a package to the INCF Software Center, log-in, and then go to the
Contents_ tab. Click on "Add new..." then "File", then fill in the form and
upload the source package.

If this is a final release, there are a few more steps:

* if it is a major release (i.e. an ``x.y.0`` release), create a new bug-fix
branch::

$ git branch x.y

* upload the source package to PyPI::
* upload the packages to PyPI (Do **not** upload development releases to PyPI)::

$ python setup.py sdist upload
$ twine upload dist/PyNN-x.y.z*

* make an announcement on the `mailing list`_

Expand Down
60 changes: 25 additions & 35 deletions doc/installation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ install and run PyNN on Windows, but this has not been tested.

Installing PyNN requires:

* Python (version 3.7+)
* Python (version 3.8+)
* a recent version of the NumPy_ package
* the lazyarray_ package
* the Neo_ package (>= 0.11.0)
Expand All @@ -32,9 +32,8 @@ The easiest way to get PyNN is to use pip_::
If you would prefer to install manually, :doc:`download the latest
source distribution <download>`, then run the setup script, e.g.::

$ tar xzf PyNN-0.10.1.tar.gz
$ cd PyNN-0.10.1
$ python setup.py install
$ tar xzf PyNN-0.11.0.tar.gz
$ pip install ./PyNN-0.11.0

This will install it to your Python :file:`site-packages` directory, and may
require root privileges. We strongly recommend, however, that you use a
Expand All @@ -55,30 +54,25 @@ Test it using something like the following::
If you get a warning "Unable to install NEST extensions. Certain models may not be available" then ensure the
program :command:`nest-config` is on your system PATH.
If you still get this message even after adding the directory containing :command:`nest-config` to the PATH,
try ``pip uninstall PyNN``, then re-install with ``pip install --no-binary :all: PyNN``
then you will still be able to use pyNN.nest, just a small number of models will not be available.

With NEURON as the simulator, make sure you install NEURON *before* you install PyNN.
The PyNN installation will then compile PyNN-specific membrane mechanisms, which are loaded when importing the :mod:`neuron` module::
For NEURON, PyNN will compile PyNN-specific membrane mechanisms the first time you import the :mod:`neuron` module::

>>> import pyNN.neuron as sim
NEURON -- Release 7.4 (1370:16a7055d4a86) 2015-11-09
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits

loading membrane mechanisms from /home/docker/dev/PyNN/pyNN/neuron/nmodl/x86_64/.libs/libnrnmech.so
Additional mechanisms from files
adexp.mod alphaisyn.mod alphasyn.mod expisyn.mod gap.mod gsfa_grr.mod hh_traub.mod
izhikevich.mod netstim2.mod refrac.mod reset.mod stdwa_guetig.mod stdwa_softlimits.mod
stdwa_songabbott.mod stdwa_symm.mod stdwa_vogels2011.mod tmgsyn.mod tmisyn.mod
tsodyksmarkram.mod vecstim.mod

If you installed PyNN before installing NEURON, or if you update your PyNN installation,
you will need to manually run :command:`nrnivmodl` in the :file:`pyNN/neuron/nmodl` directory.

Installing NEURON
=================

Download the sources for NEURON 7.4 or later, in ``.tar.gz`` format, from `<http://www.neuron.yale.edu/neuron/download/getstd>`_.
For recent versions of NEURON,

::

$ pip install neuron

may be all you need. If you have more complex needs, try the following.

Download the sources for NEURON 8.0 or later, in ``.tar.gz`` format, from `<http://www.neuron.yale.edu/neuron/download/getstd>`_.
Also download Interviews from the same location.

Compile Interviews and NEURON according to the instructions given at `<http://www.neuron.yale.edu/neuron/static/download/compilestd_unix.html>`_,
Expand All @@ -92,9 +86,9 @@ Make sure that you add the Interviews and NEURON :file:`bin` directories to your
Test that the Python support has been enabled by running::

$ nrniv -python
NEURON -- Release 7.4 (1370:16a7055d4a86) 2015-11-09
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits
NEURON -- VERSION 8.2.2 release/8.2 (93d41fafd) 2022-12-15
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2022
See http://neuron.yale.edu/neuron/credits

>>> import hoc
>>> import nrn
Expand All @@ -108,35 +102,31 @@ Now test everything worked::

$ python
>>> import neuron
NEURON -- Release 7.4 (1370:16a7055d4a86) 2015-11-09
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2015
See http://www.neuron.yale.edu/neuron/credits

If you run into problems, check out the `NEURON Forum`_.


Installing NEST and PyNEST
==========================

NEST 2.18.0 can be downloaded from `<http://www.nest-simulator.org/download/>`_.
NEST 3.4 can be downloaded from `<http://www.nest-simulator.org/download/>`_.
Earlier versions of NEST may not work with this version of PyNN.
The full installation instructions are available in the file INSTALL, which you can find in the NEST source package,
or at `<http://www.nest-simulator.org/installation/>`_.
The full installation instructions are available at `<https://nest-simulator.readthedocs.io/en/v3.4/installation/index.html/>`_.

Now try it out::

$ cd ~
$ python
>>> import nest
-- N E S T --
Copyright (C) 2004 The NEST Initiative

Version: v2.20.0
-- N E S T --
Copyright (C) 2004 The NEST Initiative

Version: 3.4
...
>>> nest.Models()
(u'ac_generator', u'aeif_cond_alpha', u'aeif_cond_alpha_RK5', u'aeif_cond_alpha_multisynapse',
...

>>> nest.node_models
('weight_recorder', 'gauss_rate_ipn', 'lin_rate_ipn', 'sigmoid_rate_ipn', 'sigmoid_rate_gg_1998_ipn', 'tanh_rate_ipn', ...)

Check that ``'aeif_cond_alpha'`` is in the list of models. If it is not, you may need to install a newer version of the `GNU Scientific Library`_ and then recompile NEST.

Expand Down
5 changes: 3 additions & 2 deletions pyNN/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
:license: CeCILL, see LICENSE for details.
"""

__version__ = '0.10.2.dev'
__version__ = '0.11.0.dev'
__all__ = ["common", "random", "nest", "neuron", "brian2",
"recording", "errors", "space", "descriptions",
"standardmodels", "parameters", "core", "serialization"]
"standardmodels", "parameters", "core", "serialization",
"utility"]
23 changes: 23 additions & 0 deletions pyNN/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
:license: CeCILL, see LICENSE for details.
"""

import os
import subprocess
import warnings
import numpy as np

Expand Down Expand Up @@ -56,6 +58,27 @@ def ezip(*args):
yield items[0], items[1:]


def find(command):
"""Try to find an executable file."""
path = os.environ.get("PATH", "").split(os.pathsep)
cmd = ''
for dir_name in path:
abs_name = os.path.abspath(os.path.normpath(os.path.join(dir_name, command)))
if os.path.isfile(abs_name):
cmd = abs_name
break
return cmd


def run_command(path, working_directory):
p = subprocess.Popen(path, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True,
cwd=working_directory)
stdout, stderr = p.communicate()
return p.returncode, stdout.split("\n")


class IndexBasedExpression(object):
"""
Abstract base class for general expressions that use the cell indices and projection class to
Expand Down
65 changes: 62 additions & 3 deletions pyNN/nest/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
:license: CeCILL, see LICENSE for details.
"""

import nest
import os.path
import logging
import tempfile
import warnings
import numpy as np

import nest

from .. import common
from ..core import reraise
from ..core import reraise, find, run_command

logger = logging.getLogger("PyNN")
name = "NEST" # for use in annotating output data
Expand All @@ -39,6 +42,57 @@
NEST_ARRAY_VARIABLES_TIME_DIMENSION = ("spike_times", "amplitude_times", "rate_times")


# --- Building extensions ------------------------------------------------------

def build_extensions(build_dir=None):
nest_config = find("nest-config")
if not nest_config:
warnings.warn("Cannot find nest-config, please check your PATH. Unable to build extensions.")
return

logger.debug("nest-config found at", nest_config)

build_dirs = []
if build_dir is not None:
build_dirs.append(build_dir)
# if a specific build directory is not provided,
# first try to build within the pyNN source dir
build_dirs.append(os.path.join(os.path.dirname(__file__), "_build"))
# if that directory is not writable, build in the current working directory
build_dirs.append(os.path.join(os.getcwd(), "_build", "nest_extensions"))

for nest_build_dir in build_dirs:
try:
os.makedirs(nest_build_dir, exist_ok=True)
except OSError:
continue
if os.access(nest_build_dir, os.W_OK):
break

if not os.access(nest_build_dir, os.W_OK):
warnings.warn("Cannot create build directory for nest extensions")
return

source_dir = os.path.join(os.path.dirname(__file__), "extensions")
result, stdout = run_command(f"cmake -Dwith-nest={nest_config} {source_dir}",
nest_build_dir)
if result != 0:
err_msg = "\n ".join(stdout)
warnings.warn(f"Problem running cmake. Output was:\n {err_msg}")
else:
result, stdout = run_command("make", nest_build_dir)
if result != 0:
err_msg = "\n ".join(stdout)
warnings.warn(f"Unable to compile NEST extensions. Output was:\n {err_msg}")
else:
result, stdout = run_command("make install", nest_build_dir)
if result != 0:
err_msg = "\n ".join(stdout)
warnings.warn(f"Unable to install NEST extensions. Output was:\n {err_msg}")
else:
logger.info("Successfully compiled NEST extensions.")


# --- For implementation of get_time_step() and similar functions --------------


Expand Down Expand Up @@ -77,7 +131,12 @@ def __init__(self):
nest.Install('pynn_extensions')
self.extensions_loaded = True
except nest.NESTError:
self.extensions_loaded = False
build_extensions()
try:
nest.Install('pynn_extensions')
self.extensions_loaded = True
except nest.NESTError:
self.extensions_loaded = False
self.initialized = False
self.optimize = False
self.spike_precision = "off_grid"
Expand Down
Loading