jammy.utils package¶
Submodules¶
jammy.utils.argument module¶
- class jammy.utils.argument.UniqueValueGetter(msg='unique value check failed', default=None)[source]¶
Bases:
object
- jammy.utils.argument.astuple(arr_like)[source]¶
Convert a sequence or a single value to a tuple. This method differ from the system method tuple in that a single value (incl. int, string, bytes) will be converted to a tuple of length 1.
- Args:
arr_like: a sequence or a single value.
Returns: a tuple.
- jammy.utils.argument.canonize_args_list(args, *, allow_empty=False, cvt=None)[source]¶
Convert the argument list to a tuple of values. This is useful to make unified interface for shape-related operations. E.g.,
>>> np.zeros(6).reshape(2, 3) >>> np.zeros(6).reshape((2, 3))
- Args:
args: allow_empty: cvt:
Returns:
jammy.utils.cache module¶
jammy.utils.cfg module¶
jammy.utils.cnt module¶
- class jammy.utils.cnt.BufferCnt(thres=inf, reset_over_thres=False)[source]¶
Bases:
object
- property cnt¶
- class jammy.utils.cnt.CBCnt(cb_fn=None, thres=inf, reset_over_thres=False)[source]¶
Bases:
BufferCnt
jammy.utils.colored_tqdm module¶
- class jammy.utils.colored_tqdm.Coloredtqdm(*_, **__)[source]¶
Bases:
tqdm_asyncio
- set_postfix(ordered_dict=None, refresh=True, color=True, round=4, **kwargs)[source]¶
Set/modify postfix (additional stats) with automatic formatting based on datatype.
Parameters¶
ordered_dict : dict or OrderedDict, optional refresh : bool, optional
Forces refresh [default: True].
kwargs : dict, optional
jammy.utils.container module¶
jammy.utils.context module¶
jammy.utils.debug module¶
jammy.utils.defaults module¶
- jammy.utils.defaults.gen_get_default(cls, default_getter=None)¶
- jammy.utils.defaults.gen_set_default(cls)¶
- jammy.utils.defaults.wrap_custom_as_default(*, is_local=False)¶
jammy.utils.deprecated module¶
jammy.utils.enum module¶
jammy.utils.env module¶
jammy.utils.filelock module¶
jammy.utils.git module¶
jammy.utils.gpu module¶
jammy.utils.hash module¶
jammy.utils.hyd module¶
- jammy.utils.hyd.hyd_instantiate(_cfg, *args, **kwargs)[source]¶
A helper func helps initialize from omegaconf(hydra) _cfg
- Args:
- _cfg: omegaconf.DictConfig, must contain _target_ key word
if param or params present in the _cfg, they are high priority to initialize instance otherwise, use _cfg
- Note:
when use the method pay attention to the parameters order
args and kwargs: other parameters needed to initialize network
- jammy.utils.hyd.instantiate(_cfg, *args, **kwargs)[source]¶
A helper func helps instantiate from omegaconf(hydra) _cfg
- Args:
- _cfg: omegaconf.DictConfig, must contain _target_ key word
if param or params present in the _cfg, they are high priority to initialize instance otherwise, use _cfg
- Note:
when use the method pay attention to the parameters order
args and kwargs: other parameters needed to initialize network
jammy.utils.imp module¶
jammy.utils.init module¶
jammy.utils.matching module¶
jammy.utils.meta module¶
- class jammy.utils.meta.Singleton[source]¶
Bases:
type
https://stackoverflow.com/a/55629949/7672954
- property ready¶
jammy.utils.meter module¶
- class jammy.utils.meter.AverageMeter[source]¶
Bases:
object
Computes and stores the average and current value
- avg = 0¶
- count = 0¶
- sum = 0¶
- tot_count = 0¶
- val = 0¶
jammy.utils.mock module¶
jammy.utils.naming module¶
jammy.utils.notifier module¶
jammy.utils.num_check module¶
jammy.utils.printing module¶
- class jammy.utils.printing.PrintToStringContext(target='STDOUT', stream=None, need_lock=True)[source]¶
Bases:
object
- jammy.utils.printing.bubbletext(text, font='cybermedium')[source]¶
Uses pyfiglet to create bubble text. Args:
- font (str): default=cybermedium, other fonts include: cybersmall and
cyberlarge.
- References:
- Example:
>>> bubble_text = bubbletext('TESTING BUBBLE TEXT', font='cybermedium') >>> print(bubble_text)
- jammy.utils.printing.kvprint(data, indent=0, sep=' : ', end='\n', max_key_len=None, file=None, float_format='{:.6f}', need_lock=True)[source]¶
- jammy.utils.printing.stprint(data, key=None, indent=0, file=None, indent_format=' ', end_format='\n', float_format='{:.6f}', need_lock=True, max_depth=100)[source]¶
Structure print.
Example:
>>> data = dict(a=np.zeros(shape=(10, 10)), b=3) >>> stprint(data) dict{ a: ndarray(10, 10), dtype=float64 b: 3 }
- Args:
data: data to be print. Currently support Sequnce, Mappings and primitive types. key: for recursion calls. Do not use it if you don’t know how it works. indent: indent level.
jammy.utils.process module¶
jammy.utils.profiler module¶
- jammy.utils.profiler.profile(func)¶
dummy profiling func. does nothing
- jammy.utils.profiler.profile_now(func)[source]¶
Eagerly report profile information after each call to func.
- Args:
func (Callable): function to profile
- Example:
>>> # xdoctest: +SKIP >>> from xdev.profiler import * # NOQA >>> def func_to_profile(): >>> list(range(10)) >>> tuple(range(100)) >>> set(range(1000)) >>> profile_now(func_to_profile)() # xdoctest: +IGNORE_WANT Total time: 3.8e-05 s Function: func_to_profile at line 1 Line # Hits Time Per Hit % Time Line Contents ============================================================== 1 def func_to_profile(): 2 1 4.0 4.0 10.5 list(range(10)) 3 1 3.0 3.0 7.9 tuple(range(100)) 4 1 31.0 31.0 81.6 set(range(1000))
jammy.utils.registry module¶
- class jammy.utils.registry.CallbackRegistry[source]¶
Bases:
Registry
A callable manager utils.
If there exists a super callback, it will block all callbacks. A super callback will receive the called name as its first argument.
Then the dispatcher will try to call the callback by name. If such name does not exists, a fallback callback will be called.
The fallback callback will also receive the called name as its first argument.
Examples:
>>> registry = CallbackRegistry() >>> callback_func = print >>> registry.register('name', callback_func) # register a callback. >>> registry.dispatch('name', 'arg1', 'arg2', kwarg1='kwarg1') # dispatch.
- property fallback_callback¶
- property super_callback¶
- class jammy.utils.registry.LockRegistry[source]¶
Bases:
DefaultRegistry
jammy.utils.retry module¶
- jammy.utils.retry.retry(exceptions=<class 'Exception'>, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=<loguru.logger handlers=[(id=1, level=20, sink=<stderr>)]>)[source]¶
Returns a retry decorator. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0.
fixed if a number, random if a range tuple (min, max)
- Parameters:
logger – logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled.
- Returns:
a retry decorator.
- jammy.utils.retry.retry_call(f, fargs=None, fkwargs=None, exceptions=<class 'Exception'>, tries=-1, delay=0, max_delay=None, backoff=1, jitter=0, logger=<loguru.logger handlers=[(id=1, level=20, sink=<stderr>)]>)[source]¶
Calls a function and re-executes it if it failed. :param f: the function to execute. :param fargs: the positional arguments of the function to execute. :param fkwargs: the named arguments of the function to execute. :param exceptions: an exception or a tuple of exceptions to catch. default: Exception. :param tries: the maximum number of attempts. default: -1 (infinite). :param delay: initial delay between attempts. default: 0. :param max_delay: the maximum value of delay. default: None (no limit). :param backoff: multiplier applied to delay between attempts. default: 1 (no backoff). :param jitter: extra seconds added to delay between attempts. default: 0.
fixed if a number, random if a range tuple (min, max)
- Parameters:
logger – logger.warning(fmt, error, delay) will be called on failed attempts. default: retry.logging_logger. if None, logging is disabled.
- Returns:
the result of the f function.