academia.utils module
Submodules
Module contents
Miscellaneous classes and functions that don’t belong anywhere else or are used by multiple modules.
The idea behind academia.utils is that other modules depend on it, but it itself does not depend on
any other module. That is different to academia.tools which works the other way around.
Exported classes:
- class academia.utils.SavableLoadable
Bases:
ABCAn interface for classes which instances can be saved or loaded.
- static get_type(type_name_full: str) Type
- Parameters:
type_name_full – type’s import name (e.g. “academia.agents.SarsaAgent”)
- Returns:
A type based on its full name (e.g.
academia.agents.SarsaAgent).
- static get_type_name_full(type_: Type) str
- Returns:
A full type name (e.g. “academia.agents.SarsaAgent”).
- abstract classmethod load(path: str)
Loads an object.
- Returns:
A loaded object.
- static prep_save_file(specified_path: str, interrupted: bool) str
Creates parent directories if they’re missing and, if
interrupted=True, prepends ‘backup_’ to the file name in the specified path.- Returns:
Final path.
- abstract save(path: str) str
Saves an object.
- Returns:
An absolute path where the object was saved.
- class academia.utils.Stopwatch(start=True)
Bases:
objectA utility class for measuring and storing consecutive CPU/wall times. All times are stored in seconds.
- Parameters:
start – whether or not to start a stopwatch immidiately after initializing it.
- property cpu_lap_times: list[float]
A list of all stored CPU lap times (excluding the current lap)
- property is_running: bool
Whether or not the stopwatch is currently running
- lap() tuple[float, float]
Ends the current lap and starts a new one.
- Returns:
Wall and CPU times of the lap that was ended.
- Raises:
RuntimeError – if stopwatch is not running
- peek_lap_time() tuple[float, float]
Checks the current lap time without ending the lap.
- Returns:
Current wall and CPU lap times.
- Raises:
RuntimeError – if stopwatch is not running
- peek_time() tuple[float, float]
Check the current total time without stopping the stopwatch.
- Returns:
Current wall and CPU times since the start.
- Raises:
RuntimeError – if stopwatch is not running
- start() None
Starts or restarts the stopwatch
- stop(lap=False) tuple[float, float]
Stops the stopwatch.
- Parameters:
lap – whether or not end and save the final lap.
- Returns:
Wall and CPU total times since the stopwatch was started.
- Raises:
RuntimeError – if stopwatch is not running
- property wall_lap_times: list[float]
A list of all stored wall lap times (excluding the current lap)