Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
0351238
first draft for some bridge fixes
bettinaheim Sep 30, 2025
6e2a893
getting closer with the testing
bettinaheim Sep 30, 2025
461a32e
more tests and fixes
bettinaheim Oct 1, 2025
3249b15
finished the tuple testing
bettinaheim Oct 2, 2025
1cf4e67
some clean up
bettinaheim Oct 6, 2025
77c02a8
allow to deconstruct lists
bettinaheim Oct 6, 2025
912c905
more clean up
bettinaheim Oct 6, 2025
1b6024a
don't assume stack size
bettinaheim Oct 6, 2025
f8e7835
fixed controlled and adjoint
bettinaheim Oct 7, 2025
9104265
tests for callable kernel args with control and adjoint
bettinaheim Oct 7, 2025
0d8d34d
argument conversion needs reexamination
bettinaheim Oct 8, 2025
a5e4944
handling the vect<bool> conversion in the argument conversion
bettinaheim Oct 8, 2025
bd73206
minor clean up
bettinaheim Oct 8, 2025
95054ff
some test clean up
bettinaheim Oct 8, 2025
418ae3b
some test clean up
bettinaheim Oct 8, 2025
7fab128
some bridge clean up
bettinaheim Oct 9, 2025
c8c699d
added a test
bettinaheim Oct 9, 2025
3ada403
more tests
bettinaheim Oct 9, 2025
7c48168
forgot something
bettinaheim Oct 9, 2025
9d611eb
forgot something
bettinaheim Oct 9, 2025
8f5e619
moving processing of veq functions
bettinaheim Oct 9, 2025
a96dccd
minor things
bettinaheim Oct 10, 2025
8ed8d07
reverting a bad change
bettinaheim Oct 10, 2025
6439bca
proper tests for comparison and found some bugs
bettinaheim Oct 10, 2025
6fb2fe7
more tests
bettinaheim Oct 10, 2025
cf202a1
Merge branch 'main' into list-comprehension
bettinaheim Oct 13, 2025
0c03364
we have some issues with data conversion for __quantum__* functions i…
bettinaheim Oct 13, 2025
e164d88
Merge branch 'list-comprehension' of https://github.com/bettinaheim/c…
bettinaheim Oct 13, 2025
8173b7b
last remaining tests for now
bettinaheim Oct 13, 2025
383584b
forgot to commit matching bridge changes
bettinaheim Oct 13, 2025
4bae1a3
adding missing return
bettinaheim Oct 14, 2025
de6e27e
Merge branch 'main' into list-comprehension
bettinaheim Oct 14, 2025
e96b872
formatting
bettinaheim Oct 14, 2025
db8531d
spelling
bettinaheim Oct 14, 2025
491994a
more formatting
bettinaheim Oct 14, 2025
8c4eb96
more formatting
bettinaheim Oct 14, 2025
62b5caa
pull the modulo change out of this PR
bettinaheim Oct 14, 2025
d4f34a5
formatting
bettinaheim Oct 14, 2025
bdbaba1
updating tests for python 3.11-3.13
bettinaheim Oct 15, 2025
277c7f7
Merge branch 'main' into list-comprehension
bettinaheim Oct 15, 2025
fd8074e
adjusting tests for the new errors (or lack thereof)
bettinaheim Oct 15, 2025
26ae70c
Merge branch 'list-comprehension' of https://github.com/bettinaheim/c…
bettinaheim Oct 15, 2025
3011f86
support star for expanding qubit arrays in lists
bettinaheim Oct 15, 2025
f5b183f
minimal support for binary ops in list comprehension
bettinaheim Oct 15, 2025
84515aa
that should update all tests
bettinaheim Oct 16, 2025
9a24085
Merge branch 'main' into list-comprehension
bettinaheim Oct 16, 2025
c49be64
spelling and formatting
bettinaheim Oct 16, 2025
91ee130
Merge branch 'list-comprehension' of https://github.com/bettinaheim/c…
bettinaheim Oct 16, 2025
aa56ce0
allowing almost all binary operators in list comprehension
bettinaheim Oct 16, 2025
81e48f6
formatting
bettinaheim Oct 16, 2025
74eb44d
adding some unpack tests
bettinaheim Oct 16, 2025
59050a5
ajusting example to not use the same local variable as a captured value
bettinaheim Oct 16, 2025
2497c9f
formatting
bettinaheim Oct 16, 2025
88f3b95
ajustments after merge
bettinaheim Oct 16, 2025
dbecdf9
Merge branch 'main' into python-modulo
bettinaheim Oct 20, 2025
946ffe3
Update python/cudaq/kernel/ast_bridge.py
bettinaheim Oct 24, 2025
8053edb
Merge branch 'main' into python-modulo
bettinaheim Oct 24, 2025
2d380b6
formatting
bettinaheim Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions python/cudaq/kernel/ast_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -4604,9 +4604,7 @@ def __process_binary_op(self, left, right, nodeType):
right = self.ifPointerThenLoad(right)

# type promotion for anything except pow to match Python behavior
if not issubclass(
nodeType,
(ast.Pow, ast.Mod)): # FIXME: remove modulo here and fix it below
if not issubclass(nodeType, ast.Pow):
superiorTy = self.__get_superior_type(left.type, right.type)
if superiorTy is not None:
left = self.changeOperandToType(superiorTy,
Expand Down Expand Up @@ -4716,18 +4714,15 @@ def __process_binary_op(self, left, right, nodeType):
self.currentNode)

if issubclass(nodeType, ast.Mod):
# FIXME: This should be revised to
# 1) properly fail when we have a complex number
# 2) use `arith.RemFOp` for floating point
# (these changes are split out into a separate PR
# per review request)
if F64Type.isinstance(left.type):
left = arith.FPToSIOp(self.getIntegerType(), left).result
if F64Type.isinstance(right.type):
right = arith.FPToSIOp(self.getIntegerType(), right).result

self.pushValue(arith.RemUIOp(left, right).result)
return
if IntegerType.isinstance(left.type):
self.pushValue(arith.RemUIOp(left, right).result)
return
if (F64Type.isinstance(left.type) or F32Type.isinstance(left.type)):
self.pushValue(arith.RemFOp(left, right).result)
return
else:
self.emitFatalError("unhandled BinOp.Mod types",
self.currentNode)

if issubclass(nodeType, ast.LShift):
if IntegerType.isinstance(left.type):
Expand Down
44 changes: 23 additions & 21 deletions python/tests/mlir/ast_elif.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_elif():
def cost(thetas: np.ndarray): # can pass 1D ndarray or list
q = cudaq.qvector(4)
for i, theta in enumerate(thetas):
if i % 2.0: # asserting we convert 2.0 to 2
if i % 2.0: # asserting we convert i to float
ry(theta, q[i % 4])
else:
rx(theta, q[i % 4])
Expand All @@ -44,10 +44,10 @@ def cost(thetas: np.ndarray): # can pass 1D ndarray or list
# CHECK: %[[VAL_10:.*]] = cc.stdvec_data %[[VAL_0]] : (!cc.stdvec<f64>) -> !cc.ptr<!cc.array<f64 x ?>>
# CHECK: %[[VAL_11:.*]] = cc.compute_ptr %[[VAL_10]]{{\[}}%[[VAL_9]]] : (!cc.ptr<!cc.array<f64 x ?>>, i64) -> !cc.ptr<f64>
# CHECK: %[[VAL_12:.*]] = arith.constant 2.000000e+00 : f64
# CHECK: %[[VAL_13:.*]] = arith.fptosi %[[VAL_12]] : f64 to i64
# CHECK: %[[VAL_14:.*]] = arith.remui %[[VAL_9]], %[[VAL_13]] : i64
# CHECK: %[[VAL_15:.*]] = arith.constant 0 : i64
# CHECK: %[[VAL_16:.*]] = arith.cmpi ne, %[[VAL_14]], %[[VAL_15]] : i64
# CHECK: %[[VAL_13:.*]] = cc.cast signed %[[VAL_9]] : (i64) -> f64
# CHECK: %[[VAL_14:.*]] = arith.remf %[[VAL_13]], %[[VAL_12]] : f64
# CHECK: %[[VAL_15:.*]] = arith.constant 0.000000e+00 : f64
# CHECK: %[[VAL_16:.*]] = arith.cmpf une, %[[VAL_14]], %[[VAL_15]] : f64
# CHECK: cc.if(%[[VAL_16]]) {
# CHECK: %[[VAL_17:.*]] = cc.load %[[VAL_11]] : !cc.ptr<f64>
# CHECK: %[[VAL_18:.*]] = arith.constant 4 : i64
Expand All @@ -72,7 +72,8 @@ def cost(thetas: np.ndarray): # can pass 1D ndarray or list

# CHECK-LABEL: func.func @__nvqpp__mlirgen__cost(
# CHECK-SAME: %[[VAL_0:.*]]: !cc.stdvec<f64>) attributes {"cudaq-entrypoint", "cudaq-kernel"} {
# CHECK-DAG: %[[VAL_1:.*]] = arith.constant 2 : i64
# CHECK-DAG: %[[VAL:.*]] = arith.constant 0.000000e+00 : f64
# CHECK-DAG: %[[VAL_1:.*]] = arith.constant 2.000000e+00 : f64
# CHECK-DAG: %[[VAL_2:.*]] = arith.constant 1 : i64
# CHECK-DAG: %[[VAL_3:.*]] = arith.constant 0 : i64
# CHECK-DAG: %[[VAL_4:.*]] = arith.constant 4 : i64
Expand All @@ -85,24 +86,25 @@ def cost(thetas: np.ndarray): # can pass 1D ndarray or list
# CHECK: ^bb0(%[[VAL_10:.*]]: i64):
# CHECK: %[[VAL_11:.*]] = cc.stdvec_data %[[VAL_0]] : (!cc.stdvec<f64>) -> !cc.ptr<!cc.array<f64 x ?>>
# CHECK: %[[VAL_12:.*]] = cc.compute_ptr %[[VAL_11]]{{\[}}%[[VAL_10]]] : (!cc.ptr<!cc.array<f64 x ?>>, i64) -> !cc.ptr<f64>
# CHECK: %[[VAL_13:.*]] = arith.remui %[[VAL_10]], %[[VAL_1]] : i64
# CHECK: %[[VAL_14:.*]] = arith.cmpi ne, %[[VAL_13]], %[[VAL_3]] : i64
# CHECK: cc.if(%[[VAL_14]]) {
# CHECK: %[[VAL_15:.*]] = cc.load %[[VAL_12]] : !cc.ptr<f64>
# CHECK: %[[VAL_16:.*]] = arith.remui %[[VAL_10]], %[[VAL_4]] : i64
# CHECK: %[[VAL_17:.*]] = quake.extract_ref %[[VAL_5]]{{\[}}%[[VAL_16]]] : (!quake.veq<4>, i64) -> !quake.ref
# CHECK: quake.ry (%[[VAL_15]]) %[[VAL_17]] : (f64, !quake.ref) -> ()
# CHECK: %[[VAL_13:.*]] = cc.cast signed %[[VAL_10]] : (i64) -> f64
# CHECK: %[[VAL_14:.*]] = arith.remf %[[VAL_13]], %[[VAL_1]] : f64
# CHECK: %[[VAL_15:.*]] = arith.cmpf une, %[[VAL_14]], %[[VAL]] : f64
# CHECK: cc.if(%[[VAL_15]]) {
# CHECK: %[[VAL_16:.*]] = cc.load %[[VAL_12]] : !cc.ptr<f64>
# CHECK: %[[VAL_17:.*]] = arith.remui %[[VAL_10]], %[[VAL_4]] : i64
# CHECK: %[[VAL_18:.*]] = quake.extract_ref %[[VAL_5]]{{\[}}%[[VAL_17]]] : (!quake.veq<4>, i64) -> !quake.ref
# CHECK: quake.ry (%[[VAL_16]]) %[[VAL_18]] : (f64, !quake.ref) -> ()
# CHECK: } else {
# CHECK: %[[VAL_18:.*]] = cc.load %[[VAL_12]] : !cc.ptr<f64>
# CHECK: %[[VAL_19:.*]] = arith.remui %[[VAL_10]], %[[VAL_4]] : i64
# CHECK: %[[VAL_20:.*]] = quake.extract_ref %[[VAL_5]]{{\[}}%[[VAL_19]]] : (!quake.veq<4>, i64) -> !quake.ref
# CHECK: quake.rx (%[[VAL_18]]) %[[VAL_20]] : (f64, !quake.ref) -> ()
# CHECK: %[[VAL_19:.*]] = cc.load %[[VAL_12]] : !cc.ptr<f64>
# CHECK: %[[VAL_20:.*]] = arith.remui %[[VAL_10]], %[[VAL_4]] : i64
# CHECK: %[[VAL_21:.*]] = quake.extract_ref %[[VAL_5]]{{\[}}%[[VAL_20]]] : (!quake.veq<4>, i64) -> !quake.ref
# CHECK: quake.rx (%[[VAL_19]]) %[[VAL_21]] : (f64, !quake.ref) -> ()
# CHECK: }
# CHECK: cc.continue %[[VAL_10]] : i64
# CHECK: } step {
# CHECK: ^bb0(%[[VAL_21:.*]]: i64):
# CHECK: %[[VAL_22:.*]] = arith.addi %[[VAL_21]], %[[VAL_2]] : i64
# CHECK: cc.continue %[[VAL_22]] : i64
# CHECK: ^bb0(%[[VAL_22:.*]]: i64):
# CHECK: %[[VAL_23:.*]] = arith.addi %[[VAL_22]], %[[VAL_2]] : i64
# CHECK: cc.continue %[[VAL_23]] : i64
# CHECK: } {invariant}
# CHECK: return
# CHECK: }
# CHECK: }
Loading