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

Random bug while compiling #1485

Open
rfiischer opened this issue Mar 8, 2020 · 9 comments
Open

Random bug while compiling #1485

rfiischer opened this issue Mar 8, 2020 · 9 comments

Comments

@rfiischer
Copy link

While compiling my code, sometimes it works just fine. Other times, randomly, this happens

Traceback (most recent call last):
  File "E:\Python Projects\tcc\venv\Scripts\pythran-script.py", line 11, in <module>
    load_entry_point('pythran==0.9.5', 'console_scripts', 'pythran')()
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\run.py", line 179, in run
    **compile_flags(args))
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\toolchain.py", line 474, in compile_pythranfile
    **kwargs)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\toolchain.py", line 395, in compile_pythrancode
    module_dir)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\toolchain.py", line 143, in generate_cxx
    content = pm.dump(Cxx, ir)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\passmanager.py", line 225, in dump
    return b.run(node)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\passmanager.py", line 143, in run
    return super(ModuleAnalysis, self).run(node)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\passmanager.py", line 122, in run
    super(Analysis, self).run(node)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\passmanager.py", line 96, in run
    return self.visit(node)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\passmanager.py", line 78, in visit
    return super(ContextManager, self).visit(node)
  File "C:\Users\rodrf\Anaconda3\lib\ast.py", line 262, in visit
    return visitor(node)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\backend.py", line 1292, in visit_Module
    node.body)))
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\backend.py", line 1291, in <genexpr>
    decls_n_defns = list(filter(None, (self.visit(stmt) for stmt in
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\passmanager.py", line 78, in visit
    return super(ContextManager, self).visit(node)
  File "C:\Users\rodrf\Anaconda3\lib\ast.py", line 262, in visit
    return visitor(node)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\backend.py", line 1302, in visit_FunctionDef
    return visitor.visit(node)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\backend.py", line 226, in visit
    return super(CxxFunction, self).visit(node)
  File "C:\Users\rodrf\Anaconda3\lib\ast.py", line 262, in visit
    return visitor(node)
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\backend.py", line 325, in visit_FunctionDef
    for k in self.ldecls]
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\backend.py", line 325, in <listcomp>
    for k in self.ldecls]
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\cxxtypes.py", line 279, in generate
    self.of.generate(ctx))
  File "E:\Python Projects\tcc\venv\lib\site-packages\pythran-0.9.5-py3.7.egg\pythran\cxxtypes.py", line 279, in generate
    self.of.generate(ctx))
AttributeError: 'Type' object has no attribute 'generate'

running

import numpy as np


# pythran export fl(float64, float64)
# pythran export fr(float64, float64, float64)
# pythran export alpha_right(float64[:], uint8[:])
# pythran export alpha_left(float64[:])
# pythran export betas(uint8[:], uint8[:])
# pythran export compute_node(float64[:], uint64, uint64, uint64[:], uint8[:])


def fl(a, b):
    return np.log((1 + np.exp(a + b)) / (np.exp(a) + np.exp(b)))


def fr(a, b, c):
    return b + (1 - 2 * c) * a


def alpha_right(alphas, beta_arr):
    out_size = alphas.size // 2
    alphas_out = np.zeros(out_size)
    for i in range(0, out_size):
        alphas_out[i] = fr(alphas[i], alphas[i + out_size], beta_arr[i])

    return alphas_out


def alpha_left(alphas):
    out_size = alphas.size // 2
    alphas_out = np.zeros(out_size)
    for i in range(0, out_size):
        alphas_out[i] = fl(alphas[i], alphas[i + out_size])

    return alphas_out


def betas(betas_left, betas_right):
    betas_size = betas_left.size
    out_size = 2 * betas_size
    betas_out = np.zeros(out_size, dtype=np.uint8)
    for i in range(0, betas_size):
        betas_out[i] = betas_left[i] ^ betas_right[i]
        betas_out[i + betas_size] = betas_right[i]

    return betas_out


def compute_node(alphas, level, counter, information, dec_bits):
    """

    :param alphas: LLR's
    :param level: tree level
    :param counter: leaf counter
    :param information: a list containing the information bit indexes
    :param dec_bits: decoded bits array
    :return: betas
    """

    dec_bits = np.copy(dec_bits)

    if len(alphas) > 1:
        alpha_l = alpha_left(alphas)
        beta_l, dec_bits = compute_node(alpha_l, np.uint64(level / 2), np.uint64(counter), information, dec_bits)
        alpha_r = alpha_right(alphas, beta_l)
        beta_r, dec_bits = compute_node(alpha_r, np.uint64(level / 2), np.uint64(counter + level / 2),
                                        information, dec_bits)
        beta = betas(beta_l, beta_r)

    else:
        if counter in information:
            beta = np.array([0], dtype=np.uint8) if alphas > 0 else np.array([1], dtype=np.uint8)
            dec_bits[counter] = beta[0]

        else:
            beta = np.array([0], dtype=np.uint8)

    return beta, dec_bits

After the bug, I just run the same compile command and it works fine.

@rfiischer
Copy link
Author

That was on my desktop. On my notebook, it never compiles. That's on master branch.

@rfiischer
Copy link
Author

Just worked after rebooting the note. Could it be a memory issue? My desktop has 16GB, whereas my notebook has 8GB.

@serge-sans-paille
Copy link
Owner

I fail to reproduce, but #1486 may do the trick... does it change anything on your side?

@serge-sans-paille
Copy link
Owner

@rfiischer do you have the time to check #1486?

@rfiischer
Copy link
Author

Yes! I will do it soon. Sorry for the delay.

@rfiischer
Copy link
Author

This error still appears randomly on Debian on Google Cloud Computing on master.

@rfiischer
Copy link
Author

Using #1486 I get also randomly.

CRITICAL: Chair to keyboard interface error
E: Internal Compiler Error, unknown type met.

The file I am trying to compile is

"""
Base functions for polar coding

Created on 06/03/2020 16:52

@author: Rodrigo Fischer ([email protected])
"""

import numpy as np


# pythran export fl(float64, float64)
# pythran export fr(float64, float64, uint8)
# pythran export alpha_right(float64[:], uint8 list)
# pythran export alpha_left(float64[:])
# pythran export betas(uint8 list, uint8 list)
# pythran export compute_node(float64[:], uint64, uint64, uint64[:], uint8[:])
# pythran export encode(uint8[:], uint64)


def fl(a, b):
    return np.sign(a) * np.sign(b) * min(abs(a), abs(b))


def fr(a, b, c):
    return b + (1 - 2 * c) * a


def alpha_right(alphas, beta_arr):
    out_size = alphas.size // 2
    alphas_out = np.zeros(out_size, dtype=np.float64)
    for i in range(0, out_size):
        alphas_out[i] = fr(alphas[i], alphas[i + out_size], beta_arr[i])

    return alphas_out


def alpha_left(alphas):
    out_size = alphas.size // 2
    alphas_out = np.zeros(out_size, dtype=np.float64)
    for i in range(0, out_size):
        alphas_out[i] = fl(alphas[i], alphas[i + out_size])

    return alphas_out


def betas(betas_left, betas_right):
    betas_size = len(betas_left)
    out_size = 2 * betas_size
    betas_out = [0] * out_size
    for i in range(0, betas_size):
        betas_out[i] = betas_left[i] ^ betas_right[i]
        betas_out[i + betas_size] = betas_right[i]

    return betas_out


def compute_node(alphas, level, counter, information, dec_bits):
    """
    Recursive computation of node metrics

    :param alphas: LLR's
    :param level: tree level
    :param counter: leaf counter
    :param information: a list containing the information bit indexes
    :param dec_bits: decoded bits array
    :return: betas
    """

    if alphas.size > 1:
        alpha_l = alpha_left(alphas)
        beta_l = compute_node(alpha_l, level // 2, counter, information, dec_bits)
        alpha_r = alpha_right(alphas, beta_l)
        beta_r = compute_node(alpha_r, level // 2, counter + level // 2,
                              information, dec_bits)
        beta = betas(beta_l, beta_r)

    else:
        if counter in information:
            beta = [0] if alphas[0] > 0 else [1]
            dec_bits[counter] = beta[0]

        else:
            beta = [0]

    return beta


def encode(bits, n):
    stage_input = bits
    stage_output = np.zeros(2 ** n, dtype=np.uint8)
    for i in range(n):
        for j in range(2 ** i):
            stage_output[j * 2 ** (n - i):
                         (j + 1) * 2 ** (n - i)] = betas(stage_input[2 * j * 2 ** (n - 1 - i):
                                                                     (2 * j + 1) * 2 ** (n - 1 - i)],
                                                         stage_input[(2 * j + 1) * 2 ** (n - 1 - i):
                                                                     (2 * j + 2) * 2 ** (n - 1 - i)])

        stage_input = stage_output
        stage_output = np.zeros(2 ** n, dtype=np.uint8)

    return stage_input

with the command

pythran polarfuncs.py

@serge-sans-paille
Copy link
Owner

I still cannot reproduce (using master branch) how strange...

@rfiischer
Copy link
Author

Running further tests, I narrowed it down to the recursive compute_node function. I added some other recursive functions on my code that work just fine. My guess is: Python or external modules version. Can you provide the frozen requirements.txt and your Python version, so that I can run some tests?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants