From 479c2c4825abbcf047fbdb707c9234b32dd19c75 Mon Sep 17 00:00:00 2001 From: Espen Hagen <2492641+espenhgn@users.noreply.github.com> Date: Tue, 2 May 2023 23:55:46 +0200 Subject: [PATCH] Fix misc. deprecated codes (#83) * set up Docker image w. NEST-3.1 * misc * fixed misc. code issues. * move nest import * relocate import nest * updated Dockerfile --- Dockerfile | 137 ++++++++---------- environment.yml | 11 +- examples/brunel_alpha_nest.py | 6 +- examples/example_brunel.py | 5 +- examples/example_microcircuit.py | 2 +- .../example_microcircuit_lognormalweights.py | 2 +- hybridLFPy/gdf.py | 11 +- setup.py | 2 + 8 files changed, 76 insertions(+), 100 deletions(-) diff --git a/Dockerfile b/Dockerfile index 240e1cd..03cef54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/LFPy.git@v2.2.1#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 diff --git a/environment.yml b/environment.yml index 9058e9b..7f9e292 100644 --- a/environment.yml +++ b/environment.yml @@ -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: diff --git a/examples/brunel_alpha_nest.py b/examples/brunel_alpha_nest.py index 098afe1..5517c49 100755 --- a/examples/brunel_alpha_nest.py +++ b/examples/brunel_alpha_nest.py @@ -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') diff --git a/examples/example_brunel.py b/examples/example_brunel.py index 7e6f34c..5c0d14e 100644 --- a/examples/example_brunel.py +++ b/examples/example_brunel.py @@ -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 @@ -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 ########################################### @@ -322,7 +320,6 @@ skiprows=3, ) - if RANK == 0: toc = time() - tic print('NEST simulation and gdf file processing done in %.3f seconds' % toc) diff --git a/examples/example_microcircuit.py b/examples/example_microcircuit.py index 4bcd326..97ff6f1 100644 --- a/examples/example_microcircuit.py +++ b/examples/example_microcircuit.py @@ -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 diff --git a/examples/example_microcircuit_lognormalweights.py b/examples/example_microcircuit_lognormalweights.py index 5acbe96..0f0dbc5 100644 --- a/examples/example_microcircuit_lognormalweights.py +++ b/examples/example_microcircuit_lognormalweights.py @@ -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 diff --git a/hybridLFPy/gdf.py b/hybridLFPy/gdf.py index dbe9435..c5a1840 100644 --- a/hybridLFPy/gdf.py +++ b/hybridLFPy/gdf.py @@ -157,7 +157,7 @@ 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( @@ -165,15 +165,6 @@ def create(self, re='brunel-py-ex-*.gdf', index=True, skiprows=0): 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: diff --git a/setup.py b/setup.py index 3b27639..d910603 100644 --- a/setup.py +++ b/setup.py @@ -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',