mystic.cache module documentation

archive module

klepto archive readers and writers, for functions and data

get_dist(archive, func, keymap=None)

get the graphical distance of func from data in archive

Parameters
  • archive (klepto.archive) – run archive (output of read)

  • func (function) – with interface y = f(x), x is a list of floats

  • keymap (klepto.keymap) – keymap used for key encoding

Returns

array of floats, graphical distance from func to each point in archive

read(name, keys=None, keymap=None, type=None)

read klepto db with name ‘name’

Parameters
  • 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.

read_func(name, keymap=None, type=None, n=0)

read stored function from db with name ‘name’

Parameters
  • name (string) – filename of the klepto db

  • keymap (klepto.keymap) – keymap used for key encoding

  • type (klepto.archive) – type of klepto archive

  • n (int) – db entry in reverse order (i.e. most recent is 0)

Returns

tuple of (stored function, distance information)

Notes

If the db is empty, or n produces a bad index, returns None. Alternately, name can be the relevant klepto.archive instance.

write(archive, entries, keymap=None)

write entries to klepto db instance ‘archive’

Parameters
  • archive (klepto.archive) – archive instance

  • entries (iterable) – iterable/dict to update the archive with

  • keymap (klepto.keymap) – keymap used for key encoding

Returns

None

Examples

>>> write(foo, {x0:y0, x1:y1, ...})
>>> write(foo, ((x0,y0), (x1,y1), ...))

Notes

Within entries, xi is a tuple of floats, and yi is a float.

function module

higher-level readers and writers for stored functions

db(name)

get function db with the name ‘name’

read(archives)

read stored functions from the list of dbs

Parameters

archives (list[string]) – list of names of function archives

Returns

a klepto.archive instance

Notes

The order of the dbs is important, with the index of archives corresponding to the desired axis. If a db is empty, returns None for the empty db. Also, a klepto.archive instance can be provided instead of the name of the db.

write(function, archives)

write function to corresponding archives