Exemple #1
0
def read(name, keys=None, keymap=None, type=None):
    """read klepto db with name 'name'

    Args:
        name (string): filename of the klepto db
        keys (iterable): keys to load; or boolean to load all/no keys
        keymap (klepto.keymap): used for key encoding
        type (klepto.archive): type of klepto archive

    Returns:
        klepto db object (has dictionary-like interface)

    Notes:
        If keys is None, create a direct handle to the db.
        If a key in keys is not found, it will be ignored.
    """
    if type is None:
        from klepto.archives import dir_archive as _archive
    else:
        _archive = type
    if keys is None:
        return _archive(name, cached=False)
    if keymap is None:
        from klepto.keymaps import keymap as _kmap
        keymap = _kmap()
    archive = _archive(name, cached=True)
    if keys is False:
        return archive
    if keys is True:
        archive.load()
    else:  # apply keymap to keys
        archive.load(*(keymap(*(k if hasattr(k, '__len__') else (k, )))
                       for k in keys))
    return archive  # archive with keymapped keys
Exemple #2
0
    def __init__(self,
                 npts=4,
                 retry=1,
                 tol=8,
                 memtol=1,
                 memsize=None,
                 map=None,
                 archive=None,
                 cache=None,
                 sprayer=None,
                 seeker=None,
                 traj=False,
                 disp=False,
                 repeat=0):
        """searcher, which searches for all minima of a response surface

        Input:
          npts - number of solvers in the ensemble
          retry - max consectutive retries w/o a cache 'miss'
          tol - rounding precision for the minima comparator
          memtol - rounding precision for memoization
          memsize - maximum size of cache to hold in memory
          map - map used for spawning solvers in the ensemble
          archive - the sampled point archive(s)
          cache - the trajectory cache(s)
          sprayer - the mystic.ensemble instance
          seeker - the mystic.solvers instance
          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
Exemple #3
0
    def __init__(self, npts=4, retry=1, tol=8, memtol=1, memsize=None,
                       map=None, archive=None, cache=None, sprayer=None,
                       seeker=None, traj=False, disp=False, repeat=0):
        """searcher, which searches for all minima of a response surface

        Input:
          npts - number of solvers in the ensemble
          retry - max consectutive retries w/o a cache 'miss'
          tol - rounding precision for the minima comparator
          memtol - rounding precision for memoization
          memsize - maximum size of cache to hold in memory
          map - map used for spawning solvers in the ensemble
          archive - the sampled point archive(s)
          cache - the trajectory cache(s)
          sprayer - the mystic.ensemble instance
          seeker - the mystic.solvers instance
          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 __init__(self,
                 npts=4,
                 retry=1,
                 tol=8,
                 memtol=1,
                 map=None,
                 archive=None,
                 sprayer=None,
                 seeker=None,
                 traj=False,
                 disp=False):

        #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
        from mystic.solvers import PowellDirectionalSolver
        from mystic.pools import SerialPool as Pool
        from __builtin__ import map as _map
        self.archive = _archive(cached=False) if archive is None else archive
        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.tol = tol  # rounding precision
        self.memtol = memtol  # memoization rounding precision
        self._allSolvers = []
        self._inv = False  # self-awareness: am I inverted (maximizing)?
        return
Exemple #5
0
    def __init__(self, npts=4, retry=1, tol=8, memtol=1, map=None,
              archive=None, sprayer=None, seeker=None, traj=False, disp=False):

        #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
        from mystic.solvers import PowellDirectionalSolver
        from mystic.pools import SerialPool as Pool
        from __builtin__ import map as _map
        self.archive = _archive(cached=False) if archive is None else archive
        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.tol = tol       # rounding precision
        self.memtol = memtol # memoization rounding precision
        self._allSolvers = []
        self._inv = False    # self-awareness: am I inverted (maximizing)?
        return