odatse.algorithm._algorithm module

class odatse.algorithm._algorithm.AlgorithmBase(info: Info, runner: Runner | None = None, run_mode: str = 'initial')[source]

Bases: object

Base class for algorithms, providing common functionality and structure.

Initialize the algorithm with the given information and runner.

Parameters:
  • info (Info) – Information object containing algorithm and base parameters.

  • runner (Runner (optional)) – Optional runner object to execute the algorithm.

  • run_mode (str) – Mode in which the algorithm should run.

abstract __init__(info: Info, runner: Runner | None = None, run_mode: str = 'initial') None[source]

Initialize the algorithm with the given information and runner.

Parameters:
  • info (Info) – Information object containing algorithm and base parameters.

  • runner (Runner (optional)) – Optional runner object to execute the algorithm.

  • run_mode (str) – Mode in which the algorithm should run.

__init_rng(info: Info) None

Initialize the random number generator.

Parameters:

info (Info) – Information object containing algorithm parameters.

_check_parameters(param=None)[source]

Check the parameters of the algorithm against previous parameters.

Parameters:

(optional) (param) – Previous parameters to check against.

_load_data(filename='state.pickle') Dict[source]

Load data from a file.

Parameters:

filename – Name of the file to load the data from.

Returns:

Dictionary containing the loaded data.

Return type:

Dict

abstract _post() Dict[source]

Abstract method to be implemented by subclasses for post-processing steps.

abstract _prepare() None[source]

Abstract method to be implemented by subclasses for preparation steps.

abstract _run() None[source]

Abstract method to be implemented by subclasses for running steps.

_save_data(data, filename='state.pickle', ngen=3) None[source]

Save data to a file with versioning.

Parameters:
  • data – Data to be saved.

  • filename – Name of the file to save the data.

  • ngen (int, default: 3) – Number of generations for versioning.

_show_parameters()[source]

Show the parameters of the algorithm.

main()[source]

Main method to execute the algorithm.

post() Dict[source]

Perform post-processing after the algorithm has run.

Returns:

Dictionary containing post-processing results.

Return type:

Dict

prepare() None[source]

Prepare the algorithm for execution.

run() None[source]

Run the algorithm.

set_runner(runner: Runner) None[source]

Set the runner for the algorithm.

Parameters:

runner (Runner) – Runner object to execute the algorithm.

write_timer(filename: Path)[source]

Write the timing information to a file.

Parameters:

filename (Path) – Path to the file where timing information will be written.

class odatse.algorithm._algorithm.AlgorithmStatus(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Enumeration for the status of the algorithm.

odatse.algorithm._algorithm.flatten_dict(d, parent_key='', separator='.')[source]

Flatten a nested dictionary.

Parameters:
  • d – Dictionary to flatten.

  • parent_key (str, default : "") – Key for the parent dictionary.

  • separator (str, default : ".") – Separator to use between keys.

Returns:

Flattened dictionary.

Return type:

dict