simdesign.utils.misc

This module provides miscellaneous utility methods.

simdesign.utils.misc.PRECISION = 8

Precision used in rounding of floating numbers.

simdesign.utils.misc.update_nested_dict(d, u)[source]

Recursively updates a nested dictionary with another dictionary.

Parameters:
  • d (Dict[str, Any]) – The original nested dictionary to be updated.

  • u (Dict[str, Any]) – The dictionary containing updates.

Returns:

The updated nested dictionary.

Return type:

Dict[str, Any]

simdesign.utils.misc.run_time(start_time)[source]

Print elapsed time between start_time and now in hours, minutes, and seconds.

Parameters:

start_time (int) – The initial time obtained via time().

Returns:

total run time (hr, min, sec).

Return type:

str

simdesign.utils.misc.handle_remove_read_only(func, path, exc)[source]

Grant write permission to a file and remove it using the provided function.

Parameters:
  • func (Callable) – remove function.

  • path (str) – file path.

  • exc (tuple) – Exception tuple.

Raises:

Warning – Path is in use.

Return type:

None

simdesign.utils.misc.remove_dir(dir_path)[source]

Remove a directory if it exists.

Parameters:

dir_path (Union[str, Path]) – Name of directory to remove.

Return type:

None

simdesign.utils.misc.make_dir(dir_path)[source]

Make a clean directory, deleting any existing one first.

Parameters:

dir_path (Union[str, Path]) – Name of directory to make.

Return type:

None

simdesign.utils.misc.signif(x, p)[source]

Round an array to the specified number of significant figures.

Parameters:
  • x (np.ndarray) – array to be rounded.

  • p (int) – significant digits.

Returns:

Rounded array.

Return type:

np.ndarray

simdesign.utils.misc.check_parameters(parameters, required_parameters)[source]

Check that all required parameters are present in the parameters dictionary.

Parameters:
  • parameters (dict) – user defined parameters.

  • required_parameters (tuple) – parameters required by the application.

Raises:

KeyError – A parameter is missing.

Return type:

None

simdesign.utils.misc.dot(a, b)[source]

Compute the dot product of two lists of floats.

Parameters:
  • a (List[float]) – The first list of floats.

  • b (List[float]) – The second list of floats.

Returns:

Dot product

Return type:

float

simdesign.utils.misc.get_time_based_seed()[source]

Return a random seed derived from the current date and time.

Returns:

Sum of time components from the current UTC time.

Return type:

int

simdesign.utils.misc.convert_numpy_types(input_list)[source]

Convert NumPy integer and float types in a list to native Python int and float.

Parameters:

input_list (List[Any]) – A list containing elements that may include NumPy-specific types or standard Python types.

Returns:

A new list with NumPy types converted to their corresponding Python types (int or float). Non-NumPy types are returned unchanged.

Return type:

List[Any]

Example

>>> example_list = [np.float64(3.14), np.int32(10), 5, 7.2]
>>> convert_numpy_types(example_list)
[3.14, 10, 5, 7.2]
simdesign.utils.misc.round_list(input_list, precision=8)[source]

Round each value in a list to the specified precision.

Parameters:
  • input_list (List[Any]) – A list of floating-point numbers to be rounded.

  • precision (int) – Number of decimal places, by default equal to the constant PRECISION.

Returns:

A new list with each value rounded to the specified precision.

Return type:

List[Any]

Examples

>>> round_list([3.14159, 2.71828, 1.61803], 2)
[3.14, 2.72, 1.62]
simdesign.utils.misc.filter_args(method, data)[source]

Filter and convert input values so they match the signature of a method.

Parameters:
  • method (callable) – The method whose signature is used for filtering and conversion.

  • data (Mapping[str, Any]) – A dictionary-like object containing raw input values (e.g., JSON body, query parameters, or user-provided input). Keys are expected to match parameter names of the method.

Returns:

A dictionary containing only the parameters expected by method, with types converted based on annotations when possible. If method defines **kwargs, extra keys in data are also included so they can be passed through via **filtered_data.

Return type:

dict[str, Any]