simopt.utils

Utility functions for simopt.

Module Contents

simopt.utils.T
simopt.utils.R
class simopt.utils.ClassPropertyDescriptor(fget: collections.abc.Callable[[type[T]], R])

Bases: Generic[T, R]

Descriptor for class properties.

Initialize the descriptor.

Parameters:

fget (Callable[[type[T]], R]) – The function to get the class property.

fget
simopt.utils.classproperty(func: collections.abc.Callable[[type[T]], R]) ClassPropertyDescriptor[T, R]

Decorator to define a class property.

Parameters:

func (Callable[[type[T]], R]) – The function to be decorated.

Returns:

The class property descriptor.

Return type:

ClassPropertyDescriptor[T, R]

simopt.utils.override(obj: T) T

Decorator to mark a method as overridden.

simopt.utils.make_nonzero(value: float, name: str, epsilon: float = 1e-15) float

Return a non-zero value to avoid division by zero.

Parameters:
  • value (float) – The value to check.

  • name (str) – The name of the variable.

  • epsilon (float, optional) – The value to use if the original value is zero. Default is 1e-15.

Returns:

The original value if it’s not close to zero, otherwise a non-zero value.

Return type:

float

simopt.utils.resolve_file_path(target: str | pathlib.Path, directory: str | pathlib.Path) pathlib.Path

Resolve a file path against a base directory.

Parameters:
  • target (str | Path) – The target file path to resolve.

  • directory (str | Path) – The base directory to resolve against.

Returns:

The resolved file path.

Return type:

Path

Raises:

ValueError – If the target is a directory.

simopt.utils.print_table(name: str, headers: list[str], data: list[tuple] | dict) None

Print a table with headers and data.

Parameters:
  • name (str) – Name of the table.

  • headers (list[str]) – List of column headers.

  • data (list[tuple]) – List of rows, each row is a tuple of values.

simopt.utils.get_specifications(config_class: type[pydantic.BaseModel]) dict[str, dict]

Get the specifications for a configuration class.