Skip to content

Commit

Permalink
Fix misc. deprecated codes (#83)
Browse files Browse the repository at this point in the history
* set up Docker image w. NEST-3.1

* misc

* fixed misc. code issues.

* move nest import

* relocate import nest

* updated Dockerfile
  • Loading branch information
espenhgn authored May 2, 2023
1 parent 01ec571 commit 479c2c4
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 100 deletions.
137 changes: 64 additions & 73 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,103 +1,94 @@
# -------- base ---------
FROM debian:bullseye-slim AS base
FROM buildpack-deps:jammy

RUN apt-get update && \
apt-get install -y \
wget \
bash \
build-essential \
make \
gcc \
g++ \
git \
libncurses-dev \
python3 \
python3-numpy \
python3-scipy \
python3-matplotlib \
python3-h5py \
python3-yaml \
python3-pytest \
python3-pip \
cython3 \
jupyter \
ipython3

RUN pip3 install --upgrade pip

# ------ NEURON -----------

FROM base AS neuron

RUN pip3 install neuron


# ----- LFPy ---------

FROM neuron AS lfpy

RUN apt-get update && \
apt-get install -y \
python3-mpi4py

RUN pip3 install git+https://github.com/LFPy/[email protected]#egg=LFPy


# --- NEST ----

FROM lfpy AS nest

ARG WITH_MPI=ON
ARG WITH_OMP=ON
ARG WITH_GSL=ON

RUN apt-get update && apt-get install -y --no-install-recommends \
cmake \
libgsl-dev \
libltdl7 \
libltdl-dev \
libreadline8 \
libreadline-dev \
libmpich-dev \
mpich \
doxygen \
libboost-dev \
libopenmpi-dev \
doxygen
libgsl-dev \
cython3 \
python3-dev \
python3-pip \
python3-numpy

RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && \
update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 10

# Install NEST 3 (master branch @v3.0)
RUN wget https://github.com/nest/nest-simulator/archive/v3.0.tar.gz && \
RUN pip install mpi4py

# Install NEST 3.4 (master branch @v3.4)
RUN git clone --depth 1 -b v3.4 https://github.com/nest/nest-simulator && \
mkdir nest-build && \
tar zxf v3.0.tar.gz && \
mv nest-simulator-3.0 nest-simulator && \
cd nest-build && \
cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/nest/ \
-Dwith-boost=ON \
-Dwith-ltdl=ON \
-Dwith-gsl=$WITH_GSL \
-Dwith-gsl=ON \
-Dwith-readline=ON \
-Dwith-python=ON \
-Dwith-mpi=$WITH_MPI \
-Dwith-openmp=$WITH_OMP \
-Dwith-mpi=ON \
-Dwith-openmp=ON \
../nest-simulator && \
make -j4 && \
make install && \
cd ..

RUN echo "source /opt/nest/bin/nest_vars.sh" >> root/.bashrc

# clean up install/build files
RUN rm v3.0.tar.gz
RUN rm -r nest-simulator
RUN rm -r nest-build


# --- hybridLFPy ----
# ---- additional requirements
RUN apt-get install -y \
python3-numpy \
python3-scipy \
python3-matplotlib \
python3-pandas \
ipython3 \
jupyter

RUN update-alternatives --install /usr/bin/ipython ipython /usr/bin/ipython3 10

# installing serial h5py (deb package installs OpenMPI which may conflict with MPICH)
RUN pip install h5py


FROM nest AS hybridlfpy
# ---- install neuron -----
RUN apt-get install -y \
bison flex

RUN pip3 install git+https://github.com/INM-6/hybridLFPy.git@master#egg=hybridLFPy
RUN git clone --depth 1 -b 8.2.2 https://github.com/neuronsimulator/nrn.git
RUN mkdir nrn-bld && cd nrn-bld

RUN cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt/nrn/ \
-DCURSES_NEED_NCURSES=ON \
-DNRN_ENABLE_INTERVIEWS=OFF \
-DNRN_ENABLE_MPI=ON \
-DNRN_ENABLE_RX3D=OFF \
-DNRN_ENABLE_PYTHON=ON \
../nrn

# ---- hybridLFPy + examples ----
RUN cmake --build . --parallel 4 --target install && \
cd ..

# add nrnpython to PYTHONPATH
ENV PYTHONPATH /opt/nrn/lib/python:${PYTHONPATH}


# --- Install hybridLFPy ----
RUN pip install git+https://github.com/INM-6/hybridLFPy.git@master#egg=hybridLFPy

FROM hybridlfpy AS examples

# ---- Install additional dependencies for examples ----
RUN pip3 install git+https://github.com/NeuralEnsemble/parameters@b95bac2bd17f03ce600541e435e270a1e1c5a478


# Add NEST environment variables
RUN echo "source /opt/nest/bin/nest_vars.sh" >> root/.bashrc

# If running with Singularity, run the below line in the host.
# PYTHONPATH set here doesn't carry over:
# export SINGULARITYENV_PYTHONPATH=/opt/nest/lib/python3.9/site-packages
# Alternatively, run "source /opt/local/bin/nest_vars.sh" while running the container
11 changes: 4 additions & 7 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ channels:
- conda-forge
- defaults
dependencies:
- python>=3.7
# - lfpy>=2.1
# - nest-simulator=*=mpi*
#- openmpi-mpicc
- python>=3.8
- lfpy>=2.3
# - nest-simulator # install from source to support MPI
- c-compiler
- cxx-compiler
- openmpi
- mpi4py
- h5py
- scipy
- numpy
- pytest
- cython
- meautility
- matplotlib
- ipython
- jupyter
- ffmpeg
- neuron
- pytest
- pip
- pip:
Expand Down
6 changes: 2 additions & 4 deletions examples/brunel_alpha_nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@
weights.
'''




from scipy.optimize import fsolve
import nest
import nest.raster_plot
import os
import time
from numpy import exp, random


def LambertWm1(x):
nest.ll_api.sli_push(x)
nest.ll_api.sli_run('LambertWm1')
Expand Down
5 changes: 1 addition & 4 deletions examples/example_brunel.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import h5py
from parameters import ParameterSet
from hybridLFPy import PostProcess, Population, CachedNetwork, setup_file_dest
import nest # import not used, but we load NEST anyway in order determine if
import neuron # NEURON compiled with MPI must be imported before NEST/mpi4py
from time import time
from matplotlib import gridspec
Expand All @@ -51,9 +50,8 @@
import matplotlib
matplotlib.use('Agg')
import matplotlib.style

matplotlib.style.use('classic')
# to avoid being aware of MPI
# network is run in parallel


########## matplotlib settings ###########################################
Expand Down Expand Up @@ -322,7 +320,6 @@
skiprows=3,
)


if RANK == 0:
toc = time() - tic
print('NEST simulation and gdf file processing done in %.3f seconds' % toc)
Expand Down
2 changes: 1 addition & 1 deletion examples/example_microcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
from time import time
import neuron # NEURON compiled with MPI must be imported before NEST and mpi4py
# to avoid NEURON being aware of MPI.
import nest # Import not used, but done in order to ensure correct execution
from hybridLFPy import PostProcess, Population, CachedNetwork
from hybridLFPy import setup_file_dest, helpers
from glob import glob
import tarfile
import lfpykit
from mpi4py import MPI
import nest


# set some seed values
Expand Down
2 changes: 1 addition & 1 deletion examples/example_microcircuit_lognormalweights.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
from time import time
import neuron # NEURON compiled with MPI must be imported before NEST/mpi4py
# to avoid NEURON being aware of MPI.
import nest # Import not used, but done in order to ensure correct execution
from hybridLFPy import PostProcess, Population, CachedNetwork
from hybridLFPy import setup_file_dest, helpers
from glob import glob
import tarfile
import lfpykit
from mpi4py import MPI
import nest


# set some seed values
Expand Down
11 changes: 1 addition & 10 deletions hybridLFPy/gdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,14 @@ def create(self, re='brunel-py-ex-*.gdf', index=True, skiprows=0):
tic = now()
for f in glob.glob(re):
print(f)
if sys.version < "3.7":
while True:
try:
for data in self._blockread(f, skiprows):
self.cursor.executemany(
'INSERT INTO spikes VALUES (?, ?)', data)
self.conn.commit()
except RuntimeError:
break
else:
while True:
try:
for data in self._blockread(f, skiprows):
self.cursor.executemany(
'INSERT INTO spikes VALUES (?, ?)', data)
self.conn.commit()
except RuntimeError:
break

toc = now()
if self.debug:
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Cython',
'Operating System :: OS Independent',
'Topic :: Scientific/Engineering',
Expand Down

0 comments on commit 479c2c4

Please sign in to comment.