pathsim.utils.progresstracker module

class pathsim.utils.progresstracker.ProgressTracker(total_duration, description='', logger=None, log=True, log_level=20, min_log_interval=1.0, update_log_every=0.2)[source]

Bases: object

A progress tracker suitable for simulations with variable timesteps, updated by progress fraction and integrated with standard logging.

Logs progress updates periodically based on time and progress intervals. Calculates an estimated step rate based on the interval since the last log. Can be used as both an iterator and a context manager for convenient integration into simulation loops.

Examples

Parameters:
  • total_duration (float) – The total simulation duration (e.g., in seconds) to track against. Must be positive.

  • description (str, optional) – A short description or name for the process being tracked, used in log messages. Defaults to “Progress”.

  • logger (logging.Logger, optional) – The logger instance to use for outputting progress messages. If None, a default logger named ‘ProgressTracker_<description>’ is created and configured to print INFO level messages to stdout.

  • log (bool) – Flag to indicate if logging messages should be printed or not.

  • log_level (int, optional) – The logging level (e.g., logging.INFO, logging.DEBUG) to use for progress messages. Defaults to logging.INFO.

  • min_log_interval (float, optional) – The minimum real time interval in seconds that must pass between consecutive log updates, regardless of progress change. Helps to throttle output. Default from ‘_constants.py’.

  • update_log_every (float, optional) – Log a message every time the progress increases by at least this fraction (e.g., 0.1 for 10%). Must be between 0 (exclusive) and 1 (inclusive). Default from ‘_constants.py’.

property current_progress

The current progress fraction (0.0 to 1.0).

Type:

float

interrupt()[source]

Interrupts the progress tracking and marks for special logging.

start()[source]

Starts the progress timer and logs the initial message.

update(progress, success=True, **kwargs)[source]

Updates the tracker’s progress and optional postfix info, logging if necessary. Should be called within the loop iterating over the tracker.

Parameters:
  • progress (float) – Current progress fraction (0.0 to 1.0).

  • success (bool, optional) – Indicates if the step contributing to this progress was successful. Defaults to True.

  • **kwargs (dict, optional) – Key-value pairs to display as postfix information (e.g., dt=0.01). These overwrite previous postfix values each time update is called.

close()[source]

Modified to distinguish between normal finish and interrupt