asparagus.utils package

Submodules

asparagus.utils.check_config module

asparagus.utils.check_config.check_device_option(device: str, config: object)[source]

Check and select device input.

Parameters:
  • device (str) – Device label

  • config (settings.Configuration) – Asparagus configuration object for default options and conversion

asparagus.utils.check_config.check_dtype_option(dtype: Any, config: object) Callable[source]

Check and select dtype input and convert eventually to correct dtype class.

Parameters:
  • dtype (any) – Data type label or class to check

  • config (settings.Configuration) – Asparagus configuration object for default options and conversion

asparagus.utils.check_config.check_input_args(instance: object | None = None, argitems: Iterator | None = None, argsskip: List[str] | None = None, check_default: Dict | None = None, check_dtype: Dict | None = None) Dict[str, Any][source]

Iterate over arg, item pair, eventually check for default and dtype, and set as class variable of instance

Parameters:

instance: object, optional, default None

Class instance to set arg, item pair as class variable. If None, skip.

argitems: iterator, optional, default None

Iterator for arg, item pairs. If None, skip.

argskipt: list(str), optional, default None

List of arguments to skip.

check_default: dict, optional, default None

Default argument parameter dictionary.

check_dtype: dict, optional, default None

Default argument data type dictionary.

Return:

dict[str, any]

Updated input arguments

asparagus.utils.check_config.check_input_dtype(arg: str, item: Any, dtypes_args: Dict[str, List[Callable]], raise_error: bool | None = True, return_info: bool | None = False) bool[source]

Check it the item (not None) of arg(ument) matchs the expectation in dtypes_args.

asparagus.utils.check_config.check_property_label(property_label, valid_property_labels: List[str] | None = None, alt_property_labels: Dict[str, List[str]] | None = None, return_modified: bool | None = True) bool[source]

Validate the property label by comparing with valid property labels in ‘valid_property_label’ or compare with alternative labels in ‘alt_property_labels’. If valid or found in ‘alt_properties’, the valid lower case form is returned with bool for match and if modified.

Parameters:
  • property_label (str) – Property labels to be checked.

  • valid_property_labels (list(str), optional, default None) – List of valid property labels. If not defined, valid property labels are taken from settings._valid_properties.

  • alt_property_labels (dict, optional, default None) – Dictionary with alternative property labels as keys and valid property labels as values. If not defined, no check for alternatively spelled properties is done.

  • return_modified (bool, optional, default True) – Return if property label was modified.

asparagus.utils.check_config.get_default_args(self_class: Callable, self_module: Callable) Dict[str, Any][source]

Combine available default argument dictionaries. In case of conflicts, the priority is from top to bottom: self_class, self_module, settings.

asparagus.utils.check_config.get_dtype_args(self_class: Callable, self_module: Callable) Dict[str, Callable][source]

Combine available argument data type dictionaries. In case of conflicts, the priority is from top to bottom: self_class, self_module, settings.

asparagus.utils.check_config.get_function_location(module_name: str | None = 'asparagus')[source]

Get function location from inspect.stack.

Returns:

Function location

Return type:

str

asparagus.utils.check_config.get_input_args()[source]
Get input arguments of the function from where this function is called:

inspect.stack()[0] <- this function inspect.stack()[1] <- the function this one is called from inspect.stack()[>1] <- previous functions (see http://kbyanc.blogspot.com/2007/07/python-aggregating-function -arguments.html)

Returns:

Input argument and item dictionary of the function this function is called from.

Return type:

dict

asparagus.utils.check_config.merge_dictionaries(dict_old: Dict[str, Any], dict_new: Dict[str, Any], keep: bool | None = False) Dict[str, Any][source]

Merge keys and items of both dictionaries. If ‘keep’ is False, update key in dict_old with item of dict_new.

asparagus.utils.check_config.merge_dictionary_lists(dictA: Dict[str, List[str]], dictB: Dict[str, List[str]]) Dict[str, List[str]][source]

Combine two dictionaries lists and check for conflicts in item lists. If an item in the lists reüeats in dictA, the assignment of ‘dictA’ is kept.

asparagus.utils.check_dtype module

asparagus.utils.check_dtype.in_cuda(x: Any, verbose: bool | None = False) bool[source]

Check if the input is a torch tensor in CUDA.

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if option of torch input matches, else False.

Return type:

bool

asparagus.utils.check_dtype.is_None(x: Any, verbose: bool | None = False) bool[source]

Check if the input is None

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_None_array(x: Any, empty: bool | None = True, inhomogeneity: bool | None = False, verbose: bool | None = False) bool[source]

Check if the input is a None array-like object.

Parameters:
  • x (Any) – Input variable of which to check dtype

  • empty (bool, optional, default True) – If True, return positive match for empty array like variables

  • inhomogeneity (bool, optional, default False) – If True, return positive match for inhomogeneous array like variables

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_array_like(x: Any, empty: bool | None = True, verbose: bool | None = False) bool[source]

Check if the input is an array-like object.

Parameters:
  • x (Any) – Input variable of which to check dtype

  • empty (bool, optional, default True) – If True, return positive match for empty array like variables

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_ase_atoms(x: Any, verbose: bool | None = False) bool[source]

Check if the input is an ASE atoms object.

Parameters:
  • x (Any) – Input variable of which to check object type

  • verbose (bool, optional, default False) – If True, return the object type of the input and the expected type

Returns:

True, if input variable match object type, else False.

Return type:

bool

asparagus.utils.check_dtype.is_ase_atoms_array(x: Any, empty: bool | None = True, inhomogeneity: bool | None = False, verbose: bool | None = False) bool[source]

Check if the input is an ASE atoms object.

Parameters:
  • x (Any) – Input variable of which to check object type

  • empty (bool, optional, default True) – If True, return positive match for empty array like variables

  • inhomogeneity (bool, optional, default False) – If True, return positive match for inhomogeneous array like variables

  • verbose (bool, optional, default False) – If True, return the object type of the input and the expected type

Returns:

True, if input variable match object type, else False.

Return type:

bool

asparagus.utils.check_dtype.is_attached(x: Any, verbose: bool | None = False) bool[source]

Check if the input is a torch tensor attached to the computational graph

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if option of torch input matches, else False.

Return type:

bool

asparagus.utils.check_dtype.is_bool(x: Any, verbose: bool | None = False) bool[source]

Check if the input is a bool

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_bool_array(x: Any, empty: bool | None = True, inhomogeneity: bool | None = False, verbose: bool | None = False) bool[source]

Check if the input is a boolean array-like object

Parameters:
  • x (Any) – Input variable of which to check dtype

  • empty (bool, optional, default True) – If True, return positive match for empty array like variables

  • inhomogeneity (bool, optional, default False) – If True, return positive match for inhomogeneous array like variables

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_boolean(x: Any, verbose: bool | None = False) bool[source]
asparagus.utils.check_dtype.is_boolean_array(x: Any, empty: bool | None = True, inhomogeneity: bool | None = False, verbose: bool | None = False) bool[source]
asparagus.utils.check_dtype.is_callable(x: Any, verbose: bool | None = False) bool[source]

Check if the input is a callable object

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_dictionary(x: Any, verbose=False)[source]

Check if the input is a dictionary

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_grad_enabled(x: Any, verbose: bool | None = False) bool[source]

Check if the input is a torch tensor with gradient enabled

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if option of torch input matches, else False.

Return type:

bool

asparagus.utils.check_dtype.is_integer(x: Any, verbose: bool | None = False) bool[source]

Check if the input is an integer type

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_integer_array(x: Any, empty: bool | None = True, inhomogeneity: bool | None = False, verbose: bool | None = False) bool[source]

Check if the input is an integer array-like object

Parameters:
  • x (Any) – Input variable of which to check dtype

  • empty (bool, optional, default True) – If True, return positive match for empty array like variables

  • inhomogeneity (bool, optional, default False) – If True, return positive match for inhomogeneous array like variables

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_none(x: Any, verbose: bool | None = False) bool[source]
asparagus.utils.check_dtype.is_numeric(x: Any, verbose: bool | None = False) bool[source]

Check if the input is a numeric type (int or float)

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_numeric_array(x: Any, empty: bool | None = True, inhomogeneity: bool | None = False, verbose: bool | None = False) bool[source]

Check if the input is a numeric array-like object

Parameters:
  • x (Any) – Input variable of which to check dtype

  • empty (bool, optional, default True) – If True, return positive match for empty array like variables

  • inhomogeneity (bool, optional, default False) – If True, return positive match for inhomogeneous array like variables

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_object(x: Any, verbose: bool | None = False) bool[source]

Check if the input is an object (everything in Python is an object …)

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_string(x: Any, verbose: bool | None = False) bool[source]

Check if the input is a string

Parameters:
  • x (Any) – Input variable of which to check dtype

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_string_array(x: Any, empty: bool | None = True, inhomogeneity: bool | None = False, verbose: bool | None = False) bool[source]

Check if the input can be a string array-like object

Parameters:
  • x (Any) – Input variable of which to check dtype

  • empty (bool, optional, default True) – If True, return positive match for empty array like variables

  • inhomogeneity (bool, optional, default False) – If True, return positive match for inhomogeneous array like variables

  • verbose (bool, optional, default False) – If True, return the type of the input and the expected type

Returns:

True, if input variable match dtype, else False.

Return type:

bool

asparagus.utils.check_dtype.is_string_array_inhomogeneous(x: Any, verbose: bool | None = False) bool[source]
asparagus.utils.check_dtype.is_torch_tensor(x: Any, verbose: bool | None = False) bool[source]

Check if the input is an torch Tensor object.

Parameters:
  • x (Any) – Input variable of which to check object type

  • verbose (bool, optional, default False) – If True, return the object type of the input and the expected type

Returns:

True, if input variable match object type, else False.

Return type:

bool

asparagus.utils.check_units module

asparagus.utils.data_ase module

asparagus.utils.functions module

asparagus.utils.legacy module

asparagus.utils.output module

asparagus.utils.output.get_header(config_file: str) str[source]

Provide the Asparagus header.

Parameters:

config_file (str) – Current configuration file path

Returns:

Asparagus header

Return type:

str

asparagus.utils.output.print_Progress(status: str | None = '')[source]

Just print progress status

Parameters:

status (str, optional, default '') – Status string

asparagus.utils.output.print_ProgressBar(iteration: int, total: int, prefix: str | None = '', suffix: str | None = '', decimals: int | None = 1, length: int | None = 100, fill: str | None = '#', printEnd: str | None = '\r')[source]

Call in a loop to create terminal progress bar

iteration: int

current iteration (Int)

total: int

total iterations

prefix: str, optional, default ‘’

prefix string

suffix: str, optional, default ‘’

suffix string

decimals: int, optional, default 1

positive number of decimals in percent complete

length: int, optional, default 100

Character length of bar (Int)

fill: str, optional, default ‘#’

bar fill character

printEnd: str, optional, default ‘

end character (e.g. “/r”, “/r/n”) (Str)

asparagus.utils.output.set_logger(logger: ~logging.Logger, level: ~typing.Callable | None = None, stream: ~typing.Callable | str | None = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, verbose: bool | None = True, **kwargs) Logger[source]

Set logging parameters,

Parameters:
  • logger (logging.Logger) – Logger object to set parameters

  • level (callable, optional, default 'logging.INFO') – Print level for output (e.g. logging.DEBUG, logging.INFO, …)

  • stream ((callable, str), optional, default 'sys.stdout') – Output channel to print or file path to write

  • verbose (bool, optional, default True) – Start logger output with header for information

Returns:

Loger object with set paramerts

Return type:

logging.Logger

Module contents