Trouble installing CyPari2 and wrapping PARI libraries

411 views
Skip to first unread message

Jonathan Hanke

unread,
Jan 25, 2019, 7:31:55 AM1/25/19
to cython...@googlegroups.com, jonhanke
Hi,

I'm trying to interface with PARI (2.11.1) libraries from Python using Cython and came across the CyPari2 package which looks really convenient, but am having trouble installing it in Docker on the continuumio/anaconda2 image using either 

RUN pip install cypari2

or

RUN pip install cysignals --upgrade
RUN pip install cypari2 --upgrade

In the Dockerfile, I've prebuilt GMP and PARI into the "/app/EXTERNAL_SOFTWARE/local" directory of the image. When using just "RUN pip install cypari2" it gives "Error: No module named cysignals".  The meaning of the error from the second option is less clear since pip has already been upgraded (see attachment for full output):

  building 'cypari2.gen' extension
    /usr/bin/gcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I./cypari2 -I/opt/conda/lib/python2.7/site-packages/cysignals -I/app/EXTERNAL_SOFTWARE/local/include -I/opt/conda/include/python2.7 -c cypari2/gen.c -o build/temp.linux-x86_64-2.7/cypari2/gen.o
    gcc: internal compiler error: Killed (program cc1)
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <file:///usr/share/doc/gcc-6/README.Bugs> for instructions.
    error: command '/usr/bin/gcc' failed with exit status 4
    
    ----------------------------------------
[91mCommand "/opt/conda/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-BQfMze/cypari2/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-pb7876/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-BQfMze/cypari2/
[0m [91mYou are using pip version 18.0, however version 19.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[0mThe command '/bin/sh -c pip install cypari2 --upgrade' returned a non-zero code: 1
Makefile:6: recipe for target 'build' failed
make: *** [build] Error 1


I also tried to interface directly with a few PARI functions directly using Cython with the pari.pxd, pari.pyx and setup.py files below.  The pari_test() function works, pari_qfrep0 fails when calling the pari_printf() function, and pari_qfisom() fails when calling qfisom().  Both of these failures give a "bug in PARI/GP (segmentation fault)" to report to PARI, but I wanted to check if this was an issue with the way I'm using Cython to perform the wrapping first.  

Any comments to help get these working would be appreciated!

Thanks,
-Jon

============================================

setup.py:
---------
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize

ext = Extension('pari',
                sources=['pari.pyx'],
                include_dirs = ['/app/EXTERNAL_SOFTWARE/local/include/pari', '/usr/local/include', '.'],
                libraries = ['gmp', 'gmpxx', 'pari'],
                library_dirs = ['/app/EXTERNAL_SOFTWARE/local/lib', '/usr/local/lib'],
                language='c++')

setup(
    ext_modules = cythonize([ext])
)

pari.pxd:
---------
## Declare the PARI header files that we're using in pari.pyx
cdef extern from "pari.h":
ctypedef long *GEN
ctypedef unsigned long ulong
cdef GEN gp_read_str(const char *t)
cdef GEN qfisom(GEN G, GEN H, GEN fl, GEN grp)
cdef GEN qfrep0(GEN a, GEN borne, long flag)
cdef void pari_init(size_t pari_size, ulong maxprime)
cdef void pari_printf(const char *fmt, ...)
cdef void pari_flush()


pari.pyx:
---------
## Python function using the C++ function calling the PARI library
def pari_test():
    """
    Returns the results of a few PARI routines.
    """
    ## Initialize the PARI stack with 4MB and all primes up to 2.
    pari_init(4000000, 2)

    ## Create a Pari matrix
    PARI_MATRIX = gp_read_str("[1, 0; 0, 1]")

    ## Print the matrix
    pari_printf("%Pd\n", PARI_MATRIX)
    pari_flush()


## Compute an isomorphism between two quadratic forms (if one exists)
def pari_qfrep0():
    """
    The qfrep0() routine from PARI.  This takes a square symmetric integer Gram matrix
    and returns the theta series. 
    """
    ## Initialize the PARI stack with 4MB and all primes up to 2.
    pari_init(4000000, 2)

    ## Call the PARI function qfrep0
    PARI_MATRIX = gp_read_str("[1, 0; 0, 1]")
    PARI_PRECISION = gp_read_str("20")
    ans_GEN = qfrep0(PARI_MATRIX, PARI_PRECISION, 0)

    ## Print the answer
    pari_printf("%Pd\n", ans_GEN[0])
    pari_flush()


## Compute an isomorphism between two quadratic forms (if one exists)
def pari_qfisom():
    """
    The qfisom() routine from PARI.  This takes two square symmetric integer matrices and either returns 
    False or a matrix that gives this automorphism.  
    """
    ## Initialize the PARI stack with 4MB and all primes up to 2.
    pari_init(4000000, 2)

    ## Call the PARI function qfisom
    PARI_MATRIX = gp_read_str("[1, 0; 0, 1]")
    ans_GEN = qfisom(PARI_MATRIX, PARI_MATRIX, NULL, NULL)

    ## Print the answer
    pari_printf("%Pd\n", ans_GEN)
    pari_flush()


cypari2_failed_build.txt

Jeroen Demeyer

unread,
Jan 25, 2019, 11:46:33 AM1/25/19
to cython...@googlegroups.com
On 2019-01-25 13:31, Jonathan Hanke wrote:
> gcc: internal compiler error: Killed (program cc1)

That's a genuine problem unrelated to cypari2. Most likely causes are:

- broken compiler
- running out of memory (check dmesg for OOM killer)
- broken hardware

Is the error reproducible, i.e. does it happen every time that you try
the same commands?

PS: I am the main cypari2 developer, happy to see some interest!

Jonathan Hanke

unread,
Jan 25, 2019, 5:03:11 PM1/25/19
to cython-users
Thanks Jeroen for reaching out and for working on developing cypari2!  Yes, these errors seem to be reproducible.  I've added repository here to try out, with the cypari2 installation lines commented out in the Dockerfile so the build can proceed.  

For the Cython wrapper code, one can use "make build; make run" to get it going in ipython.  Then "pari.qfrep0()" or "pari.qfisom()" will cause the segfault.

Thanks,
-Jon

Jeroen Demeyer

unread,
Jan 27, 2019, 6:25:42 PM1/27/19
to cython...@googlegroups.com
On 2019-01-25 23:03, Jonathan Hanke wrote:
> Thanks Jeroen for reaching out and for working on developing cypari2!
> Yes, these errors seem to be reproducible. I've added repository here
> <https://github.com/jonhanke/cypari2_test> to try out, with the cypari2
> installation lines commented out in the Dockerfile so the build can
> proceed.

Sorry, I don't have enough experience with Conda/Docker to help you
here. Did you check your memory? Running out of memory is the most
likely explanation for that "gcc: internal compiler error: Killed",
especially given the fact that gen.c is a pretty large file.
Reply all
Reply to author
Forward
0 new messages