Source code for bragi_quantum.datalayer.utils.logging.visuals

# ══════════════════════════════════════════════════════════════════════════
#     ___   ___ ___   _      _   ___
#    / _ \ / __|_  ) | |    /_\ | _ )
#   | (_) | (__ / /  | |__ / _ \| _ \
#    \__\_\\___/___| |____/_/ \_\___/
#
#   QC2 @ CHALMERS CALIBRATION TOOLKIT
#   (c) 2026 Chalmers University of Technology and Project Contributors
# ──────────────────────────────────────────────────────────────────────────
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       https://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
# ──────────────────────────────────────────────────────────────────────────
#   CONTRIBUTORS list:
#
#   Matteo Robbiati, robbiati@chalmers.se
#   Axel Andersson, axean@chalmers.se
# ══════════════════════════════════════════════════════════════════════════


# This code is part of Tergite
#
# (C) Copyright Eleftherios Moschandreou 2023, 2024
# (C) Copyright Stefan Hill 2024
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
#
# Modified from tergite-autocalibration
# (https://github.com/tergite/tergite-autocalibration), file:
#   tergite_autocalibration/utils/logging/visuals.py


from colorama import Fore, Style

from bragi_quantum.datalayer.utils.logging import logger


[docs] def log_timing(label: str, duration: float, suffix: str = "") -> None: """Log a timing status message with the duration highlighted in cyan.""" logger.status( f"{label}{Fore.CYAN}{Style.BRIGHT}{duration:.5g} sec{suffix}{Style.RESET_ALL}" )
[docs] def log_snapshot_size(file_path) -> None: """Log the on-disk size of a cluster snapshot/diff file in MB, highlighted in red.""" log_size_on_disk("Snapshot written:", file_path)
[docs] def log_size_on_disk(label: str, paths) -> None: """Log on-disk file size(s) in MB, highlighted in red. Pass a single :class:`~pathlib.Path` (or str) for a single-file report:: log_size_on_disk("Dataset saved:", data_path / "dataset.hdf5") Pass an iterable of paths for an aggregated count + total-size report:: log_size_on_disk("Plots saved:", list(data_path.glob("*.png"))) """ from pathlib import Path if isinstance(paths, (str, Path)): paths = [Path(paths)] else: paths = [Path(p) for p in paths] total_bytes = sum(p.stat().st_size for p in paths) size_mb = total_bytes / (1024 * 1024) detail = paths[0].name if len(paths) == 1 else f"{len(paths)} files" logger.status( f"{label} {detail} {Fore.RED}{Style.BRIGHT}{size_mb:.3f} MB{Style.RESET_ALL}" )