qstack.tools¶
Utility functions and classes for Q-stack.
Provides decorators, argument parsers, and helper functions for command-line tools.
- class qstack.tools.Cursor(action='slicer', inc=<function Cursor.<lambda>>, i0=0)[source]¶
Bases:
objectCursor class to manage dynamic indexing.
- Parameters:
action (str) – Type of indexing action (‘slicer’ or ‘ranger’).
(callable (inc) – int->int): Function to determine increment size. Defaults to identity function.
i0 (int) – Initial index position. Defaults to 0.
- cur (range or slice
Current range or slice.
- class qstack.tools.FlexParser(prog=None, usage=None, description=None, epilog=None, parents=[], formatter_class=<class 'argparse.HelpFormatter'>, prefix_chars='-', fromfile_prefix_chars=None, argument_default=None, conflict_handler='error', add_help=True, allow_abbrev=True, exit_on_error=True)[source]¶
Bases:
ArgumentParserArgument parser that allows removing arguments.
- Parameters:
**kwargs – Arguments passed to ArgumentParser.
- qstack.tools.correct_num_threads()[source]¶
Set MKL and OpenBLAS thread counts based on SLURM environment.
If running under SLURM, sets MKL_NUM_THREADS and OPENBLAS_NUM_THREADS to match SLURM_CPUS_PER_TASK.
- qstack.tools.slice_generator(iterable, inc=<function <lambda>>, i0=0)[source]¶
Generate slices for elements in an iterable based on increments.
- Parameters:
iterable (iterable) – Iterable of elements to generate slices for.
(callable (inc) – int->int): Function that computes increment size for each element. Defaults to identity function.
i0 (int) – Initial starting index. Defaults to 0.
- Yields:
tuple – (element, slice) pairs for each element in the iterable.
- qstack.tools.unix_time_decorator(func)[source]¶
Measure and print execution time statistics for a function.
Measures real, user, and system time for the decorated function. Thanks to https://gist.github.com/turicas/5278558
- Parameters:
func (callable) – Function to be decorated.
- Returns:
Wrapped function that prints timing information.
- Return type:
callable
- qstack.tools.unix_time_decorator_with_tvalues(func)[source]¶
Measure execution time statistics and return them along with function result.
Measures real, user, and system time for the decorated function and returns timing dict. Thanks to https://gist.github.com/turicas/5278558
- Parameters:
func (callable) – Function to be decorated.
- Returns:
Wrapped function that returns (timing_dict, result).
- Return type:
callable