Utilities

Progress Bar

class lambdapic.core.utils.progress_bar.ProgressBar(total: int, initial: int = 0, desc: str = 'Progress', disable: bool | None = None, progress_interval: int | None = None, position: int | None = None)[source]

A progress bar that logs timing info when not in a terminal.

This class wraps tqdm to provide progress display in terminals and structured logging when running in non-terminal environments (e.g., batch jobs, logs, pipes).

Parameters:
  • total (int) – Total number of iterations.

  • initial (int, optional) – Initial counter value. Default: 0.

  • desc (str, optional) – Description prefix. Default: “Progress”.

  • disable (bool, optional) – Force disable progress bar and logging. Default: None (auto-detect).

  • progress_interval (int, optional) – Log progress every N iterations when not in terminal. Default: min(100, total//10).

  • position (int, optional) – Line offset for tqdm display. Default: None.

Example

>>> with ProgressBar(total=100, desc="Simulation") as pbar:
...     for i in range(100):
...         pbar.update(1)
close()[source]

Close the progress bar and log final status.

property n: int

Current iteration count.

update(n: int = 1)[source]

Update progress by n steps.

Terminal Detection

lambdapic.core.utils.terminal.is_terminal() bool[source]

Check if the current process is running in a terminal.

Returns True if stdout is attached to a terminal (TTY), False otherwise. This is useful for disabling progress bars and spinners in non-terminal environments like logs, pipes, or batch job systems.

Returns:

True if running in a terminal, False otherwise.

Return type:

bool