From 268914def2540d8799e767e4b95d55c0f4c8009c Mon Sep 17 00:00:00 2001 From: ale Date: Wed, 8 Oct 2025 05:24:12 +0200 Subject: [PATCH] more logging Signed-off-by: ale --- python/cudaq_bridge.py | 12 +++++++++++- src/bridge/python-bridge.ts | 12 ++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/python/cudaq_bridge.py b/python/cudaq_bridge.py index 06af822..3f5570c 100644 --- a/python/cudaq_bridge.py +++ b/python/cudaq_bridge.py @@ -509,11 +509,18 @@ def main(): for line in sys.stdin: try: - request = json.loads(line.strip()) + line = line.strip() + if not line: + continue + + request = json.loads(line) command = request.get("command") data = request.get("data", {}) request_id = request.get("requestId", "") + # Debug logging + print(f"DEBUG - Processing command: {command} with ID: {request_id}", file=sys.stderr, flush=True) + if command: result = dispatch_command(command, **data) response = { @@ -521,6 +528,7 @@ def main(): "data": result, "requestId": request_id } + print(f"DEBUG - Command {command} completed successfully", file=sys.stderr, flush=True) else: response = { "success": False, @@ -531,6 +539,8 @@ def main(): print(json.dumps(response), flush=True) except Exception as e: + print(f"ERROR - Exception in main loop: {str(e)}", file=sys.stderr, flush=True) + print(f"ERROR - Traceback: {traceback.format_exc()}", file=sys.stderr, flush=True) error_response = { "success": False, "error": str(e), diff --git a/src/bridge/python-bridge.ts b/src/bridge/python-bridge.ts index 2bfe540..f48d17f 100644 --- a/src/bridge/python-bridge.ts +++ b/src/bridge/python-bridge.ts @@ -172,8 +172,16 @@ export class PythonBridge extends EventEmitter { const requestId = Math.random().toString(36).substring(2, 15); const request = { command, data, requestId }; - // Set timeout - longer for target operations - const timeoutDuration = command === 'set_target' ? 10000 : 30000; // 10s for set_target, 30s for others + // Set timeout based on command complexity + let timeoutDuration = 5000; // Default 5s + + if (command === 'set_target') { + timeoutDuration = 10000; // 10s for target operations + } else if (['sample', 'observe', 'get_state'].includes(command)) { + timeoutDuration = 15000; // 15s for quantum operations + } else if (['get_platform_info', 'get_available_targets', 'list_kernels'].includes(command)) { + timeoutDuration = 3000; // 3s for simple info operations + } const timeout = setTimeout(() => { this.requestQueue.delete(requestId); reject(new Error(`Python command timeout: ${command}`));