From 6633a2d7a13f2fabbe53ff4a59956281cff6fb1c Mon Sep 17 00:00:00 2001 From: TheoQM Date: Tue, 19 Nov 2024 16:47:52 +0100 Subject: [PATCH] fix filtering to remove error message with qm-qua > 1.1.7 --- CHANGELOG.md | 2 ++ qualang_tools/multi_user/multi_user_tools.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e782bc62..4dba72b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Fixed +- multi_user - fix filtering to remove error message with qm-qua > 1.1.7 ## [0.18.1] - 2024-11-05 ### Added diff --git a/qualang_tools/multi_user/multi_user_tools.py b/qualang_tools/multi_user/multi_user_tools.py index 94c3acb0..b17e843f 100644 --- a/qualang_tools/multi_user/multi_user_tools.py +++ b/qualang_tools/multi_user/multi_user_tools.py @@ -1,6 +1,6 @@ import logging from contextlib import contextmanager -from time import sleep +from time import sleep, time from qm import QuantumMachine from qm import QuantumMachinesManager @@ -14,6 +14,7 @@ class BusyFilter(logging.Filter): def filter(self, record): return not ("already uses" in record.getMessage() or msg in record.getMessage()) + # return False @contextmanager @@ -34,12 +35,14 @@ def qm_session(qmm: QuantumMachinesManager, config: dict, timeout: int = 100) -> """ if not timeout > 0: raise ValueError(f"timeout={timeout} but must be positive") - qm_log = logging.getLogger("qm") + qm_log = logging.getLogger("qm.api.frontend_api") + # qm_log = logging.getLogger("qm") filt = BusyFilter() is_busy = True printed = False - time = 0 - while is_busy and time < timeout: + t0 = time() + elapsed_time = 0 + while is_busy and elapsed_time < timeout: try: qm_log.addFilter(filt) qm = qmm.open_qm(config, close_other_machines=False) @@ -57,7 +60,7 @@ def qm_session(qmm: QuantumMachinesManager, config: dict, timeout: int = 100) -> qm_log.warning(f"QOP is busy. Waiting for it to free up for {timeout}s...") printed = True sleep(0.2) - time += 0.2 + elapsed_time = time() - t0 else: raise Exception from e else: @@ -65,7 +68,7 @@ def qm_session(qmm: QuantumMachinesManager, config: dict, timeout: int = 100) -> qm_log.info("Opening QM") finally: qm_log.removeFilter(filt) - if is_busy and time >= timeout: + if is_busy and elapsed_time >= timeout: qm_log.warning(f"While waiting for QOP to free, reached timeout: {timeout}s") raise TimeoutError(f"While waiting for QOP to free, reached timeout: {timeout}s") try: