Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Backport 8.2: Python 3.13 support #3319

Draft
wants to merge 20 commits into
base: release/8.2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 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
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
39) pyenv_py_ver="3.9.1" ;;
310) pyenv_py_ver="3.10.1" ;;
311) pyenv_py_ver="3.11.0" ;;
312) pyenv_py_ver="3.12.0" ;;
313) pyenv_py_ver="3.13.1" ;;
*) echo "Error: pyenv python version not specified!" && exit 1;;
esac

Expand Down Expand Up @@ -110,5 +112,5 @@ workflows:
- manylinux2014-aarch64:
matrix:
parameters:
NRN_PYTHON_VERSION: ["37", "38", "39", "310", "311"]
NRN_PYTHON_VERSION: ["37", "38", "39", "310", "311", "312", "313"]
NRN_NIGHTLY_UPLOAD: ["true"]
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ on:

env:
PY_MIN_VERSION: '3.7'
PY_MAX_VERSION: '3.11'
PY_MAX_VERSION: '3.13'

jobs:
coverage:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/neuron-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
BUILD_TYPE: Release
DESIRED_CMAKE_VERSION: 3.15.0
PY_MIN_VERSION: '3.7'
PY_MAX_VERSION: '3.11'
PY_MAX_VERSION: '3.13'

jobs:
ci:
Expand All @@ -40,12 +40,12 @@ jobs:
BUILD_TYPE: Release
DESIRED_CMAKE_VERSION: 3.15.0
PY_MIN_VERSION: ${{ matrix.config.python_min_version || '3.8' }}
PY_MAX_VERSION: ${{ matrix.config.python_max_version || '3.11' }}
PY_MAX_VERSION: ${{ matrix.config.python_max_version || '3.12' }}
MUSIC_INSTALL_DIR: /opt/MUSIC

strategy:
matrix:
os: [ macOS-12, ubuntu-20.04]
os: [ macOS-13, ubuntu-20.04]
config:
- { matrix_eval : "CC=gcc-9 CXX=g++-9", build_mode: "setuptools"}
- { matrix_eval : "CC=gcc-8 CXX=g++-8", build_mode: "cmake", music: ON}
Expand Down Expand Up @@ -148,15 +148,15 @@ jobs:
run: |
python3 -m venv music-venv
source music-venv/bin/activate
python3 -m pip install mpi4py "cython<3" "numpy<2"
python3 -m pip install mpi4py cython numpy
sudo mkdir -p $MUSIC_INSTALL_DIR
sudo chown -R $USER $MUSIC_INSTALL_DIR
# Stable build: https://github.com/INCF/MUSIC/archive/refs/heads/switch-to-MPI-C-interface.zip @ f33b66ea9348888eed1761738ab48c23ffc8a0d0
curl -L -o MUSIC.zip https://codeload.github.com/INCF/MUSIC/zip/f33b66ea9348888eed1761738ab48c23ffc8a0d0
unzip MUSIC.zip && mv MUSIC-* MUSIC && cd MUSIC
./autogen.sh
# workaround for MUSIC on MacOS 12
if [[ "${{matrix.os}}" == "macOS-12" ]]; then
if [[ "${{matrix.os}}" == "macOS-13" ]]; then
MPI_CXXFLAGS="-g" MPI_CFLAGS="-g" MPI_LDFLAGS="-g" CC=mpicc CXX=mpicxx ./configure --with-python-sys-prefix --prefix=$MUSIC_INSTALL_DIR --disable-anysource
else
./configure --with-python-sys-prefix --prefix=$MUSIC_INSTALL_DIR --disable-anysource
Expand Down
8 changes: 7 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ stages:
python.version: '3.11'
Python312:
python.version: '3.12'
Python313:
python.version: '3.13'
steps:

# Secure files documentation:
Expand Down Expand Up @@ -86,7 +88,7 @@ stages:
- job: 'MacOSWheels'
timeoutInMinutes: 40
pool:
vmImage: 'macOS-12'
vmImage: 'macOS-13'
strategy:
matrix:
Python37:
Expand All @@ -113,6 +115,10 @@ stages:
python.version: '3.12'
python.org.version: '3.12.2'
python.installer.name: 'macos11.pkg'
Python313:
python.version: '3.13'
python.org.version: '3.13.1'
python.installer.name: 'macos11.pkg'

steps:

Expand Down
2 changes: 1 addition & 1 deletion bldnrnmacpkgcmake.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -ex

default_pythons="python3.8 python3.9 python3.10 python3.11 python3.12"
default_pythons="python3.8 python3.9 python3.10 python3.11 python3.12 python3.13"
# distribution built with
# bash bldnrnmacpkgcmake.sh
# without args, default are the pythons above.
Expand Down
6 changes: 3 additions & 3 deletions ci/win_build_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export MINGW_CHOST=x86_64-w64-mingw32
export MSYSTEM_PREFIX=/mingw64
export PATH=/mingw64/bin:$PATH

# have compatible cython3
python3 -m pip install "cython<3"
# have compatible cython
python3 -m pip install cython

# if BUILD_SOURCESDIRECTORY not available, use te root of the repo
if [ -z "$BUILD_SOURCESDIRECTORY" ]; then
Expand All @@ -31,7 +31,7 @@ cd $BUILD_SOURCESDIRECTORY/build
-DNRN_RX3D_OPT_LEVEL=2 \
-DPYTHON_EXECUTABLE=/c/Python37/python.exe \
-DNRN_ENABLE_PYTHON_DYNAMIC=ON \
-DNRN_PYTHON_DYNAMIC='c:/Python37/python.exe;c:/Python38/python.exe;c:/Python39/python.exe;c:/Python310/python.exe;c:/Python311/python.exe;c:/Python312/python.exe' \
-DNRN_PYTHON_DYNAMIC='c:/Python37/python.exe;c:/Python38/python.exe;c:/Python39/python.exe;c:/Python310/python.exe;c:/Python311/python.exe;c:/Python312/python.exe;c:/Python313/python.exe' \
-DCMAKE_INSTALL_PREFIX='/c/nrn-install' \
-DMPI_CXX_LIB_NAMES:STRING=msmpi \
-DMPI_C_LIB_NAMES:STRING=msmpi \
Expand Down
1 change: 1 addition & 0 deletions ci/win_download_deps.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pwsh -command Invoke-WebRequest -MaximumRetryCount 4 -OutFile python-3.9.exe htt
pwsh -command Invoke-WebRequest -MaximumRetryCount 4 -OutFile python-3.10.exe https://www.python.org/ftp/python/3.10.0/python-3.10.0-amd64.exe || goto :error
pwsh -command Invoke-WebRequest -MaximumRetryCount 4 -OutFile python-3.11.exe https://www.python.org/ftp/python/3.11.1/python-3.11.1-amd64.exe || goto :error
pwsh -command Invoke-WebRequest -MaximumRetryCount 4 -OutFile python-3.12.exe https://www.python.org/ftp/python/3.12.1/python-3.12.1-amd64.exe || goto :error
pwsh -command Invoke-WebRequest -MaximumRetryCount 4 -OutFile python-3.13.exe https://www.python.org/ftp/python/3.13.1/python-3.13.1-amd64.exe || goto :error

:: mpi
pwsh -command Invoke-WebRequest -MaximumRetryCount 4 -OutFile msmpisetup.exe https://download.microsoft.com/download/a/5/2/a5207ca5-1203-491a-8fb8-906fd68ae623/msmpisetup.exe || goto :error
Expand Down
22 changes: 12 additions & 10 deletions ci/win_install_deps.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ python-3.9.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustFo
python-3.10.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python310 || goto :error
python-3.11.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python311 || goto :error
python-3.12.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python312 || goto :error
python-3.13.exe /passive Include_pip=1 Include_test=0 PrependPath=1 DefaultJustForMeTargetDir=C:\Python313 || goto :error

:: fix msvcc version for all python3
pwsh -command "(Get-Content C:\Python37\Lib\distutils\cygwinccompiler.py) -replace 'elif msc_ver == ''1600'':', 'elif msc_ver == ''1900'':' | Out-File C:\Python37\Lib\distutils\cygwinccompiler.py"
Expand All @@ -26,12 +27,13 @@ pwsh -command "(Get-Content C:\Python310\Lib\distutils\cygwinccompiler.py) -repl
pwsh -command "(Get-Content C:\Python311\Lib\distutils\cygwinccompiler.py) -replace 'msvcr100', 'msvcrt' | Out-File C:\Python311\Lib\distutils\cygwinccompiler.py"

:: install numpy
C:\Python37\python.exe -m pip install numpy==1.14.6 "cython < 3" || goto :error
C:\Python38\python.exe -m pip install numpy==1.17.5 "cython < 3" || goto :error
C:\Python39\python.exe -m pip install numpy==1.19.3 "cython < 3" || goto :error
C:\Python310\python.exe -m pip install numpy==1.21.3 "cython < 3" || goto :error
C:\Python311\python.exe -m pip install numpy==1.23.5 "cython < 3" || goto :error
C:\Python312\python.exe -m pip install numpy==1.26.3 "cython < 3" || goto :error
C:\Python37\python.exe -m pip install numpy==1.14.6 cython || goto :error
C:\Python38\python.exe -m pip install numpy==1.17.5 cython || goto :error
C:\Python39\python.exe -m pip install numpy==1.19.3 cython || goto :error
C:\Python310\python.exe -m pip install numpy==1.21.3 cython || goto :error
C:\Python311\python.exe -m pip install numpy==1.23.5 cython || goto :error
C:\Python312\python.exe -m pip install numpy==1.26.3 cython || goto :error
C:\Python313\python.exe -m pip install numpy cython || goto :error
:: setuptools 70.2 leads to an error
C:\Python312\python.exe -m pip install setuptools==70.1.1 || goto :error

Expand Down Expand Up @@ -67,11 +69,11 @@ base-devel ^
mingw-w64-x86_64-cmake ^
mingw-w64-x86_64-ncurses ^
mingw-w64-x86_64-readline ^
mingw-w64-x86_64-python3 ^
mingw-w64-x86_64-python ^
mingw64/mingw-w64-x86_64-cython ^
mingw-w64-x86_64-python3-setuptools ^
mingw-w64-x86_64-python3-packaging ^
mingw-w64-x86_64-python3-pip ^
mingw-w64-x86_64-python-setuptools ^
mingw-w64-x86_64-python-packaging ^
mingw-w64-x86_64-python-pip ^
mingw64/mingw-w64-x86_64-dlfcn ^
mingw-w64-x86_64-toolchain || goto :error

Expand Down
22 changes: 21 additions & 1 deletion ci/win_test_installer.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,28 @@ C:\Python39\python -c "import neuron; neuron.test(); quit()" || set "errorfound=
C:\Python310\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python311\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python312\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python313\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"

:: install oldest supported numpy
C:\Python37\python.exe -m pip install -r packaging/python/oldest_numpy_requirements.txt || goto :error
C:\Python38\python.exe -m pip install -r packaging/python/oldest_numpy_requirements.txt || goto :error
C:\Python39\python.exe -m pip install -r packaging/python/oldest_numpy_requirements.txt || goto :error
C:\Python310\python.exe -m pip install -r packaging/python/oldest_numpy_requirements.txt || goto :error
C:\Python311\python.exe -m pip install -r packaging/python/oldest_numpy_requirements.txt || goto :error
C:\Python312\python.exe -m pip install -r packaging/python/oldest_numpy_requirements.txt || goto :error
C:\Python313\python.exe -m pip install -r packaging/python/oldest_numpy_requirements.txt || goto :error

:: test all pythons again
C:\Python37\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python38\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python39\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python310\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python311\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python312\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python313\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"

:: install numpy dependency
python -m pip install "numpy<2"
python -m pip install numpy
:: run also using whatever is system python
python --version
python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
Expand Down
3 changes: 2 additions & 1 deletion ci/win_test_installer_wo_rxd.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ C:\Python39\python -c "import neuron; neuron.test(); quit()" || set "errorfound=
C:\Python310\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python311\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python312\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
C:\Python313\python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"

:: install numpy dependency
python -m pip install "numpy<2"
python -m pip install numpy
:: run also using whatever is system python
python --version
python -c "import neuron; neuron.test(); quit()" || set "errorfound=y"
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# NEURON 8.2

## 8.2.7
_Release Date_ : 01-02-2025

This release allows use of Python 3.13

## 8.2.6
_Release Date_ : 24-07-2024

Expand Down
2 changes: 1 addition & 1 deletion docs/conda_environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- cmake
- xorg-libxcomposite
- ffmpeg
- cython<3
- cython
- pandoc
- pip
- pip:
Expand Down
5 changes: 2 additions & 3 deletions docs/docs_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ jupyter
nbconvert
recommonmark
matplotlib
# bokeh 3 seems to break docs notebooks
bokeh<3
bokeh
# do not check import of next line
ipython
plotnine
numpy<2
numpy
plotly
nbsphinx
jinja2
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Installation

pip3 install neuron

Alternatively, you can use the `PKG installer <https://github.com/neuronsimulator/nrn/releases/download/8.2.6/nrn-8.2.6-macosx-10.9-universal2-py-38-39-310-311-312.pkg>`_.
Alternatively, you can use the `PKG installer <https://github.com/neuronsimulator/nrn/releases/download/8.2.6/nrn-8.2.6-macosx-10.9-universal2-py-38-39-310-311-312-313.pkg>`_.

For troubleshooting, see the `detailed installation instructions <install/install_instructions.html>`_.

Expand Down
2 changes: 1 addition & 1 deletion docs/install/install_instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ In order to build NEURON from source, the following packages must be available:
The following packages are optional (see build options):

- Python >=3.7 (for Python interface)
- Cython < 3 (for RXD)
- Cython (for RXD)
- MPI (for parallel)
- X11 (Linux) or XQuartz (MacOS) (for GUI)

Expand Down
2 changes: 1 addition & 1 deletion docs/install/mac_pkg.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ cmake .. -DCMAKE_INSTALL_PREFIX=$NRN_INSTALL \

The default variables above will be
```
pythons="python3.9;python3.10;python3.11;python3.12"
pythons="python3.9;python3.10;python3.11;python3.12;python3.13"
archs_cmake='-DCMAKE_OSX_ARCHITECTURES=arm64;x86_64'
```

Expand Down
7 changes: 3 additions & 4 deletions nrn_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ wheel
setuptools<=70.3.0
scikit-build
matplotlib
# bokeh 3 seems to break docs notebooks
bokeh<3
bokeh
ipython
cython<3
cython
packaging
pytest
pytest-cov
mpi4py
numpy<2
numpy
2 changes: 1 addition & 1 deletion packaging/python/build_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cython<3
cython
packaging
11 changes: 6 additions & 5 deletions packaging/python/build_wheels.bash
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,16 @@ pip_numpy_install() {
36) numpy_ver="numpy==1.12.1" ;;
37) numpy_ver="numpy==1.14.6" ;;
38) numpy_ver="numpy==1.17.5" ;;
39) numpy_ver="numpy==1.19.3" ;;
310) numpy_ver="numpy==1.21.3" ;;
311) numpy_ver="numpy==1.23.5" ;;
312) numpy_ver="numpy==1.26.0" ;;
39) numpy_ver="numpy>=2" ;;
310) numpy_ver="numpy>=2" ;;
311) numpy_ver="numpy>=2" ;;
312) numpy_ver="numpy>=2" ;;
313) numpy_ver="numpy>=2" ;;
Comment on lines +55 to +59
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because numpy 2 is backwards compatible, but numpy 1 is not forwards compatible, so building a wheel with numpy 1.x and testing it with 2.x will fail, but the other way around works.

*) echo "Error: numpy version not specified for this python!" && exit 1;;
esac

# older version for apple m1 as building from source fails
if [[ `uname -m` == 'arm64' ]] && [[ $py_ver != 311 ]] && [[ $py_ver != 312 ]]; then
if [[ `uname -m` == 'arm64' ]] && [[ $py_ver -le 311 ]] ; then
numpy_ver="numpy==1.21.3"
fi

Expand Down
8 changes: 8 additions & 0 deletions packaging/python/oldest_numpy_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
numpy==1.14.6;python_version=='3.7'
numpy==1.17.5;python_version=='3.8'
numpy==1.20.3;python_version=='3.9' and platform_machine!='arm64'
numpy==1.21.6;python_version=='3.9' and platform_machine=='arm64'
numpy==1.21.6;python_version=='3.10'
numpy==1.23.5;python_version=='3.11'
numpy==1.26.4;python_version=='3.12'
numpy>=2;python_version=='3.13'
2 changes: 2 additions & 0 deletions packaging/python/test_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
setuptools;python_version>='3.12' # From 3.12, no longer installed by default
21 changes: 15 additions & 6 deletions packaging/python/test_wheels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ test_wheel () {
}


test_wheel_basic_python () {
echo "=========== BASIC PYTHON TESTS ==========="
$python_exe -c "import neuron; neuron.test(); neuron.test_rxd()"
}


echo "== Testing $python_wheel using $python_exe ($python_ver) =="


Expand All @@ -297,10 +303,8 @@ $python_exe -m pip install --upgrade pip
$python_exe -m pip install --upgrade setuptools


# install numpy, pytest and neuron
# we install setuptools because since python 3.12 it is no more installed
# by default
$python_exe -m pip install "numpy<2" pytest setuptools
# install test requirements
$python_exe -m pip install -r packaging/python/test_requirements.txt
$python_exe -m pip install $python_wheel
$python_exe -m pip show neuron \
|| $python_exe -m pip show neuron-nightly \
Expand Down Expand Up @@ -332,9 +336,14 @@ if [[ "$has_gpu_support" == "true" ]]; then
fi


# run tests
test_wheel $(which python)
# run tests with latest NumPy
echo " == Running tests with latest NumPy == "
test_wheel

# run basic python tests with oldest supported NumPy
echo " == Running basic python tests with oldest supported NumPy == "
$python_exe -m pip install -r packaging/python/oldest_numpy_requirements.txt
test_wheel_basic_python

# cleanup
if [[ "$use_venv" != "false" ]]; then
Expand Down
Loading
Loading