Ask Your Question
1

Cython compilation fail after separating code

asked 2022-11-04 01:21:53 +0100

alexhutman gravatar image

updated 2022-11-21 02:29:47 +0100

Hello,

I am on SageMath version 9.8.beta2, Release Date: 2022-10-16, Using Python 3.10.5.

I am using an Intel i9-12900K on WSL version 1.0.0.0, WSL Kernel version 5.15.74.2.


The code in my master branch is all in a big Cython file called OneGinormousFile.pyx. Running sage OneGinormousFile.pyx results in no compilation errors, and I'm able to call the functions defined in this file in a Jupyter notebook with no problems.

In the cleanup branch, I then tried separating the code into logical modules for easier readability/organization. When running sage setup.py build_ext --inplace, the fastqueue module compiles without any problems. The metagraph module, however, gives me a bunch of type coercion errors. Below is a brief snippet, but here is the full error log:

>sage --python3 setup.py build_ext --inplace

Compiling zeroforcing/metagraph/metagraph.pyx because it changed.
[1/1] Cythonizing zeroforcing/metagraph/metagraph.pyx

Error compiling Cython file:
------------------------------------------------------------
...

    cdef mp_bitcnt_t extra

    bits.size = size
    if fused_bitset_t is bitset_t:
        bits.limbs = (size - 1) / (8 * LIMB_SIZE) + 1
                                                 ^
------------------------------------------------------------

/mnt/e/projects/python/sage/src/sage/data_structures/bitset_base.pxd:177:50: Cannot assign type 'double' to 'mp_size_t'

Error compiling Cython file:
------------------------------------------------------------
...
    bits.size = size
    if fused_bitset_t is bitset_t:
        bits.limbs = (size - 1) / (8 * LIMB_SIZE) + 1
        bits.bits = <mp_limb_t*>check_calloc(bits.limbs, LIMB_SIZE)
    else:
        bits.limbs = ((size - 1) / (8*ALIGNMENT) + 1) * (ALIGNMENT/LIMB_SIZE)
                                                     ^
------------------------------------------------------------

/mnt/e/projects/python/sage/src/sage/data_structures/bitset_base.pxd:180:54: Cannot assign type 'double' to 'mp_size_t'

Error compiling Cython file:
------------------------------------------------------------
...
        bits.limbs = ((size - 1) / (8*ALIGNMENT) + 1) * (ALIGNMENT/LIMB_SIZE)
        extra = (ALIGNMENT + LIMB_SIZE - 2) // LIMB_SIZE
        bits.mem = check_calloc(bits.limbs + extra, LIMB_SIZE)
        bits.bits = <mp_limb_t*> align(bits.mem, ALIGNMENT)
        bits.non_zero_chunks_are_initialized = False
        bits.non_zero_chunks = <mp_bitcnt_t*> check_allocarray((bits.limbs*LIMB_SIZE) / ALIGNMENT, sizeof(mp_bitcnt_t))
                                                                                     ^
------------------------------------------------------------

/mnt/e/projects/python/sage/src/sage/data_structures/bitset_base.pxd:185:86: Cannot assign type 'double' to 'size_t'

Does anyone know why this is happening? There isn't a problem in the code since it's giving errors on Sage's bitset modules and it's only when the code is separated. I'm out of ideas ๐Ÿ˜…

edit retag flag offensive close merge delete

Comments

It would have been easier to debug with the name cleanup of the branch you are working on rather than describing partially what you did.

vdelecroix gravatar imagevdelecroix ( 2022-11-17 23:10:37 +0100 )edit

@vdelecroix I didn't want to be accused of not including enough information, so I included every step that I took along the way. I linked the cleanup branch in the links for fastqueue module and metagraph module, but I will add an addendum to make it a bit more clear.

alexhutman gravatar imagealexhutman ( 2022-11-21 02:25:49 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-11-17 23:07:25 +0100

vdelecroix gravatar image

It is not allowed (but not very well documented) to have a cython file zeroforcing/fastqueue/fastqueue.pyx in order to create the extension module zerforcing.fastqueue. Either

  • change the location to zeroforcing/fastqueue.pyx
  • or change the module name to zeroforcing.fastqueue.fastqueue (the first argument of Extension in your setup.py)
edit flag offensive delete link more

Comments

Thank you Vincent, this solved my problem! I ended up going with the former option since after re-evaluating, zeroforcing.fastqueue.fastqueue was a bit too redundant for the current use case.

alexhutman gravatar imagealexhutman ( 2022-11-21 02:23:58 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-11-04 01:21:53 +0100

Seen: 290 times

Last updated: Nov 21 '22