Pickling numba within closures?

Hey all, I’m doing some dynamic compilation with branch pruning. Up until now did it with functional closures, but I just realized I’m unable to pickle the anonymous classes within the closure - is there any way to actually save such a function/jitclass?

(I tried to save manually as apparently numba caching doesn’t work with global variables)

from numba.experimental import jitclass
import numba as nb
import pickle

def dyn_compile(value_dtype):
   # THIS FAILS 
   @jitclass
   class Bag(object):
       value: value_dtype
       def __init__(self, value):
           self.value = value
   
       def clone(self):
           return Bag(self.value)

    return Bag

comp = dyn_compile(nb.int64)

res = comp(1)
print(res)

with open('test.pkl', 'wb') as f:
   pickle.dump(comp, f)

My current idea - perhaps its possible to just pickle the compiled binary and later somehow restore it back?

Any help/pointers highly appreciated! :slight_smile:

EDIT - removing the part about anonymous functions, only anonymous jitclasses don’t work

I’m not following this… You have an example of what you mean here?