levisim.core.wrappers

Decorators for timing, profiling and showing a progress bar

levisim.core.wrappers.timer(enabled, debug=False)[source]

A perf_counter timer decorator, which logs the run time of each call at DEBUG

With debug it also logs the call’s arguments at DEBUG. Both messages are formatted lazily, so they cost nothing when no sink takes DEBUG.

levisim.core.wrappers.profiler(enabled)[source]

A cProfile profiling decorator

levisim.core.wrappers.resolve_variable_path(bound_arguments, path)[source]

Resolves a dotted path against a function call’s bound arguments

The first part names any argument of the call (self in a method, or e.g. labels in a plain function); each later part is an attribute lookup, or a key lookup if the object is a dict. So ‘self.ω_range’, ‘labels’ and ‘mtrap.cavity.κ’ all work.

levisim.core.wrappers.progress_bar_wanted_levels()[source]

The console levels at which progress bars are drawn: INFO and anything more verbose

SUCCESS (severity 25) is less verbose than INFO (20), so, like WARNING, it draws no bars; this matches the numeric rule in progress_bars_wanted() (severity <= 20).

levisim.core.wrappers.progress_bars_wanted()[source]

Whether progress bars should be drawn now, decided at call time

True only if the console log level (see levisim.core.logger.set_console_level) is INFO or more verbose, so that the default WARNING console keeps notebooks and scripts free of bars. tqdm’s own TQDM_DISABLE environment variable still switches them off regardless.

levisim.core.wrappers.progress_bar(loop_variable_path, enabled)[source]

A decorator that shows a tqdm progress bar sized by an iterable the function loops over

The iterable is found from loop_variable_path, a dotted path whose first part is the name of any argument of the decorated function (see resolve_variable_path): ‘self.ω_range’ for the MultiTrap spectrum methods, ‘labels’ for generate_determinant_and_adjugate_by_order. Defaults of unpassed arguments are applied before resolving.

NOTE: a decorator cannot see inside the function’s loop, so the bar is not updated per iteration: it opens with the total length, the function runs, and the bar is filled when it returns (it then reports the elapsed time and the mean time per item).

Parameters:
  • loop_variable_path – the dotted path to the iterable (e.g. ‘self.ω_range’)

  • enabled – Boolean to toggle the progress bar on or off