Caching a function that takes in a jitclass instance
See original GitHub issue@jitclass([])
class NumbaClass():
def __init__(self):
pass
@njit(cache=True)
def calc(numbaObj):
pass
numbaObject = NumbaClass()
calc(numbaObject)
Each time the script above is ran, it generates a new cache entry for “calc”, likely because NumbaClass.class_type.instance_type changes on every run, making the cache flag effectively not work and growing the __pycache__ folder on every run (mine eneded up being a few gigs). Is there a work-around for this? Numba 0.51.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Cache jitted function with jitclass argument - Numba Discussion
There's an open issue about this: Caching a function that takes in a jitclass instance · Issue #6522 · numba/numba · GitHub, unfortunately, ......
Read more >Reducing numba @jitclass compilation time (with caching?)
My guess is that because State isn't cached it compiles each time, and then the dependent functions requires compilation. Is there any solution ......
Read more >Compiling Python classes with @jitclass - Numba
All methods of a jitclass are compiled into nopython functions. The data of a jitclass instance is allocated on the heap as a...
Read more >Compiling Python classes with @jitclass
We call the resulting class object a jitclass. All methods of a jitclass are compiled into nopython functions. The data of a jitclass...
Read more >numba/numba-dev - Gitter
it wouldn't if you force use of jitclass ... that I made good progress on extending the cache invalidation to function dependencies here...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the report. I think your assessment of the situation is correct. Should probably warn users this doesn’t work and disable caching.
This is due to
id(self)
being part of the jitclass’ name:https://github.com/numba/numba/blob/f04f4b164887e5aa5ffeeed1bef317e13ec995f8/numba/core/types/misc.py#L425-L426I looked through the history but couldn’t figure out why it’s needed. I saw at some point early on (when jitclasses were being added), the sig didn’t include the fielddesc. But since it does include it now, it seems like that should be enough to fully define the type’s layout? Is there some problem I’m not seeing?
I tried removing
id(self)
, which makes caching work, and adding/removing fields works as expected too (just makes new cache entries).