Commit 3ad87f0
[monolithic change] Rework the way CUDA-Q embeds in Python (#3693)
[Python] Total rewrite of the python/CUDA-Q interface.
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.
and many other changes!
Signed-off-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Thien Nguyen <thiennguyen@nvidia.com>
Co-authored-by: Bettina Heim <heimb@outlook.com>
Co-authored-by: Sachin Pisal <spisal@nvidia.com>1 parent d6b8bc7 commit 3ad87f0
File tree
318 files changed
+12650
-15371
lines changed- .github/workflows/config
- cmake/Modules
- docs
- sphinx
- applications/python
- afqmc_src
- examples/python
- include/cudaq
- Frontend/nvqpp
- Optimizer
- Builder
- CodeGen
- Dialect
- CC
- Quake
- Transforms
- lib
- Frontend/nvqpp
- Optimizer
- Builder
- CodeGen
- Dialect/CC
- Transforms
- python
- cudaq
- kernel
- runtime
- visualization
- extension
- runtime
- common
- cudaq
- algorithms
- domains/plugins
- platform
- interop
- mlir
- utils
- tests
- backends
- builder
- custom
- domains
- dynamics
- handlers
- interop
- kernel
- mlir
- utils
- parallel
- remote
- visualization
- utils
- runtime
- common
- cudaq
- algorithms
- builder
- platform
- default
- python
- rest_server
- rest/helpers/quantinuum
- mqpu
- orca
- qis
- nvqir
- cutensornet
- qpp
- test
- targettests
- Remote-Sim
- execution
- infleqtion
- ionq
- qci
- quantinuum
- quantum_machines
- test
- AST-Quake
- NVQPP
- Transforms
- Translate
- OpenQASM
- tools
- cudaq-opt
- cudaq-qpud
- cudaq-translate
- nvqpp
- unittests
- backends
- pasqal
- quantinuum
- quera
- integration
- output_record
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
318 files changed
+12650
-15371
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
194 | | - | |
195 | 193 | | |
196 | 194 | | |
197 | 195 | | |
| |||
202 | 200 | | |
203 | 201 | | |
204 | 202 | | |
| 203 | + | |
| 204 | + | |
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
| |||
147 | 154 | | |
148 | 155 | | |
149 | 156 | | |
150 | | - | |
| 157 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
147 | 149 | | |
148 | 150 | | |
149 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
255 | | - | |
| 255 | + | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| |||
264 | 264 | | |
265 | 265 | | |
266 | 266 | | |
267 | | - | |
| 267 | + | |
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
| 312 | + | |
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| |||
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
486 | | - | |
| 486 | + | |
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
| |||
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
540 | | - | |
| 540 | + | |
541 | 541 | | |
542 | 542 | | |
543 | 543 | | |
| |||
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | | - | |
| 554 | + | |
555 | 555 | | |
556 | 556 | | |
557 | 557 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
| 265 | + | |
266 | 266 | | |
267 | 267 | | |
268 | 268 | | |
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
| 288 | + | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| |||
345 | 345 | | |
346 | 346 | | |
347 | 347 | | |
348 | | - | |
| 348 | + | |
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
| |||
557 | 557 | | |
558 | 558 | | |
559 | 559 | | |
560 | | - | |
561 | | - | |
| 560 | + | |
| 561 | + | |
562 | 562 | | |
563 | 563 | | |
564 | 564 | | |
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
| 577 | + | |
578 | 578 | | |
579 | 579 | | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
580 | 584 | | |
581 | 585 | | |
582 | 586 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
152 | 154 | | |
153 | 155 | | |
154 | 156 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
385 | | - | |
| 385 | + | |
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| |||
415 | 415 | | |
416 | 416 | | |
417 | 417 | | |
418 | | - | |
| 418 | + | |
419 | 419 | | |
420 | 420 | | |
421 | 421 | | |
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
447 | | - | |
| 447 | + | |
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| |||
464 | 464 | | |
465 | 465 | | |
466 | 466 | | |
467 | | - | |
| 467 | + | |
468 | 468 | | |
469 | 469 | | |
470 | 470 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
110 | | - | |
| 110 | + | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
| 113 | + | |
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| |||
Lines changed: 28 additions & 18 deletions
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
| 406 | + | |
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| |||
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
427 | | - | |
| 427 | + | |
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
| 433 | + | |
434 | 434 | | |
435 | 435 | | |
436 | 436 | | |
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
454 | | - | |
| 454 | + | |
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
| |||
0 commit comments