mattkjames7 / PyGeopack

Wrapper for geopack-08 used for the Tsyganenko magnetic field models
GNU General Public License v3.0
11 stars 2 forks source link

Segmentation Fault on Clean Install (Linux) #14

Closed ddasilva closed 1 year ago

ddasilva commented 1 year ago

Steps to reproduce (does not include downloading the data):

  1. Make a new conda environment with Python 3.10
  2. Install PyGeopack from Pip
  3. Run the command python -c "import PyGeopack; print(PyGeopack.ModelField(-3, 0, 0, Date=20130101, ut=0, CoordIn='SM', CoordOut='SM', Model='T96'))"
  4. The code will segfault

I am using gfortran 12.2.0 and debian sid.

Full log:

daniel@desktop:~$ conda create --name gp-test python=3.10
Collecting package metadata (current_repodata.json): done
Solving environment: done

==> WARNING: A newer version of conda exists. <==
  current version: 4.14.0
  latest version: 22.11.1

Please update conda by running

    $ conda update -n base -c defaults conda

## Package Plan ##

  environment location: /home/daniel/.miniconda3/envs/gp-test

  added / updated specs:
    - python=3.10

The following NEW packages will be INSTALLED:

  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main
  _openmp_mutex      pkgs/main/linux-64::_openmp_mutex-5.1-1_gnu
  bzip2              pkgs/main/linux-64::bzip2-1.0.8-h7b6447c_0
  ca-certificates    pkgs/main/linux-64::ca-certificates-2022.10.11-h06a4308_0
  certifi            pkgs/main/linux-64::certifi-2022.12.7-py310h06a4308_0
  ld_impl_linux-64   pkgs/main/linux-64::ld_impl_linux-64-2.38-h1181459_1
  libffi             pkgs/main/linux-64::libffi-3.4.2-h6a678d5_6
  libgcc-ng          pkgs/main/linux-64::libgcc-ng-11.2.0-h1234567_1
  libgomp            pkgs/main/linux-64::libgomp-11.2.0-h1234567_1
  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-11.2.0-h1234567_1
  libuuid            pkgs/main/linux-64::libuuid-1.41.5-h5eee18b_0
  ncurses            pkgs/main/linux-64::ncurses-6.3-h5eee18b_3
  openssl            pkgs/main/linux-64::openssl-1.1.1s-h7f8727e_0
  pip                pkgs/main/linux-64::pip-22.3.1-py310h06a4308_0
  python             pkgs/main/linux-64::python-3.10.8-h7a1cb2a_1
  readline           pkgs/main/linux-64::readline-8.2-h5eee18b_0
  setuptools         pkgs/main/linux-64::setuptools-65.5.0-py310h06a4308_0
  sqlite             pkgs/main/linux-64::sqlite-3.40.0-h5082296_0
  tk                 pkgs/main/linux-64::tk-8.6.12-h1ccaba5_0
  tzdata             pkgs/main/noarch::tzdata-2022g-h04d1e81_0
  wheel              pkgs/main/noarch::wheel-0.37.1-pyhd3eb1b0_0
  xz                 pkgs/main/linux-64::xz-5.2.8-h5eee18b_0
  zlib               pkgs/main/linux-64::zlib-1.2.13-h5eee18b_0

Proceed ([y]/n)? y

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate gp-test
#
# To deactivate an active environment, use
#
#     $ conda deactivate

Retrieving notices: ...working... 
done
daniel@desktop:~$ 
daniel@desktop:~$ conda activate gp-test
daniel@desktop:~$ which python
/home/daniel/.miniconda3/envs/gp-test/bin/python
daniel@desktop:~$ pip install PyGeopack 
Collecting PyGeopack
  Downloading PyGeopack-1.1.2-py3-none-any.whl (4.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 15.7 MB/s eta 0:00:00
Collecting kpindex>=1.0.1
  Using cached kpindex-1.0.2-py3-none-any.whl (11 kB)
Collecting PyFileIO
  Using cached PyFileIO-0.0.5-py3-none-any.whl (10 kB)
Collecting DateTimeTools>=1.1.0
  Using cached DateTimeTools-1.1.1-py3-none-any.whl (241 kB)
Collecting RecarrayTools
  Using cached RecarrayTools-0.1.1-py3-none-any.whl (12 kB)
Collecting pyomnidata>=1.0.1
  Using cached pyomnidata-1.0.1-py3-none-any.whl (17 kB)
Collecting numpy
  Downloading numpy-1.24.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.3/17.3 MB 12.6 MB/s eta 0:00:00
Collecting scipy
  Downloading scipy-1.9.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (33.7 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 33.7/33.7 MB 6.7 MB/s eta 0:00:00
Collecting cdflib
  Downloading cdflib-0.4.9-py3-none-any.whl (72 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 72.9/72.9 kB 5.0 MB/s eta 0:00:00
Collecting matplotlib
  Downloading matplotlib-3.6.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.8 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.8/11.8 MB 15.2 MB/s eta 0:00:00
Collecting contourpy>=1.0.1
  Downloading contourpy-1.0.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (296 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 296.1/296.1 kB 3.7 MB/s eta 0:00:00
Collecting python-dateutil>=2.7
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 kB 32.5 MB/s eta 0:00:00
Collecting cycler>=0.10
  Downloading cycler-0.11.0-py3-none-any.whl (6.4 kB)
Collecting fonttools>=4.22.0
  Downloading fonttools-4.38.0-py3-none-any.whl (965 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 965.4/965.4 kB 26.9 MB/s eta 0:00:00
Collecting kiwisolver>=1.0.1
  Downloading kiwisolver-1.4.4-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 30.5 MB/s eta 0:00:00
Collecting pyparsing>=2.2.1
  Using cached pyparsing-3.0.9-py3-none-any.whl (98 kB)
Collecting pillow>=6.2.0
  Downloading Pillow-9.3.0-cp310-cp310-manylinux_2_28_x86_64.whl (3.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 25.6 MB/s eta 0:00:00
Collecting packaging>=20.0
  Downloading packaging-22.0-py3-none-any.whl (42 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 42.6/42.6 kB 2.7 MB/s eta 0:00:00
Collecting six>=1.5
  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, pyparsing, pillow, packaging, numpy, kiwisolver, fonttools, cycler, scipy, python-dateutil, contourpy, cdflib, RecarrayTools, matplotlib, DateTimeTools, PyFileIO, pyomnidata, kpindex, PyGeopack
Successfully installed DateTimeTools-1.1.1 PyFileIO-0.0.5 PyGeopack-1.1.2 RecarrayTools-0.1.1 cdflib-0.4.9 contourpy-1.0.6 cycler-0.11.0 fonttools-4.38.0 kiwisolver-1.4.4 kpindex-1.0.2 matplotlib-3.6.2 numpy-1.24.0 packaging-22.0 pillow-9.3.0 pyomnidata-1.0.1 pyparsing-3.0.9 python-dateutil-2.8.2 scipy-1.9.3 six-1.16.0
daniel@desktop:~$ python -c "import PyGeopack; print(PyGeopack.ModelField(-3, 0, 0, Date=20130101, ut=0, CoordIn='SM', CoordOut='SM', Model='T96'))"
Loading Model Parameter File:

Segmentation fault
ddasilva commented 1 year ago

I am also getting segfaults when I run it on a clean install on a Windows Subsytem for Linux installation of ubuntu

ddasilva commented 1 year ago

Here is a Dockerfile which reproduces the error with Ubuntu 20.04, Python 3.8.10, using the latest wheel from PyPI

Attachment: Dockerfile.txt

$ docker.exe run test
Python 3.8.10
Segmentation fault
mattkjames7 commented 1 year ago

Hi there,

Apologies for the late response, I was away from work over the Christmas period!

Thanks for reporting this bug - I can confirm that I also get the same segmentation faults on my Linux system. I am just attempting to figure out what is the problem...

mattkjames7 commented 1 year ago

Hello again,

I think I have fixed the bug in the ModelField() function. The segmentation fault appears to have originated in the wrapper code used by Python to call the C++ function - I added some arguments in C++ and forgot to update Python (whoops).

The newest version of the code is 1.1.3, which you can either upgrade using pip or download from here: https://github.com/mattkjames7/PyGeopack/releases/tag/v1.1.3

Please do let me know whether or not that fixes the problem for you!

Cheers.

ddasilva commented 1 year ago

Looks good for me, thanks!

I can add some simple tests that run under github actions after each push and result in an email notification if they fail. That would help prevent breaking changes like this. Would that pull request be welcome?

mattkjames7 commented 1 year ago

Great!

That sounds like a great idea, I would be happy to include it if you decide to create a pull request.