Skip to content

Conversation

@1tnguyen
Copy link
Collaborator

Description

(1) Allow override in registerDeviceKernel

(2) Clear kernel decorator's module (parsed from walking the Python AST) as we switch target.
The lack of this module attribute tells the decorator to perform a proper compile().

Note: Other global maps might be populated during kernel constructor (i.e., as Python sees kernels); hence might not be safe to clear.

(3) Python to honor the default simulator environment variable for hardware target emulation. It was hardcoded to qpp for those targets that don't define a simulator.

github-actions bot pushed a commit that referenced this pull request Oct 10, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 15, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

@1tnguyen 1tnguyen marked this pull request as ready for review October 24, 2025 02:35
github-actions bot pushed a commit that referenced this pull request Oct 24, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

github-actions bot pushed a commit that referenced this pull request Oct 24, 2025
@github-actions
Copy link

CUDA Quantum Docs Bot: A preview of the documentation can be found here.

Copy link
Collaborator

@sacpis sacpis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @1tnguyen.

@1tnguyen 1tnguyen merged commit 67fd323 into NVIDIA:main Oct 24, 2025
193 checks passed
github-actions bot pushed a commit that referenced this pull request Oct 24, 2025
@schweitzpgi
Copy link
Collaborator

schweitzpgi commented Oct 24, 2025

I'm going to very likely revert this with my changes.

Yes. I'll revert these changes in my total rewrite of the python handling of builders, decorators, compilation, and launching.

schweitzpgi added a commit to schweitzpgi/cuda-quantum that referenced this pull request Oct 31, 2025
schweitzpgi added a commit to schweitzpgi/cuda-quantum that referenced this pull request Oct 31, 2025
The current implementation of the Python handling of CUDA-Q has baked in
various attempts to deal with the language coupling between Python and
CUDA-Q kernels. These solutions have been accumulating and making it more
and more difficult to work on the Python implementation.

These changes are a total rewrite to bring the Python implementation more
closely aligned with the C++ implementation.

Changes:
  - The kernel builder and kernel decorator are fundamentally different
    and will no longer share a duck-typed interface. It doesn't work well.
    The builder assembles a CUDA-Q kernel dynamically. As such all symbolic
    references are known immediately. The decorator converts a static AST
    of code into a CUDA-Q kernel. Symbolic references are either local or
    not. Non-local symbols are unknown at the point the decorator is
    processed. All non-local symbols in a decorator are recorded with the
    decorator itself and lambda lifted as actual arguments.
  - MLIR requires that symbols be uniqued. The previous implementation ignored
    this requirement.
  - Lazy state maintenance in Python and the C++ runtime layers is buggy and
    not needed. It is removed. This includes dangling MLIR bindings from the
    AST bridge's python MLIR bindings.
  - Kernels are no longer built with assumptions, then rebuilt when those
    guesses prove wrong. Kernels are no longer built and rebuilt for different
    steps in the process. A kernel decorator builds a target agnostic, context
    independent kernel, and saves that MLIR ModuleOp under a unique name.
  - Launch scenarios have been reworked and consolidated to use the ModuleOp
    directly instead of shuffling between string representations (possibly
    under maps that were not thread-safe) and ModuleOp instances.
  - Every step of the process creating a brand new MLIRContext and loading all
    the dialects into that context, etc. is removed. This is done once and the
    Python interpreter uses the same context to build all modules.

These changes also revert some work on the bridge meant to fix bugs that was
in conflict. This includes NVIDIA#3507, NVIDIA#3545.

Signed-off-by: Eric Schweitz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants