Skip to content

Conversation

@schweitzpgi
Copy link
Collaborator

This is a huge change that crosscuts almost every aspect of the system (except for the C++ frontend, maybe?).

The main drivers are:

  • Replace all the random, ad hoc compiler pipelines being used in the Python compiler front-end with pipelines that the C++ compiler uses
  • To achieve the previous bullet required
    • Changing pipelines that were run backwards or multiple times
    • Getting rid of ad hoc caches of information kept at all levels of the code
    • Deploying proper lambda lifting and beta reduction steps at definition and call, resp.
    • Radical brain surgery on Python kernel launchers (algorithms) so that they could properly resolve symbols in context
    • Fixing the misuse of MLIR symbols
    • Removing ad hoc, blind, and error prone pruning of MLIR code
    • Fixing bugs due to the conflation of kernel definition and kernel call semantics
    • Fixing tests with errors, bugs, etc.
  • This includes folding (back) in changes to the Python ast_bridge (Python bridge revision #3537)

schweitzpgi and others added 30 commits December 2, 2025 09:40
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
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.

Other changes include:

Fix GIL issue in get_state_async.

Restructure lambda lifting so it handles recursive ops.

Clone the ModuleOps as they go into the make_copyable_function closure
to prevent them from being erased along the way.

Remove VQE tests. Use VQE from CUDA-QX!

Simplifying cudaq::state support.

Handle kernel decorator from import module

Simplify the symbol table. Python is not a scoped language other than LEGB.

Convert kernel builder to generate code compatible with C++ for state initialization of veqs.

Refactor the AST bridge to generate state objects from the runtime.

Fixes for various tests.

Signed-off-by: Eric Schweitz <[email protected]>
Co-authored-by: Thien Nguyen <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
* Fixes for alternate module resolution.

Teaches kernel launching to understand how to deal with qualified symbols
and the symbol lookup rules that are entailed from that.

Signed-off-by: Eric Schweitz <[email protected]>

* Fix module seeking issues.

Signed-off-by: Eric Schweitz <[email protected]>

* Remove debug print.

Signed-off-by: Eric Schweitz <[email protected]>

---------

Signed-off-by: Eric Schweitz <[email protected]>
* Don't implicit handle density matrix as a flattened vector

Signed-off-by: Thien Nguyen <[email protected]>

* Format

Signed-off-by: Thien Nguyen <[email protected]>

* Fix Clang build

Signed-off-by: Thien Nguyen <[email protected]>

* Code review: fix style and add test

Signed-off-by: Thien Nguyen <[email protected]>

* Fix clang build

Signed-off-by: Thien Nguyen <[email protected]>

* More clang build fix

Signed-off-by: Thien Nguyen <[email protected]>

---------

Signed-off-by: Thien Nguyen <[email protected]>
Much of this no longer makes much sense, but port the parts of the tests
that do make sense to the new Python refactoring.

Specifically verboten: It does not make sense to try and synthesize Python
kernel decorators or look them up by non-unique short names in C++ code. The
python interpreter knows what kernel decorators it is referencing and must
do the resolution of symbols to bindings.

Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Thien Nguyen <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Signed-off-by: Eric Schweitz <[email protected]>
Correcting the last weight (#3654)
[features/py-redesign] Fix for C++ mock server tests
Signed-off-by: Eric Schweitz <[email protected]>
@sacpis
Copy link
Collaborator

sacpis commented Dec 30, 2025

/ok to test 47806d2

Command Bot: Processing...

@sacpis
Copy link
Collaborator

sacpis commented Dec 30, 2025

/ok to test e9bfaed

Command Bot: Processing...

@sacpis
Copy link
Collaborator

sacpis commented Jan 2, 2026

/ok to test 4ba0d0b

Command Bot: Processing...

@schweitzpgi
Copy link
Collaborator Author

schweitzpgi commented Jan 5, 2026

/ok to test 7ef7a0f

Command Bot: Processing...

@schweitzpgi
Copy link
Collaborator Author

schweitzpgi commented Jan 5, 2026

/ok to test d0f9ec4

Command Bot: Processing...

github-actions bot pushed a commit that referenced this pull request Jan 6, 2026
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

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

@sacpis
Copy link
Collaborator

sacpis commented Jan 6, 2026

/ok to test afae941

Command Bot: Processing...

I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: 39ec1fe
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: 47088c5
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: de9912a
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: 917efc1
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: 01ef52b
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: 37ac0ed
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: 383a4d5
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: 2db277f
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: a346745
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: d604ba6
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: b5d0963
I, Sachin Pisal <[email protected]>, hereby add my Signed-off-by to this commit: 11474fb

Signed-off-by: Sachin Pisal <[email protected]>
@sacpis
Copy link
Collaborator

sacpis commented Jan 6, 2026

/ok to test b9c6342

Command Bot: Processing...

I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 7bf59b9
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 97e2216
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 7c9197b
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: bfba600
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: f78e4ab

Signed-off-by: Thien Nguyen <[email protected]>
@sacpis
Copy link
Collaborator

sacpis commented Jan 6, 2026

/ok to test c790937

Command Bot: Processing...

…ply.github.com>

I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 7bf59b9
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 97e2216
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 7c9197b
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: bfba600
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: f78e4ab

Signed-off-by: Thien Nguyen <[email protected]>

Signed-off-by: Thien Nguyen <[email protected]>
…ply.github.com>

I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 7bf59b9
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 97e2216
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: 7c9197b
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: bfba600
I, Thien Nguyen <[email protected]>, hereby add my Signed-off-by to this commit: f78e4ab

Signed-off-by: Thien Nguyen <[email protected]>
@sacpis
Copy link
Collaborator

sacpis commented Jan 6, 2026

/ok to test d6e2d92

Command Bot: Processing...

@sacpis
Copy link
Collaborator

sacpis commented Jan 6, 2026

/ok to test d5e0513

Command Bot: Processing...

github-actions bot pushed a commit that referenced this pull request Jan 6, 2026
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

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

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.

6 participants