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

Numba 0.54 NumbaIRAssumptionWarning #178

Closed
mhostetter opened this issue Aug 24, 2021 · 4 comments · Fixed by #173 or #207
Closed

Numba 0.54 NumbaIRAssumptionWarning #178

mhostetter opened this issue Aug 24, 2021 · 4 comments · Fixed by #173 or #207
Assignees
Labels
numba compatibility Affects compatibility with Numba

Comments

@mhostetter
Copy link
Owner

Numba 0.53.1

In [1]: import numba                                                                                                                                                                                                                 

In [2]: import galois                                                                                                                                                                                                                

In [3]: numba.__version__                                                                                                                                                                                                            
Out[3]: '0.53.1'

In [4]: galois.__version__                                                                                                                                                                                                           
Out[4]: '0.0.19'

In [5]: GF = galois.GF(2**8, compile="jit-calculate")                                                                                                                                                                                

In [6]: a = GF.Random(10); a                                                                                                                                                                                                         
Out[6]: GF([191, 116,  80,  93, 191,  52,  93, 174, 195, 244], order=2^8)

In [7]: b = GF.Random(10); b                                                                                                                                                                                                         
Out[7]: GF([251, 216, 189, 173,  24, 209, 184, 170, 154, 126], order=2^8)

In [8]: a * b                                                                                                                                                                                                                        
Out[8]: GF([ 21,  64,  99,  40, 174, 205, 165, 177, 104,  42], order=2^8)

Numba 0.54

In [1]: import numba                                                                                                                                                                                                                 

In [2]: import galois                                                                                                                                                                                                                

In [3]: numba.__version__                                                                                                                                                                                                            
Out[3]: '0.54.0'

In [4]: galois.__version__                                                                                                                                                                                                           
Out[4]: '0.0.19'

In [5]: GF = galois.GF(2**8, compile="jit-calculate")                                                                                                                                                                                

In [6]: a = GF.Random(10); a                                                                                                                                                                                                         
Out[6]: GF([ 89, 195, 178, 200, 222,  96,  53,   9,  20,  12], order=2^8)

In [7]: b = GF.Random(10); b                                                                                                                                                                                                         
Out[7]: GF([207,  45,  38, 249, 151,  37,   5, 139,  80, 198], order=2^8)

In [8]: a * b                                                                                                                                                                                                                        
/home/matt/.local/lib/python3.8/site-packages/numba/core/ssa.py:272: NumbaIRAssumptionWarning: variable 'b.1.1' is not in scope.

This warning came from an internal pedantic check. Please report the warning
message and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new?template=bug_report.md

  warnings.warn(errors.NumbaIRAssumptionWarning(wmsg,
/home/matt/.local/lib/python3.8/site-packages/numba/core/ssa.py:272: NumbaIRAssumptionWarning: variable 'a.1.1' is not in scope.

This warning came from an internal pedantic check. Please report the warning
message and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new?template=bug_report.md

  warnings.warn(errors.NumbaIRAssumptionWarning(wmsg,
Out[8]: GF([ 56, 251,  72, 114, 110,  97, 225, 167,  52,  65], order=2^8)
@mhostetter mhostetter added the numba compatibility Affects compatibility with Numba label Aug 24, 2021
@mhostetter mhostetter self-assigned this Aug 24, 2021
@mhostetter mhostetter linked a pull request Aug 24, 2021 that will close this issue
@mhostetter mhostetter reopened this Aug 24, 2021
@mhostetter
Copy link
Owner Author

Pinned Numba to <0.54 in c14f2ca.

@mhostetter
Copy link
Owner Author

mhostetter commented Dec 6, 2021

As of this date with galois v0.0.22, this warning still persists. This warning appears with Numba v0.54.0 and v0.54.1.

In [1]: import galois

In [2]: galois.__version__
Out[2]: '0.0.22'

In [3]: import numba

In [4]: numba.__version__
Out[4]: '0.54.0'

In [5]: GF = galois.GF(2**8, compile="jit-calculate")

In [6]: x = GF.Random(10); x
Out[6]: GF([ 65, 146, 183, 209, 229, 126,  21, 182,  85,  43], order=2^8)

In [7]: y = GF.Random(10); y
Out[7]: GF([193, 201,   2,   2, 123, 188,  14, 203, 128,  90], order=2^8)

In [8]: x * y
/home/matt/.local/lib/python3.8/site-packages/numba/core/ssa.py:272: NumbaIRAssumptionWarning: variable 'a.1.1' is not in scope.

This warning came from an internal pedantic check. Please report the warning
message and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new?template=bug_report.md

  warnings.warn(errors.NumbaIRAssumptionWarning(wmsg,
/home/matt/.local/lib/python3.8/site-packages/numba/core/ssa.py:272: NumbaIRAssumptionWarning: variable 'b.1.1' is not in scope.

This warning came from an internal pedantic check. Please report the warning
message and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new?template=bug_report.md

  warnings.warn(errors.NumbaIRAssumptionWarning(wmsg,
Out[8]: GF([203, 227, 115, 191, 177,  11, 214, 137, 213, 139], order=2^8)

@mhostetter
Copy link
Owner Author

Replacing the inputs a and b with aa and bb resolves the warning. Hmmm...

    @staticmethod
    @numba.extending.register_jitable(inline="always")
    def _multiply_calculate(aa, bb, CHARACTERISTIC, DEGREE, IRREDUCIBLE_POLY):
        """
        a in GF(2^m), can be represented as a degree m-1 polynomial a(x) in GF(2)[x]
        b in GF(2^m), can be represented as a degree m-1 polynomial b(x) in GF(2)[x]
        p(x) in GF(2)[x] with degree m is the irreducible polynomial of GF(2^m)

        a * b = c
            = (a(x) * b(x)) % p(x) in GF(2)
            = c(x)
            = c
        """
        ORDER = CHARACTERISTIC**DEGREE

        # Re-order operands such that a > b so the while loop has less loops
        if bb > aa:
            aa, bb = bb, aa

        c = 0
        while bb > 0:
            if bb & 0b1:
                c ^= aa  # Add aa(x) to c(x)

            bb >>= 1  # Divide bb(x) by x
            aa <<= 1  # Multiply aa(x) by x
            if aa >= ORDER:
                aa ^= IRREDUCIBLE_POLY  # Compute aa(x) % p(x)

        return c
In [1]: import galois

In [2]: galois.__version__
Out[2]: '0.0.22'

In [3]: import numba

In [4]: numba.__version__
Out[4]: '0.54.1'

In [5]: GF = galois.GF(2**8, compile="jit-calculate")

In [6]: x = GF.Random(10); x
Out[6]: GF([116,  50, 199, 161, 194, 123,  31,  58, 165,  93], order=2^8)

In [7]: y = GF.Random(10); y
Out[7]: GF([139, 204,   7,   0, 153, 132, 226,  80,  85,  14], order=2^8)

In [8]: x * y
Out[8]: GF([131,  97, 111,   0, 169, 186,  81, 161, 187,   1], order=2^8)

@mhostetter
Copy link
Owner Author

I filed numba/numba#7623. It appears renaming the lambda arguments resolves the issue as well.

For instance

            if cls._UFUNC_TYPE[name] == "unary":
                cls._UFUNC_CACHE_CALCULATE[key] = numba.vectorize(["int64(int64)"], nopython=True)(lambda a: function(a, characteristic, degree, irreducible_poly))
            else:
                cls._UFUNC_CACHE_CALCULATE[key] = numba.vectorize(["int64(int64, int64)"], nopython=True)(lambda a, b: function(a, b, characteristic, degree, irreducible_poly))

to

            if cls._UFUNC_TYPE[name] == "unary":
                cls._UFUNC_CACHE_CALCULATE[key] = numba.vectorize(["int64(int64)"], nopython=True)(lambda aa: function(aa, characteristic, degree, irreducible_poly))
            else:
                cls._UFUNC_CACHE_CALCULATE[key] = numba.vectorize(["int64(int64, int64)"], nopython=True)(lambda aa, bb: function(aa, bb, characteristic, degree, irreducible_poly))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
numba compatibility Affects compatibility with Numba
Projects
None yet
1 participant