From e28ffbee7785f329de4755edfde8ecbef1ca1fb5 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 2 May 2025 15:38:51 -0400 Subject: [PATCH 01/20] Initial support for active debugger session for compiler attachment --- frontend/catalyst/compiler.py | 17 ++++++++++++++++- frontend/catalyst/pipelines.py | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/frontend/catalyst/compiler.py b/frontend/catalyst/compiler.py index c38c968e5f..de54902f3e 100644 --- a/frontend/catalyst/compiler.py +++ b/frontend/catalyst/compiler.py @@ -28,6 +28,7 @@ from os import path from typing import List, Optional +from catalyst.debug.debugger import debugger_is_active from catalyst.logging import debug_logger, debug_logger_init from catalyst.pipelines import CompileOptions from catalyst.utils.exceptions import CompileError @@ -438,10 +439,24 @@ def run_from_ir(self, ir: str, module_name: str, workspace: Directory): output_ir_name = os.path.join(str(workspace), f"{module_name}.ll") cmd = self.get_cli_command(tmp_infile_name, output_ir_name, module_name, workspace) + import signal + try: if self.options.verbose: print(f"[SYSTEM] {' '.join(cmd)}", file=self.options.logfile) - result = subprocess.run(cmd, check=True, capture_output=True, text=True) + + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + if p.returncode not in {0, None}: + raise subprocess.CalledProcessError(p.returncode, cmd) + + if debugger_is_active(): + print(f"Compiler PID={p.pid}") + print( + f"Ensure gdb/lldb debugger is attached and running before continuing with:\nkill -s SIGCONT {p.pid}" + ) + p.send_signal(signal.SIGSTOP) + + result = p.communicate() if self.options.verbose or os.getenv("ENABLE_DIAGNOSTICS"): if result.stdout: print(result.stdout.strip(), file=self.options.logfile) diff --git a/frontend/catalyst/pipelines.py b/frontend/catalyst/pipelines.py index 49ece83c56..1cdf0fede1 100644 --- a/frontend/catalyst/pipelines.py +++ b/frontend/catalyst/pipelines.py @@ -94,6 +94,7 @@ class CompileOptions: circuit_transform_pipeline: Optional[dict[str, dict[str, str]]] = None pass_plugins: Optional[Set[Path]] = None dialect_plugins: Optional[Set[Path]] = None + debug_compiler: Optional[bool] = False def __post_init__(self): # Check that async runs must not be seeded From 52d848bd2629e46dd732305ed5ae7ea02138f068 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 2 May 2025 16:15:57 -0400 Subject: [PATCH 02/20] Add debug flag autocheck --- frontend/catalyst/compiler.py | 4 ++-- frontend/catalyst/debug/__init__.py | 2 ++ frontend/catalyst/debug/debugger.py | 26 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 frontend/catalyst/debug/debugger.py diff --git a/frontend/catalyst/compiler.py b/frontend/catalyst/compiler.py index de54902f3e..8d1a529b0f 100644 --- a/frontend/catalyst/compiler.py +++ b/frontend/catalyst/compiler.py @@ -28,7 +28,7 @@ from os import path from typing import List, Optional -from catalyst.debug.debugger import debugger_is_active +from catalyst.debug.debugger import is_debugger_active from catalyst.logging import debug_logger, debug_logger_init from catalyst.pipelines import CompileOptions from catalyst.utils.exceptions import CompileError @@ -449,7 +449,7 @@ def run_from_ir(self, ir: str, module_name: str, workspace: Directory): if p.returncode not in {0, None}: raise subprocess.CalledProcessError(p.returncode, cmd) - if debugger_is_active(): + if self.options.debug_compiler and is_debugger_active(): print(f"Compiler PID={p.pid}") print( f"Ensure gdb/lldb debugger is attached and running before continuing with:\nkill -s SIGCONT {p.pid}" diff --git a/frontend/catalyst/debug/__init__.py b/frontend/catalyst/debug/__init__.py index 20f00c1fc2..3f151ed24c 100644 --- a/frontend/catalyst/debug/__init__.py +++ b/frontend/catalyst/debug/__init__.py @@ -22,6 +22,7 @@ get_compilation_stages_groups, replace_ir, ) +from catalyst.debug.debugger import is_debugger_active from catalyst.debug.instruments import instrumentation from catalyst.debug.printing import ( # pylint: disable=redefined-builtin print, @@ -38,4 +39,5 @@ "instrumentation", "replace_ir", "compile_executable", + "is_debugger_active", ) diff --git a/frontend/catalyst/debug/debugger.py b/frontend/catalyst/debug/debugger.py new file mode 100644 index 0000000000..4bb4ceeb7b --- /dev/null +++ b/frontend/catalyst/debug/debugger.py @@ -0,0 +1,26 @@ +# Copyright 2025 Xanadu Quantum Technologies Inc. + +# 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 + +# http://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. + +""" +This module adds functionality to check if the active Python session +is being run with an active debugger. +""" + + +import sys + + +def is_debugger_active() -> bool: + """Will return true in active debugger session""" + return hasattr(sys, "gettrace") and sys.gettrace() From 6101c6f37607228af8a8f62d96ccd5e8fd02d5a8 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 2 May 2025 16:57:26 -0400 Subject: [PATCH 03/20] Ensure VSCode debugger launch file is tracked --- .vscode/launch.json | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..23a0e216a2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "(debugpy): Debug Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": false + }, + { + "name": "(gdb): Attach To Python Process", + "type": "cppdbg", + "request": "attach", + "program": "${command:python.interpreterPath}", + "processId": "${command:pickProcess}", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true, + } + ] + } + ] +} From 4d1ff9468421e85c800a3ed88f76fa11f3745e76 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 2 May 2025 16:57:47 -0400 Subject: [PATCH 04/20] Add debug_compiler args to CompileOptions and qjit --- frontend/catalyst/jit.py | 3 +++ frontend/catalyst/pipelines.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/frontend/catalyst/jit.py b/frontend/catalyst/jit.py index b6d7cc182f..62148164e9 100644 --- a/frontend/catalyst/jit.py +++ b/frontend/catalyst/jit.py @@ -94,6 +94,7 @@ def qjit( circuit_transform_pipeline=None, pass_plugins=None, dialect_plugins=None, + debug_compiler=False ): # pylint: disable=too-many-arguments,unused-argument """A just-in-time decorator for PennyLane and JAX programs using Catalyst. @@ -161,6 +162,8 @@ def qjit( If not specified, the default pass pipeline will be applied. pass_plugins (Optional[List[Path]]): List of paths to pass plugins. dialect_plugins (Optional[List[Path]]): List of paths to dialect plugins. + debug_compiler (Optional[bool]): Enable external debugger attachment to the compiler + driver when launching from an active Python debugging environment. Returns: QJIT object. diff --git a/frontend/catalyst/pipelines.py b/frontend/catalyst/pipelines.py index 1cdf0fede1..4decec6a2d 100644 --- a/frontend/catalyst/pipelines.py +++ b/frontend/catalyst/pipelines.py @@ -74,6 +74,8 @@ class CompileOptions: Default is None. pass_plugins (Optional[Set[Path]]): List of paths to pass plugins. dialect_plugins (Optional[Set[Path]]): List of paths to dialect plugins. + debug_compiler (Optional[bool]): Enable external debugger attachment to the compiler + driver when launching from an active Python debugging environment. """ verbose: Optional[bool] = False From 21686dd280afcd8c62bdfe5e0cde90945ab893d4 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 2 May 2025 17:13:24 -0400 Subject: [PATCH 05/20] Fix stdout stderr from popen --- frontend/catalyst/compiler.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/catalyst/compiler.py b/frontend/catalyst/compiler.py index 8d1a529b0f..3326271f8a 100644 --- a/frontend/catalyst/compiler.py +++ b/frontend/catalyst/compiler.py @@ -456,12 +456,12 @@ def run_from_ir(self, ir: str, module_name: str, workspace: Directory): ) p.send_signal(signal.SIGSTOP) - result = p.communicate() + res_stdout, res_stderr = p.communicate() if self.options.verbose or os.getenv("ENABLE_DIAGNOSTICS"): - if result.stdout: - print(result.stdout.strip(), file=self.options.logfile) - if result.stderr: - print(result.stderr.strip(), file=self.options.logfile) + if res_stdout: + print(res_stdout.strip(), file=self.options.logfile) + if res_stderr: + print(res_stderr.strip(), file=self.options.logfile) except subprocess.CalledProcessError as e: # pragma: nocover raise CompileError(f"catalyst failed with error code {e.returncode}: {e.stderr}") from e From 97cd18bdc7eb171fa7465d3e31da638e96261f81 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 2 May 2025 17:16:57 -0400 Subject: [PATCH 06/20] Update debugger prompt --- frontend/catalyst/compiler.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/frontend/catalyst/compiler.py b/frontend/catalyst/compiler.py index 3326271f8a..b076e157aa 100644 --- a/frontend/catalyst/compiler.py +++ b/frontend/catalyst/compiler.py @@ -21,6 +21,7 @@ import pathlib import platform import shutil +import signal import subprocess import sys import tempfile @@ -439,24 +440,26 @@ def run_from_ir(self, ir: str, module_name: str, workspace: Directory): output_ir_name = os.path.join(str(workspace), f"{module_name}.ll") cmd = self.get_cli_command(tmp_infile_name, output_ir_name, module_name, workspace) - import signal try: if self.options.verbose: print(f"[SYSTEM] {' '.join(cmd)}", file=self.options.logfile) - p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - if p.returncode not in {0, None}: - raise subprocess.CalledProcessError(p.returncode, cmd) - - if self.options.debug_compiler and is_debugger_active(): - print(f"Compiler PID={p.pid}") - print( - f"Ensure gdb/lldb debugger is attached and running before continuing with:\nkill -s SIGCONT {p.pid}" - ) - p.send_signal(signal.SIGSTOP) - - res_stdout, res_stderr = p.communicate() + with subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True + ) as p: + if p.returncode not in {0, None}: + raise subprocess.CalledProcessError(p.returncode, cmd) + + if self.options.debug_compiler and is_debugger_active(): + print(f"Compiler PID={p.pid}") + print( + f"""Ensure C++ debugger is attached and running before continuing with: + kill -s SIGCONT {p.pid}""" + ) + p.send_signal(signal.SIGSTOP) + + res_stdout, res_stderr = p.communicate() if self.options.verbose or os.getenv("ENABLE_DIAGNOSTICS"): if res_stdout: print(res_stdout.strip(), file=self.options.logfile) From 6d779764f7668f479031c070f190575705781777 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 11:46:39 -0400 Subject: [PATCH 07/20] Add external build type makefile arg for middle-end --- mlir/Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mlir/Makefile b/mlir/Makefile index 496dc26ee5..00cfbb623d 100644 --- a/mlir/Makefile +++ b/mlir/Makefile @@ -13,6 +13,7 @@ RT_BUILD_DIR ?= $(MK_DIR)/../runtime/build ENABLE_ASAN ?= OFF STRICT_WARNINGS ?= ON BUILD_TYPE ?= Release +BUILD_TYPE_EXT ?= Release LLVM_EXTERNAL_LIT ?= $(LLVM_BUILD_DIR)/bin/llvm-lit ifeq ($(shell uname), Darwin) @@ -65,7 +66,7 @@ llvm: patch -p1 $(TARGET_FILE) $(PATCH_FILE); \ fi cmake -G Ninja -S llvm-project/llvm -B $(LLVM_BUILD_DIR) \ - -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE_EXT) \ -DLLVM_BUILD_EXAMPLES=OFF \ -DLLVM_TARGETS_TO_BUILD="host" \ -DLLVM_ENABLE_PROJECTS="$(LLVM_PROJECTS)" \ @@ -101,7 +102,7 @@ mhlo: patch -p1 $(TARGET_FILE) $(PATCH_FILE); \ fi cmake -G Ninja -S mlir-hlo -B $(MHLO_BUILD_DIR) \ - -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE_EXT) \ -DLLVM_ENABLE_ASSERTIONS=ON \ -DMLIR_DIR=$(LLVM_BUILD_DIR)/lib/cmake/mlir \ -DPython3_EXECUTABLE=$(PYTHON) \ @@ -123,7 +124,7 @@ enzyme: @echo "build enzyme" cmake -G Ninja -S Enzyme/enzyme -B $(ENZYME_BUILD_DIR) \ -DENZYME_STATIC_LIB=ON \ - -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE_EXT) \ -DLLVM_DIR=$(LLVM_BUILD_DIR)/lib/cmake/llvm \ -DCMAKE_C_COMPILER=$(C_COMPILER) \ -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) \ @@ -144,6 +145,7 @@ plugin: cmake -B standalone/build -G Ninja \ -DCMAKE_C_COMPILER=$(C_COMPILER) \ -DCMAKE_CXX_COMPILER=$(CXX_COMPILER) \ + -DCMAKE_BUILD_TYPE=$(BUILD_TYPE_EXT) \ -DCMAKE_C_COMPILER_LAUNCHER=$(COMPILER_LAUNCHER) \ -DCMAKE_CXX_COMPILER_LAUNCHER=$(COMPILER_LAUNCHER) \ -DMLIR_DIR=$(LLVM_BUILD_DIR)/lib/cmake/mlir \ From afba2ce1d339fe8e479b9caaf6117809ae0b00e2 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:14:53 -0400 Subject: [PATCH 08/20] Add debugging docs for mixed-mode --- doc/dev/debugging.rst | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/doc/dev/debugging.rst b/doc/dev/debugging.rst index bf776f4cfc..67c2f76a02 100644 --- a/doc/dev/debugging.rst +++ b/doc/dev/debugging.rst @@ -388,3 +388,81 @@ corresponding arguments. $ /path/to/executable MemRef: base@ = 0x64fc9dd5ffc0 rank = 0 offset = 0 sizes = [] strides = [] data = 25 + +Mixed-mode debugging of Python and C++ +====================================== + +Catalyst supports mixed-mode debugging of Python and/or C++ code when providing the ``debug_compiler=True`` flag to +the ``@qjit`` decorator. Enabling this option signals to the compiler to wait for an appropriate user-provided signal +after launching the compiler process. Some notes about use of this support: + +* This functionality requires building Catalyst with debug symbols. This can be achieved via make all +``BUILD_TYPE="RelWithDebInfo"``. The debug symbols are only within available within the Catalyst-owned targets. +To enable debugging of LLVM and other associated external libraries and binaries, ensure the +``BUILD_TYPE_EXT="RelWithDebInfo"`` option is also set. +* Launching the C++ debugger requires attaching to a running process. This often requires ``sudo`` privileges on the running system. +* The spawned compiler subprocess immediately issues a ``SIGSTOP`` signal to avoid execution of the compiler. To continue execution +requires receipt of a ``SIGCONT`` signal after the C++ debugger has attached. + +The signalling steps can be provided via an active terminal session as + +.. code-block:: shell + + $ kill -s SIGCONT + +where ```` is the process-ID. This can also be issued from an active Python debugger session, such as through VSCode's +debug terminal as + +.. code-block:: python + + import os, signal + os.kill(, signal.SIGCONT) + +To enable support from VSCode, the following configuration files can be used to add debugger configurations for Python, and +C++. + +.. code-block:: json + :caption: .vscode/launch.json + + { + "version": "0.2.0", + "configurations": [ + { + "name": "(Python): Debug Current Python File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal", + "justMyCode": false + }, + { + "name": "(C++): Attach To Executing Python Process", + "type": "cppdbg", + "request": "attach", + "program": "${workspaceFolder}/pyenv/bin/python", + "processId": "${command:pickProcess}", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing", + "text": "-enable-pretty-printing", + "ignoreFailures": true, + } + ] + }, + ] + } + + +.. code-block:: json + :caption: .vscode/settings.json + + { + "python.defaultInterpreterPath": "${env:VIRTUAL_ENV}", + "python.terminal.launchArgs": [], + } + + +Note that on MacOS ``gdb`` will alias ``lldb``, and will continue to function identically +to ``gdb`` on Linux using the editor's debugging interface. To explicitly use ``lldb`` on Linux, it may be necessary to also +the `machine-interface driver `_. From deb050214cba1700fb92928e7bbee10708f338cc Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:15:11 -0400 Subject: [PATCH 09/20] Remove restriction on launching from a Python debugger --- frontend/catalyst/compiler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/catalyst/compiler.py b/frontend/catalyst/compiler.py index e49c33fcf7..bdf8398342 100644 --- a/frontend/catalyst/compiler.py +++ b/frontend/catalyst/compiler.py @@ -451,7 +451,7 @@ def run_from_ir(self, ir: str, module_name: str, workspace: Directory): if p.returncode not in {0, None}: raise subprocess.CalledProcessError(p.returncode, cmd) - if self.options.debug_compiler and is_debugger_active(): + if self.options.debug_compiler: print(f"Compiler PID={p.pid}") print( f"""Ensure C++ debugger is attached and running before continuing with: From 23a8cc582f030a8a737e4c9847ea0840daade769 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:21:57 -0400 Subject: [PATCH 10/20] Add caption for filenames --- doc/dev/debugging.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/dev/debugging.rst b/doc/dev/debugging.rst index 67c2f76a02..7a7b70ba74 100644 --- a/doc/dev/debugging.rst +++ b/doc/dev/debugging.rst @@ -397,12 +397,13 @@ the ``@qjit`` decorator. Enabling this option signals to the compiler to wait fo after launching the compiler process. Some notes about use of this support: * This functionality requires building Catalyst with debug symbols. This can be achieved via make all -``BUILD_TYPE="RelWithDebInfo"``. The debug symbols are only within available within the Catalyst-owned targets. + ``BUILD_TYPE="RelWithDebInfo"``. The debug symbols are only within available within the Catalyst-owned targets. To enable debugging of LLVM and other associated external libraries and binaries, ensure the -``BUILD_TYPE_EXT="RelWithDebInfo"`` option is also set. -* Launching the C++ debugger requires attaching to a running process. This often requires ``sudo`` privileges on the running system. -* The spawned compiler subprocess immediately issues a ``SIGSTOP`` signal to avoid execution of the compiler. To continue execution -requires receipt of a ``SIGCONT`` signal after the C++ debugger has attached. + ``BUILD_TYPE_EXT="RelWithDebInfo"`` option is also set. +* Launching the C++ debugger requires attaching to a running process. This often requires ``sudo`` privileges on the + running system. +* The spawned compiler subprocess immediately issues a ``SIGSTOP`` signal to avoid execution of the compiler. To + continue execution requires receipt of a ``SIGCONT`` signal after the C++ debugger has attached. The signalling steps can be provided via an active terminal session as @@ -422,7 +423,7 @@ To enable support from VSCode, the following configuration files can be used to C++. .. code-block:: json - :caption: .vscode/launch.json + :caption: Filename ``.vscode/launch.json`` { "version": "0.2.0", @@ -455,7 +456,7 @@ C++. .. code-block:: json - :caption: .vscode/settings.json + :caption: Filename ``.vscode/settings.json`` { "python.defaultInterpreterPath": "${env:VIRTUAL_ENV}", From a6e75141a7dc2b75f2264dacf8b81e660e88580e Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:26:50 -0400 Subject: [PATCH 11/20] Add python debug session checker --- doc/dev/debugging.rst | 2 ++ frontend/catalyst/compiler.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/dev/debugging.rst b/doc/dev/debugging.rst index 7a7b70ba74..d4d037d1d1 100644 --- a/doc/dev/debugging.rst +++ b/doc/dev/debugging.rst @@ -404,6 +404,8 @@ To enable debugging of LLVM and other associated external libraries and binaries running system. * The spawned compiler subprocess immediately issues a ``SIGSTOP`` signal to avoid execution of the compiler. To continue execution requires receipt of a ``SIGCONT`` signal after the C++ debugger has attached. +* To validate if running within an active (Python) debugger session, the function :func:`~.debug.debugger.is_debugger_active` + can be used. The signalling steps can be provided via an active terminal session as diff --git a/frontend/catalyst/compiler.py b/frontend/catalyst/compiler.py index bdf8398342..90be4d6642 100644 --- a/frontend/catalyst/compiler.py +++ b/frontend/catalyst/compiler.py @@ -29,7 +29,6 @@ from os import path from typing import List, Optional -from catalyst.debug.debugger import is_debugger_active from catalyst.logging import debug_logger, debug_logger_init from catalyst.pipelines import CompileOptions from catalyst.utils.exceptions import CompileError From fcc3895b87fa5096c6a4622dc5a8de7819b27534 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:30:10 -0400 Subject: [PATCH 12/20] Use editor interpreter path --- doc/dev/debugging.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/debugging.rst b/doc/dev/debugging.rst index d4d037d1d1..d81519f627 100644 --- a/doc/dev/debugging.rst +++ b/doc/dev/debugging.rst @@ -442,7 +442,7 @@ C++. "name": "(C++): Attach To Executing Python Process", "type": "cppdbg", "request": "attach", - "program": "${workspaceFolder}/pyenv/bin/python", + "program": "${command:python.interpreterPath}", "processId": "${command:pickProcess}", "MIMode": "gdb", "setupCommands": [ From f40a06bedd89b5ecabbc28ebc371d0bc92dbe04f Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:32:40 -0400 Subject: [PATCH 13/20] Move debug config to docs --- .vscode/launch.json | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 23a0e216a2..0000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "name": "(debugpy): Debug Current File", - "type": "debugpy", - "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "justMyCode": false - }, - { - "name": "(gdb): Attach To Python Process", - "type": "cppdbg", - "request": "attach", - "program": "${command:python.interpreterPath}", - "processId": "${command:pickProcess}", - "MIMode": "gdb", - "setupCommands": [ - { - "description": "Enable pretty-printing for gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true, - } - ] - } - ] -} From 9c84fcbf702e3ac9895f8ef2a138c62eb941fdd0 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:38:26 -0400 Subject: [PATCH 14/20] Add CL --- doc/releases/changelog-dev.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/releases/changelog-dev.md b/doc/releases/changelog-dev.md index f8b7311b9e..7a2553b108 100644 --- a/doc/releases/changelog-dev.md +++ b/doc/releases/changelog-dev.md @@ -212,6 +212,10 @@

Internal changes ⚙️

+* `qjit` now supports a `debug_compiler` argument, which signals that the compiler driver should stop and wait + for a user-provided `SIGNCONT`. This allows developer to attach a debugger session to the driver before processing its input. + [(#1712)](https://github.com/PennyLaneAI/catalyst/pull/1712) + * `null.qubit` can now support an optional `track_resources` argument which allows it to record which gates are executed. [(#1619)](https://github.com/PennyLaneAI/catalyst/pull/1619) @@ -291,6 +295,10 @@

Documentation 📝

+* Documentation for the configuration of mixed-mode (Python and C++) debugging with Catalyst has + been added. Configuration guidelines are provided for VSCode. + [(#1712)](https://github.com/PennyLaneAI/catalyst/pull/1712) + * The header (logo+title) images in the README and in the overview on RtD have been updated, reflecting that Catalyst is now beyond the beta! [(#1718)](https://github.com/PennyLaneAI/catalyst/pull/1718) @@ -312,6 +320,7 @@ Christina Lee, Mehrdad Malekmohammadi, Anton Naim Ibrahim, Erick Ochoa Lopez, +Lee J. O'Riordan, Ritu Thombre, Paul Haochen Wang, Jake Zaia. From dbe0908e0bed00adfaf61289c933cd228ebe66dc Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:40:41 -0400 Subject: [PATCH 15/20] Rehide the internal active debug check --- frontend/catalyst/debug/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/catalyst/debug/__init__.py b/frontend/catalyst/debug/__init__.py index 3f151ed24c..ab3dba57c7 100644 --- a/frontend/catalyst/debug/__init__.py +++ b/frontend/catalyst/debug/__init__.py @@ -38,6 +38,5 @@ "get_cmain", "instrumentation", "replace_ir", - "compile_executable", - "is_debugger_active", + "compile_executable" ) From 25583b3a48afd2f661c7c9fdd1e1feb3af8d04a5 Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 15:43:45 -0400 Subject: [PATCH 16/20] fix format --- frontend/catalyst/debug/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/catalyst/debug/__init__.py b/frontend/catalyst/debug/__init__.py index ab3dba57c7..f11574950f 100644 --- a/frontend/catalyst/debug/__init__.py +++ b/frontend/catalyst/debug/__init__.py @@ -38,5 +38,5 @@ "get_cmain", "instrumentation", "replace_ir", - "compile_executable" + "compile_executable", ) From fa50232336f9da94e281d50a77e01388a0b6e4bb Mon Sep 17 00:00:00 2001 From: "Lee J. O'Riordan" Date: Fri, 30 May 2025 18:03:46 -0400 Subject: [PATCH 17/20] Ensure stdout,stderr tracked from subprocess --- frontend/catalyst/compiler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/catalyst/compiler.py b/frontend/catalyst/compiler.py index 90be4d6642..6c92aa6b96 100644 --- a/frontend/catalyst/compiler.py +++ b/frontend/catalyst/compiler.py @@ -447,6 +447,7 @@ def run_from_ir(self, ir: str, module_name: str, workspace: Directory): with subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True ) as p: + # Ensure process creation succeeds if p.returncode not in {0, None}: raise subprocess.CalledProcessError(p.returncode, cmd) @@ -459,6 +460,10 @@ def run_from_ir(self, ir: str, module_name: str, workspace: Directory): p.send_signal(signal.SIGSTOP) res_stdout, res_stderr = p.communicate() + # Ensure process execution succeeds + if p.returncode not in {0, None}: + raise subprocess.CalledProcessError(p.returncode, cmd, res_stdout, res_stderr) + if self.options.verbose or os.getenv("ENABLE_DIAGNOSTICS"): if res_stdout: print(res_stdout.strip(), file=self.options.logfile) From 004ebff4243fc68efac5c4978357af9273824217 Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Fri, 30 May 2025 18:09:23 -0400 Subject: [PATCH 18/20] Update doc/dev/debugging.rst Co-authored-by: David Ittah --- doc/dev/debugging.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/dev/debugging.rst b/doc/dev/debugging.rst index d81519f627..c49b490cf1 100644 --- a/doc/dev/debugging.rst +++ b/doc/dev/debugging.rst @@ -396,8 +396,9 @@ Catalyst supports mixed-mode debugging of Python and/or C++ code when providing the ``@qjit`` decorator. Enabling this option signals to the compiler to wait for an appropriate user-provided signal after launching the compiler process. Some notes about use of this support: -* This functionality requires building Catalyst with debug symbols. This can be achieved via make all - ``BUILD_TYPE="RelWithDebInfo"``. The debug symbols are only within available within the Catalyst-owned targets. +* This functionality requires building Catalyst with debug symbols. This can be achieved via + ``make all BUILD_TYPE="RelWithDebInfo"``. The debug symbols are only within available + within the Catalyst-owned targets. To enable debugging of LLVM and other associated external libraries and binaries, ensure the ``BUILD_TYPE_EXT="RelWithDebInfo"`` option is also set. * Launching the C++ debugger requires attaching to a running process. This often requires ``sudo`` privileges on the From 6ddad2ae434c76c66860775f65af87d536c017e5 Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Mon, 2 Jun 2025 16:12:10 -0400 Subject: [PATCH 19/20] Update doc/dev/debugging.rst Co-authored-by: David Ittah --- doc/dev/debugging.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/debugging.rst b/doc/dev/debugging.rst index c49b490cf1..59564cfa9b 100644 --- a/doc/dev/debugging.rst +++ b/doc/dev/debugging.rst @@ -397,7 +397,7 @@ the ``@qjit`` decorator. Enabling this option signals to the compiler to wait fo after launching the compiler process. Some notes about use of this support: * This functionality requires building Catalyst with debug symbols. This can be achieved via - ``make all BUILD_TYPE="RelWithDebInfo"``. The debug symbols are only within available + ``make all BUILD_TYPE="RelWithDebInfo"``. The debug symbols are only available within the Catalyst-owned targets. To enable debugging of LLVM and other associated external libraries and binaries, ensure the ``BUILD_TYPE_EXT="RelWithDebInfo"`` option is also set. From 634f8fdf2fd96317b8bddbd02c1681b9a50fddaf Mon Sep 17 00:00:00 2001 From: Lee James O'Riordan Date: Mon, 2 Jun 2025 16:12:26 -0400 Subject: [PATCH 20/20] Update doc/dev/debugging.rst Co-authored-by: David Ittah --- doc/dev/debugging.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/dev/debugging.rst b/doc/dev/debugging.rst index 59564cfa9b..5591c3cd42 100644 --- a/doc/dev/debugging.rst +++ b/doc/dev/debugging.rst @@ -400,7 +400,7 @@ after launching the compiler process. Some notes about use of this support: ``make all BUILD_TYPE="RelWithDebInfo"``. The debug symbols are only available within the Catalyst-owned targets. To enable debugging of LLVM and other associated external libraries and binaries, ensure the - ``BUILD_TYPE_EXT="RelWithDebInfo"`` option is also set. + ``BUILD_TYPE_EXT="RelWithDebInfo"`` option is also set when building Catalyst. * Launching the C++ debugger requires attaching to a running process. This often requires ``sudo`` privileges on the running system. * The spawned compiler subprocess immediately issues a ``SIGSTOP`` signal to avoid execution of the compiler. To