quimb.utils#

Miscellenous

Functions

check_opt(name, value, valid)

deprecated(fn, old_name, new_name)

ensure_dict(x)

Make sure x is a dict, creating an empty one if x is None.

find_library(x)

Check if library is installed.

gen_bipartitions(it)

Generate all unique bipartitions of it.

int2tup(x)

load_from_disk(fname, **load_opts)

Load an object form disk using joblib.load.

pairwise(iterable)

Iterate over each pair of neighbours in iterable.

print_multi_line(*lines[, max_width])

progbar(*args, **kwargs)

raise_cant_find_library_function(x[, extra_msg])

Return function to flag up a missing necessary library.

save_to_disk(obj, fname, **dump_opts)

Save an object to disk using joblib.dump.

Classes

LRU(maxsize, *args, **kwds)

Least recently used dict, which evicts old items.

Verbosify(fn[, highlight, mpi])

Decorator for making functions print their inputs.

continuous_progbar(*_, **__)

A continuous version of tqdm, so that it can be updated with a float within some pre-given range, rather than a number of steps.

oset([it])

An ordered set which stores elements as the keys of dict (ordered as of python 3.6).

class quimb.utils.LRU(maxsize, *args, **kwds)[source]#

Least recently used dict, which evicts old items. Taken from python collections OrderedDict docs.

class quimb.utils.Verbosify(fn, highlight=None, mpi=False)[source]#

Decorator for making functions print their inputs. Simply for illustrating a MPI example in the docs.

class quimb.utils.continuous_progbar(*_, **__)[source]#

A continuous version of tqdm, so that it can be updated with a float within some pre-given range, rather than a number of steps.

Parameters
  • args ((stop) or (start, stop)) – Stopping point (and starting point if len(args) == 2) of window within which to evaluate progress.

  • total (int) – The number of steps to represent the continuous progress with.

  • kwargs – Supplied to tqdm.tqdm

cupdate(x)[source]#

‘Continuous’ update of progress bar.

Parameters

x (float) – Current position within the range [self.start, self.stop].

quimb.utils.ensure_dict(x)[source]#

Make sure x is a dict, creating an empty one if x is None.

quimb.utils.find_library(x)[source]#

Check if library is installed.

Parameters

x (str) – Name of library

Returns

If library is available.

Return type

bool

quimb.utils.gen_bipartitions(it)[source]#

Generate all unique bipartitions of it. Unique meaning (1, 2), (3, 4) is considered the same as (3, 4), (1, 2).

quimb.utils.load_from_disk(fname, **load_opts)[source]#

Load an object form disk using joblib.load.

class quimb.utils.oset(it=())[source]#

An ordered set which stores elements as the keys of dict (ordered as of python 3.6). ‘A few times’ slower than using a set directly for small sizes, but makes everything deterministic.

classmethod from_dict(d)[source]#

Public method makes sure to copy incoming dictionary.

quimb.utils.pairwise(iterable)[source]#

Iterate over each pair of neighbours in iterable.

quimb.utils.raise_cant_find_library_function(x, extra_msg=None)[source]#

Return function to flag up a missing necessary library.

This is simplify the task of flagging optional dependencies only at the point at which they are needed, and not earlier.

Parameters
  • x (str) – Name of library

  • extra_msg (str, optional) – Make the function print this message as well, for additional information.

Returns

A mock function that when called, raises an import error specifying the required library.

Return type

callable

quimb.utils.save_to_disk(obj, fname, **dump_opts)[source]#

Save an object to disk using joblib.dump.