def solver_scaled(I, dt, C, T): """ Solve 1D wave equation in dimensionless form. """ # Make a hash of the arguments import inspect, hashlib data = inspect.getsource(I) + '_' + str(dt) + '_' + \ str(C) + '_' + str(T) # Not fool proof: if x0 changes value, the source code of I # is still the same, and no recomputation takes place... hashed_input = hashlib.sha1(data).hexdigest() # Use joblib-based tool (class Storage) to store already # computed solutions in files cachedir = 'tmp_%s' % hashed_input is_computed = os.path.isdir(cachedir) print 'cachedir:', cachedir, is_computed storage = Storage(cachedir, verbose=0) def action(u, x, t, n): if n == 0: storage.save('x', x) storage.save('t', t) storage.save('u%d' % n, u) if is_computed: print 'No need to compute the numerical solution' return storage else: print 'Computing the numerical solution' solver_unscaled( I=I, V=0, f=0, c=1, L=1, dt=dt, C=C, T=T, user_action=action) return storage
def solver_scaled(I, dt, C, T): """ Solve 1D wave equation in dimensionless form. """ # Make a hash of the arguments import inspect, hashlib data = inspect.getsource(I) + '_' + str(dt) + '_' + \ str(C) + '_' + str(T) # Not fool proof: if x0 changes value, I source is the same... hashed_input = hashlib.sha1(data).hexdigest() cachedir = 'tmp_%s' % hashed_input is_computed = os.path.isdir(cachedir) import joblib memory = joblib.Memory(cachedir=cachedir, verbose=1) def retrieve(name, data=None): print 'joblib save of', name return data retrieve = memory.cache(retrieve, ignore=['data']) save = retrieve def action(u, x, t, n): if n == 0: save('x', x) save('t', t) save('u%d' % n, u) if is_computed: print 'No need to compute the numerical solution' return retrieve else: print 'Computing the numerical solution' solver_unscaled(I=I, V=0, f=0, c=1, L=1, dt=dt, C=C, T=T, user_action=action) return retrieve
def solver_scaled_prev(I, dt, C, T): """ Solve 1D wave equation in dimensionless form. """ # store solution in files? joblib? or just list in memory? # joblib doesn't handle I... Store u in joblib? retrieve/store Yes! def action(u, x, t, n): if n == 0: save('x', x) save('t', t) save('u%d' % n, u) # Make a hash of the arguments import inspect, hashlib data = inspect.getsource(I) + '_' + str(dt) + '_' + \ str(C) + '_' + str(T) hashed_input = hashlib.sha1(data).hexdigest() print 'hash:', hashed_input cachedir = 'tmp_%s' % hashed_input import joblib memory = joblib.Memory(cachedir=cachedir, verbose=1) @memory.cache(ignore=['data']) def retrieve(name, data=None): print 'joblib save of', name return data save = retrieve if os.path.isdir(cachedir): return retrieve else: print 'Computing the numerical solution' solver_unscaled(I=I, V=0, f=0, c=1, L=1, dt=dt, C=C, T=T, user_action=action) return retrieve
def solver_scaled(I, dt, C, T): """ Solve 1D wave equation in dimensionless form. """ # Make a hash of the arguments import inspect, hashlib data = inspect.getsource(I) + '_' + str(dt) + '_' + \ str(C) + '_' + str(T) # Not fool proof: if x0 changes value, I source is the same... hashed_input = hashlib.sha1(data).hexdigest() cachedir = 'tmp_%s' % hashed_input is_computed = os.path.isdir(cachedir) import joblib memory = joblib.Memory(cachedir=cachedir, verbose=1) def retrieve(name, data=None): print 'joblib save of', name return data retrieve = memory.cache(retrieve, ignore=['data']) save = retrieve def action(u, x, t, n): if n == 0: save('x', x) save('t', t) save('u%d' % n, u) if is_computed: print 'No need to compute the numerical solution' return retrieve else: print 'Computing the numerical solution' solver_unscaled( I=I, V=0, f=0, c=1, L=1, dt=dt, C=C, T=T, user_action=action) return retrieve
def solver_scaled_prev(I, dt, C, T): """ Solve 1D wave equation in dimensionless form. """ # store solution in files? joblib? or just list in memory? # joblib doesn't handle I... Store u in joblib? retrieve/store Yes! def action(u, x, t, n): if n == 0: save('x', x) save('t', t) save('u%d' % n, u) # Make a hash of the arguments import inspect, hashlib data = inspect.getsource(I) + '_' + str(dt) + '_' + \ str(C) + '_' + str(T) hashed_input = hashlib.sha1(data).hexdigest() print 'hash:', hashed_input cachedir = 'tmp_%s' % hashed_input import joblib memory = joblib.Memory(cachedir=cachedir, verbose=1) @memory.cache(ignore=['data']) def retrieve(name, data=None): print 'joblib save of', name return data save = retrieve if os.path.isdir(cachedir): return retrieve else: print 'Computing the numerical solution' solver_unscaled( I=I, V=0, f=0, c=1, L=1, dt=dt, C=C, T=T, user_action=action) return retrieve