siml.utils package

Submodules

siml.utils.errors module

exception siml.utils.errors.SimlMultiprocessError

Bases: ValueError

This error raises when a process is failed under multiprocess condition

exception siml.utils.errors.SimlSkipNotificationError

Bases: ValueError

This error raises when a process is skipped

siml.utils.fem_data_utils module

class siml.utils.fem_data_utils.FemDataWrapper(fem_data: FEMData)

Bases: object

add_abs_difference(dict_data: dict, reference_dict_data: dict, prefix: str = 'difference_abs') None
add_difference(dict_data: dict, reference_dict_data: dict, prefix: str = 'difference') None
extract_variables(mandatory_variables: list[str], *, optional_variables: list[str] | None = None) dict[str, numpy.ndarray]

Extract variables from FEMData object to convert to data dictionary.

Parameters:
  • mandatory_variables (list[str]) – Mandatory variable names.

  • optional_variables (list[str], optional) – Optional variable names.

Returns:

dict_data – Data dictionary.

Return type:

dict

update_fem_data(dict_data: dict, prefix: str = '', *, allow_overwrite=False, answer_keys=None, answer_prefix='')
siml.utils.fem_data_utils.reshape_data_if_needed(value: ndarray)

Reshape numpy.ndarray-like to be writable to visualization files.

Parameters:

value (numpy.ndarray) – Data to be processed.

Returns:

reshaped_data

Return type:

numpy.ndarray

siml.utils.multiprocessor module

class siml.utils.multiprocessor.SimlMultiprocessor(max_process: int)

Bases: object

run(*inputs: list[Any], target_fn: Callable[[Any], T], chunksize: int = 1) list[T]
Wrapper function for concurrent.futures

to run safely with multiple processes.

Parameters:
  • max_process (int) – the number of processes to use

  • target_fn (Callable[[Any], T]) – function to execute

  • chunksize (int, optional) – chunck size, by default 1

Returns:

Iterable of objects returned from target_fn

Return type:

list[T]

Raises:

SimlMultiprocessError: – If some processes are killed by host system such as OOM killer, this error raises.

siml.utils.progress_bar module

class siml.utils.progress_bar.SimlProgressBar(total: int, desc: str | None = None)

Bases: object

destroy() None
update(trick: int, *, desc: str | None = None) None

Update progress bar

If Progress bar is not created, create it automatically. When counter becomes full, progress bar is destroyed.

Parameters:
  • trick (int) – Increment to add to the internal counter of iterations

  • desc (str, optional) – Set/modify description of the progress bar. [Default: None] If None, skip to modify description.

siml.utils.timer module

class siml.utils.timer.SimlStopWatch(offset: float = 0.0)

Bases: object

reset() None
start() None
stop() float
watch() float

Return elapsed time since timer started..

Returns:

Elapsed time from start time

Return type:

float

Raises:

ValueError – If timer has not started, raise this error

Module contents