How to clear cache (or force recompilation) in numba

Viewed 3699

I have a fairly large codebase written in numba, and I have noticed that when the cache is enabled for a function calling another numba compiled function in another file, changes in the called function are not picked up when the called function is changed. The situation occurs when I have two files:

testfile2:

import numba

@numba.njit(cache=True)
def function1(x):
    return x * 10

testfile:

import numba
from tests import file1

@numba.njit(cache=True)
def function2(x, y):
    return y + file1.function1(x)

If in a jupyter notebook, I run the following:

# INSIDE JUPYTER NOTEBOOK
import sys
sys.path.insert(1, "path/to/files/")
from tests import testfile

testfile.function2(3, 4)
>>> 34   # good value

However, if I change then change testfile2 to the following:

import numba

@numba.njit(cache=True)
def function1(x):
    return x * 1

Then I restart the jupyter notebook kernel and rerun the notebook, I get the following

import sys
sys.path.insert(1, "path/to/files/")
from tests import testfile

testfile.function2(3, 4)
>>> 34   # bad value, should be 7

Importing both files into the notebook has no effect on the bad result. Also, setting cache=False only on function1 also has no effect. What does work is setting cache=False on all njit'ted functions, then restarting the kernel, then rerunning.

I believe that LLVM is probably inlining some of the called functions and then never checking them again.

I looked in the source and discovered there is a method that returns the cache object numba.caching.NullCache(), instantiated a cache object and ran the following:

cache = numba.caching.NullCache()
cache.flush()

Unfortunately that appears to have no effect.

Is there a numba environment setting, or another way I can manually clear all cached functions within a conda env? Or am I simply doing something wrong?

I am running numba 0.33 with Anaconda Python 3.6 on Mac OS X 10.12.3.

2 Answers
Related