Skip to content

Commit

Permalink
fix filtering to remove error message with qm-qua > 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLaudatQM committed Nov 19, 2024
1 parent ab96682 commit 6633a2d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions qualang_tools/multi_user/multi_user_tools.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -57,15 +60,15 @@ 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:
is_busy = False
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:
Expand Down

0 comments on commit 6633a2d

Please sign in to comment.