Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@lru_cache(maxsize=3, cache=dict_archive('test'), purge=True)
def identity(x):
return x
@lru_cache(maxsize=3, cache=dict_archive('test', cached=False))
def foo(x):
return x
@memoized(cache=dict_archive(cached=False)) # use archive backend 'direcly'
def add(x,y):
return x+y
add(1,2)
except:
index = {}
# should have at least one column; if so, get the name of the column
name = df.columns[0] if len(df.columns) else None
# get the name of the column -- this will be our cached data
store = df.columns[1] if cached else cache
# get the data from the first column
data = {} if name is None else dict((k,v) for (k,v) in d[name].items() if repr(v) not in ['nan','NaN'])
# get the archive type, defaulting to dict_archive
col = df.columns.name
try:
col = col if col.endswith('_archive') else ''.join((col,'_archive'))
except AttributeError:
col = ''
import klepto.archives as archives
d_ = getattr(archives, col, archives.dict_archive)
# get the archive instance
d_ = d_(name, data, cached, **index)
# if cached, add the cache data
if cached: d_.archive.update((k,v) for (k,v) in d.get(store,{}).items() if repr(v) not in ['nan','NaN'])
return d_
def UseArchive(self, min=None, max=None):
"""track sampled points in an archive(s)
Input:
min: archive instance to store minima; if True, use a new archive
max: archive instance to store maxima; if True, use a new archive
Output:
None
"""
from klepto.archives import dict_archive as d
if type(min) is bool: self._minarch = d(cached=False) if min else None
elif min is not None: self._minarch = min
if type(max) is bool: self._maxarch = d(cached=False) if max else None
elif max is not None: self._maxarch = max
return
disp - if True, be verbose
repeat - number of times to repeat the search
"""
#XXX: better not to use klepto as default? just dict and false cache?
from klepto.archives import dict_archive as _archive
from mystic.solvers import BuckshotSolver #XXX: or SparsitySolver?
from mystic.solvers import PowellDirectionalSolver
from mystic.pools import SerialPool as Pool
import sys
if (sys.hexversion >= 0x30000f0):
from builtins import map as _map
else:
from __builtin__ import map as _map
del sys
self.archive = _archive(cached=False) if archive is None else archive
self.cache = _archive(cached=False) if cache is None else cache
self.sprayer = BuckshotSolver if sprayer is None else sprayer
self.seeker = PowellDirectionalSolver if seeker is None else seeker
self.map = Pool().map if map in (None, _map) else map
self.traj = traj
self.disp = disp
self.npts = npts # number of solvers
self.retry = retry # max consectutive retries w/o a cache 'miss'
self.repeat = repeat # number of times to repeat the search
self.tol = tol # rounding precision
self.memtol = memtol # memoization rounding precision
self.memsize = memsize # max in-memory cache size
self._allSolvers = []
self._inv = False # self-awareness: am I inverted (maximizing)?
return
traj - if True, save the parameter trajectories
disp - if True, be verbose
repeat - number of times to repeat the search
"""
#XXX: better not to use klepto as default? just dict and false cache?
from klepto.archives import dict_archive as _archive
from mystic.solvers import BuckshotSolver #XXX: or SparsitySolver?
from mystic.solvers import PowellDirectionalSolver
from mystic.pools import SerialPool as Pool
import sys
if (sys.hexversion >= 0x30000f0):
from builtins import map as _map
else:
from __builtin__ import map as _map
del sys
self.archive = _archive(cached=False) if archive is None else archive
self.cache = _archive(cached=False) if cache is None else cache
self.sprayer = BuckshotSolver if sprayer is None else sprayer
self.seeker = PowellDirectionalSolver if seeker is None else seeker
self.map = Pool().map if map in (None, _map) else map
self.traj = traj
self.disp = disp
self.npts = npts # number of solvers
self.retry = retry # max consectutive retries w/o a cache 'miss'
self.repeat = repeat # number of times to repeat the search
self.tol = tol # rounding precision
self.memtol = memtol # memoization rounding precision
self.memsize = memsize # max in-memory cache size
self._allSolvers = []
self._inv = False # self-awareness: am I inverted (maximizing)?
return
def UseArchive(self, min=None, max=None):
"""track sampled points in an archive(s)
Input:
min: archive instance to store minima; if True, use a new archive
max: archive instance to store maxima; if True, use a new archive
Output:
None
"""
from klepto.archives import dict_archive as d
if type(min) is bool: self._minarch = d(cached=False) if min else None
elif min is not None: self._minarch = min
if type(max) is bool: self._maxarch = d(cached=False) if max else None
elif max is not None: self._maxarch = max
return