brezniczky / ep_elections_2019_hun

Examining the Hungarian results of the 2019 European Parliamentary elections data
GNU General Public License v2.0
3 stars 0 forks source link

Persistent caching of simulated CDFs #18

Closed brezniczky closed 5 years ago

brezniczky commented 5 years ago

So that the edit/verify/push loop gets shortcut by about a lot esp. in refactoring situations.

brezniczky commented 5 years ago

The biggest issue with on disk caching is this or that I don't know what the suggested prevention of this from happening is:

from diskcache import Cache

cache = Cache()

@cache.memoize()
def memoized():
    return 5

x1 = memoized()

@cache.memoize()
def memoized():
    return 10

x2 = memoized()

assert x1 != x2
     19 
     20 
---> 21 assert x1 != x2
     22 
     23 

AssertionError: 
brezniczky commented 5 years ago

Another problem to foresee is largely depicted below - not sure if I'm just generally sloppy at defining decorators, but could be, anyway, my decorators typically don't return functions with unique names, therefore ... you know.

from diskcache import Cache

cache = Cache()

def primo_decorate(f):

    def wrapped(*args, **kwargs):
        return f(*args, **kwargs)

    return wrapped

@cache.memoize()
@primo_decorate
def memoized3(x):
    return x ** 2

z1 = memoized3(5)

@cache.memoize()
@primo_decorate
def memoized3_2(x):
    return x ** 2 + 1

z2 = memoized3_2(5)

assert(z1 != z2)

The assertion fails here too.

brezniczky commented 5 years ago

Of course, these scenarios will potentially frequently recur if I am refining analytics from the REPL.

brezniczky commented 5 years ago

Safe to say for now joblib's caching did the job.