NekUpload.utils.parsing module

NekUpload.utils.parsing.evaluate_parameters(params: dict[str, str]) dict[str, float][source]

Evaluates all parameters in a dictionary. For example, the following: data = {“PARAM1”: “10”,”PARAM2” : “PARAM1”} will be resolved into the following form due to the references: expected = {“PARAM1”: 10,”PARAM2” : 10}

Mathematical operators can also be evaluated, the following also works: data = {“PARAM1”: “10”,”PARAM2” : “PARAM1 + 5”} -> expected = {“PARAM1”: 10,”PARAM2” : 15}

Parameters:

params (dict[str, str]) – Dictionary mapping parameter names to expressions.

Returns:

Evaluated parameters with numerical values.

Return type:

dict[str, float]

NekUpload.utils.parsing.get_all_files_with_extension(files: list[str], extension: str) list[str][source]

Return all files in a list with the specified file extension

Parameters:
  • files (list[str]) – list containing the files

  • extension (str) – File extension to be found

Returns:

list of files containing the extension

Return type:

list[str]

NekUpload.utils.parsing.get_both_sides_of_equals(text_with_equals: str) tuple[str, str][source]

Given a string “LHS = RHS”, acquire LHS and RHS

Parameters:

text_with_equals (str) – String containing an equality “LHS = RHS”

Returns:

Returns a tuple containing LHS string and RHS string, trimmed of leading and trailing whitespace

Return type:

tuple[str, str]

NekUpload.utils.parsing.get_hdf5_datasets_with_depth_limit(hdf5_file: File, max_depth: int, start_path: str = '', max_datasets: int = 100) list[str][source]

Traverses the HDF5 hierarchy and returns dataset paths up to a specified depth.

Parameters:
  • hdf5_file (h5py.File) – An open h5py.File object.

  • max_depth (int) – The maximum depth to traverse.

  • start_path (str) – the path to start the search from.

  • max_groups (int) – If defined, specifies maximum number of groups to be found. Once exceeded, function will return.

Returns:

A list of group paths.

Return type:

list[str]

NekUpload.utils.parsing.get_hdf5_groups_with_depth_limit(hdf5_file: File, max_depth: int, start_path: str = '', max_groups: int = 100) list[str][source]

Traverses the HDF5 hierarchy and returns group paths up to a specified depth. Will find “” as first group.

Parameters:
  • hdf5_file (h5py.File) – An open h5py.File object.

  • max_depth (int) – The maximum depth to traverse.

  • start_path (str) – the path to start the search from.

  • max_groups (int) – If defined, specifies maximum number of groups to be found. Once exceeded, function will return.

Returns:

A list of group paths.

Return type:

list[str]

NekUpload.utils.parsing.safe_resolve(param_name: str, params: dict[str, str], seen: set) float | str[source]

Recursively resolves and evaluates expressions in params. For example, the following: data = {“PARAM1”: “10”,”PARAM2” : “PARAM1”} will be resolved into the following form due to the references: expected = {“PARAM1”: 10,”PARAM2” : 10}

Mathematical operators can also be evaluated, the following also works: data = {“PARAM1”: “10”,”PARAM2” : “PARAM1 + 5”} -> expected = {“PARAM1”: 10,”PARAM2” : 15}

Parameters:
  • param_name (str) – The name of the parameter to resolve.

  • params (dict[str, str]) – Dictionary of parameters mapping names to expressions.

  • seen (set) – Set of already visited parameters (to prevent cycles).

Returns:

Evaluated numerical result or original string if resolution fails.

Return type:

Union[float, str]