Skip to content
Open
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
112 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
a4c1470
draft manually pushing and poping stack frames before making this cle…
bettinaheim Oct 15, 2025
4fbb505
to be reverted/revised
bettinaheim Oct 15, 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
1301201
Merge branch 'main' into python-bridge
bettinaheim Oct 21, 2025
e58fc94
Merge branch 'python-modulo' into python-bridge
bettinaheim Oct 21, 2025
a64cb69
clean up before making the frames automatic
bettinaheim Oct 21, 2025
c11cf08
overlooked a failing test
bettinaheim Oct 21, 2025
87e587b
eliminating the attribute sometimes producing two values
bettinaheim Oct 21, 2025
86f785d
removing the manual pushing and popping of frames
bettinaheim Oct 22, 2025
fe3a626
should be an ok structure for the stack
bettinaheim Oct 22, 2025
5961a75
making some decent progress towards making sure we fail when somethin…
bettinaheim Oct 22, 2025
93b975c
validated the gate update
bettinaheim Oct 22, 2025
29ec9d9
just some comments
bettinaheim Oct 22, 2025
486b227
general helper to group values
bettinaheim Oct 23, 2025
01fe16f
minor things
bettinaheim Oct 23, 2025
a9f662c
cleaning up loops
bettinaheim Oct 24, 2025
4643b51
eliminating code duplication in visit_for
bettinaheim Oct 24, 2025
f107ca5
clean up
bettinaheim Oct 27, 2025
f37f20a
more clean up
bettinaheim Oct 27, 2025
55e6177
wip to clean up the handling of reference types
bettinaheim Oct 29, 2025
9b78a5f
more wip
bettinaheim Oct 29, 2025
be3884b
some progress with clean up
bettinaheim Oct 30, 2025
4c5c8ba
minor thing
bettinaheim Oct 30, 2025
04aea9c
first complete outline
bettinaheim Oct 31, 2025
05d1892
existing python kernel tests pass
bettinaheim Oct 31, 2025
59c6978
whitespace fixes
bettinaheim Oct 31, 2025
da53fcf
clean up
bettinaheim Oct 31, 2025
c58e77a
creating list copies when needed
bettinaheim Oct 31, 2025
ffa3697
some clean up for the assignment tests
bettinaheim Oct 31, 2025
c9f2d8d
more assignment tests
bettinaheim Nov 3, 2025
ae0d14b
confirmed value behavior
bettinaheim Nov 3, 2025
74363e9
added an error when we have lists in structs
bettinaheim Nov 4, 2025
dd4ac73
that should do for the assignment tests
bettinaheim Nov 4, 2025
2f929cd
updating most mlir tests
bettinaheim Nov 4, 2025
3a81c6e
python tests are ok, but we have some gaps - commit before closing them
bettinaheim Nov 5, 2025
f625eb2
close to the final version
bettinaheim Nov 6, 2025
7041ab6
clean up
bettinaheim Nov 6, 2025
cf3a0e9
feeling good about assignments now
bettinaheim Nov 6, 2025
cf041b3
python kernel and mlir tests pass
bettinaheim Nov 7, 2025
d665ffa
updates from main
bettinaheim Nov 7, 2025
024d10b
test updates from merge
bettinaheim Nov 7, 2025
cb0e259
fixing list[bool] arg issue
bettinaheim Nov 10, 2025
2a0bb39
other bridge fixes after merge
bettinaheim Nov 10, 2025
64c6d60
python kernel and mlir tests pass
bettinaheim Nov 10, 2025
5a82186
Merge branch 'main' into python-bridge
bettinaheim Nov 11, 2025
02e5fcb
last clean up from merge
bettinaheim Nov 12, 2025
bdcb5f7
removing the now unnecessary loads throughout the bridge
bettinaheim Nov 13, 2025
6dfbdd6
some formatting
bettinaheim Nov 13, 2025
692a668
addressing some review comments
bettinaheim Nov 18, 2025
b873ec0
minor things
bettinaheim Nov 18, 2025
15cbd2e
whitespace
bettinaheim Nov 19, 2025
cf0aebb
undoing change left over from merge
bettinaheim Nov 19, 2025
5156f98
Merge branch 'main' into python-bridge
bettinaheim Nov 19, 2025
c9d37e9
formatting
bettinaheim Nov 19, 2025
eacfe78
spelling
bettinaheim Nov 19, 2025
53b1e33
formatting
bettinaheim Nov 19, 2025
639ebf2
minor thing
bettinaheim Nov 19, 2025
eeea99a
a couple more test updates
bettinaheim Nov 19, 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
1,138 changes: 510 additions & 628 deletions python/cudaq/kernel/ast_bridge.py

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions python/extension/CUDAQuantumExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ PYBIND11_MODULE(_quakeDialects, m) {
cudaqRuntime.def("isTerminator", [](MlirOperation op) {
return unwrap(op)->hasTrait<mlir::OpTrait::IsTerminator>();
});
// TODO: This is needed because with LLVM 16, it seems that the MLIR
// Python bindings do not expose cc::ArrayType::getSize to Python.
// This should be replaced by the automatically generated binding
// once it is available.
cudaqRuntime.def("ArrayTypeGetSize", &cudaq::cc::ArrayType::getSize);

auto ahsSubmodule = cudaqRuntime.def_submodule("ahs");
cudaq::bindAnalogHamiltonian(ahsSubmodule);
Expand Down
124 changes: 122 additions & 2 deletions python/tests/kernel/test_kernel_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,124 @@ def kernel6():
assert len(counts) == 1
assert '0101' in counts

@cudaq.kernel
def kernel7():
qubits = cudaq.qvector(5)
r = [i for i in range(2, 5)]
for i in r:
x(qubits[i])

counts = cudaq.sample(kernel7)
assert len(counts) == 1
assert '00111' in counts

@cudaq.kernel
def kernel8():
qubits = cudaq.qvector(5)
r = [i for i in range(2, 6, 2)]
for i in r:
x(qubits[i])

counts = cudaq.sample(kernel8)
assert len(counts) == 1
assert '00101' in counts

@cudaq.kernel
def kernel9():
qubits = cudaq.qvector(5)
r = [i for i in range(6, 2, 2)]
for i in r:
x(qubits[i])

counts = cudaq.sample(kernel9)
assert len(counts) == 1
assert '00000' in counts

@cudaq.kernel
def kernel10():
qubits = cudaq.qvector(5)
r = [i for i in range(3, 0, -2)]
for i in r:
x(qubits[i])

counts = cudaq.sample(kernel10)
assert len(counts) == 1
assert '01010' in counts

@cudaq.kernel
def kernel11():
qubits = cudaq.qvector(5)
r = [i for i in range(-5, -2, -2)]
for i in r:
x(qubits[i])

counts = cudaq.sample(kernel11)
assert len(counts) == 1
assert '00000' in counts

@cudaq.kernel
def kernel12():
qubits = cudaq.qvector(5)
r = [i for i in range(-1, -5, -2)]
for i in r:
x(qubits[-i])

counts = cudaq.sample(kernel12)
assert len(counts) == 1
assert '01010' in counts

@cudaq.kernel
def kernel13():
qubits = cudaq.qvector(5)
r = [i for i in range(1, -4, -1)]
for i in r:
if i < 0:
x(qubits[-i])
else:
x(qubits[i])

counts = cudaq.sample(kernel13)
assert len(counts) == 1
assert '10110' in counts

@cudaq.kernel
def kernel14():
qubits = cudaq.qvector(5)
r = [i for i in range(-2, 6, 2)]
for i in r:
if i < 0:
x(qubits[-i])
else:
x(qubits[i])

counts = cudaq.sample(kernel14)
assert len(counts) == 1
assert '10001' in counts

@cudaq.kernel
def kernel15():
qubits = cudaq.qvector(5)
r = [i for i in range(1, 4, 0)]
for i in r:
x(qubits[i])

with pytest.raises(RuntimeError) as e:
cudaq.sample(kernel15)
assert "range step value must be non-zero" in str(e.value)
assert "offending source -> range(1, 4, 0)" in str(e.value)

@cudaq.kernel
def kernel16(v : int):
qubits = cudaq.qvector(5)
r = [i for i in range(1, 4, v)]
for i in r:
x(qubits[i])

with pytest.raises(RuntimeError) as e:
cudaq.sample(kernel16)
assert "range step value must be a constant" in str(e.value)
assert "offending source -> range(1, 4, v)" in str(e.value)


def test_array_value_assignment():

Expand Down Expand Up @@ -1558,7 +1676,8 @@ def test_kernel():

with pytest.raises(RuntimeError) as e:
test_kernel.compile()
assert 'invalid assignment detected.' in repr(e)
assert 'no valid value was created' in repr(e)
assert '(offending source -> state_reg = cudaq.qubit)' in repr(e)


def test_cast_error_1451():
Expand Down Expand Up @@ -2151,8 +2270,9 @@ def less_arguments():

with pytest.raises(RuntimeError) as error:
print(less_arguments)
assert 'invalid number of arguments (1) passed to rx (requires at least 2 arguments)' in repr(
assert 'missing argument for target operand' in repr(
error)
assert '(offending source -> rx(3.14))' in repr(error)

@cudaq.kernel
def wrong_arguments():
Expand Down
4 changes: 2 additions & 2 deletions python/tests/kernel/test_run_async_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def simple_dataclass_int_bool_error() -> MyClass:

with pytest.raises(RuntimeError) as e:
cudaq.run_async(simple_dataclass_int_bool_error, shots_count=2).get()
assert 'invalid number of arguments passed in call to MyClass (0 vs required 2)' in repr(
assert 'invalid number of arguments' in repr(
e)

@cudaq.kernel
Expand All @@ -752,7 +752,7 @@ def simple_dataclass_int_bool_error() -> MyClass:

with pytest.raises(RuntimeError) as e:
cudaq.run_async(simple_dataclass_int_bool_error, shots_count=2).get()
assert 'invalid number of arguments passed in call to MyClass (0 vs required 2)' in repr(
assert 'invalid number of arguments' in repr(
e)


Expand Down
2 changes: 1 addition & 1 deletion python/tests/kernel/test_run_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def incrementer(i: int) -> int:
def kernel_with_list_arg(arg: list[int]) -> list[int]:
result = arg
for i in result:
incrementer(i)
incrementer(i) # FIXME: THIS IS NOT HOW PYTHON SHOULD BEHAVE...!
return result

@cudaq.kernel
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: }
12 changes: 6 additions & 6 deletions python/tests/mlir/ast_list_comprehension.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ def kernel3() -> float:


# CHECK-LABEL: func.func @__nvqpp__mlirgen__kernel1() -> i1 attributes {"cudaq-entrypoint", "cudaq-kernel"}
# CHECK: %[[VAL_0:.*]] = arith.constant 1 : i64
# CHECK: %[[VAL_1:.*]] = arith.constant true
# CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1 : i64
# CHECK-DAG: %[[VAL_1:.*]] = arith.constant true
# CHECK: %[[VAL_2:.*]] = cc.alloca !cc.array<!cc.stdvec<i1> x 5>
# CHECK: %[[VAL_3:.*]] = cc.alloca !cc.array<i1 x 1>
# CHECK: %[[VAL_4:.*]] = cc.cast %[[VAL_3]] : (!cc.ptr<!cc.array<i1 x 1>>) -> !cc.ptr<!cc.array<i1 x ?>>
Expand All @@ -283,8 +283,8 @@ def kernel3() -> float:
# CHECK: cc.store %[[VAL_6]], %[[VAL_7]] : !cc.ptr<!cc.stdvec<i1>>

# CHECK-LABEL: func.func @__nvqpp__mlirgen__kernel2() -> f64 attributes {"cudaq-entrypoint", "cudaq-kernel"}
# CHECK: %[[VAL_0:.*]] = arith.constant 1 : i64
# CHECK: %[[VAL_1:.*]] = arith.constant 1.000000e+00 : f64
# CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1 : i64
# CHECK-DAG: %[[VAL_1:.*]] = arith.constant 1.000000e+00 : f64
# CHECK: %[[VAL_2:.*]] = cc.alloca !cc.array<!cc.stdvec<f64> x 5>
# CHECK: %[[VAL_3:.*]] = cc.alloca !cc.array<f64 x 1>
# CHECK: %[[VAL_4:.*]] = cc.cast %[[VAL_3]] : (!cc.ptr<!cc.array<f64 x 1>>) -> !cc.ptr<!cc.array<f64 x ?>>
Expand All @@ -295,8 +295,8 @@ def kernel3() -> float:
# CHECK: cc.store %[[VAL_6]], %[[VAL_7]] : !cc.ptr<!cc.stdvec<f64>>

# CHECK-LABEL: func.func @__nvqpp__mlirgen__kernel3() -> f64 attributes {"cudaq-entrypoint", "cudaq-kernel"}
# CHECK: %[[VAL_0:.*]] = arith.constant 1 : i64
# CHECK: %[[VAL_1:.*]] = complex.constant [0.000000e+00, 1.000000e+00] : complex<f64>
# CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1 : i64
# CHECK-DAG: %[[VAL_1:.*]] = complex.constant [0.000000e+00, 1.000000e+00] : complex<f64>
# CHECK: %[[VAL_2:.*]] = cc.alloca !cc.array<!cc.stdvec<complex<f64>> x 5>
# CHECK: %[[VAL_3:.*]] = cc.alloca !cc.array<complex<f64> x 1>
# CHECK: %[[VAL_4:.*]] = cc.cast %[[VAL_3]] : (!cc.ptr<!cc.array<complex<f64> x 1>>) -> !cc.ptr<!cc.array<complex<f64> x ?>>
Expand Down
26 changes: 19 additions & 7 deletions python/tests/mlir/ast_while_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def cost():
ry(np.pi, q[i])
i -= 1

counts = cudaq.sample(cost)
assert len(counts) == 1
assert '011111' in counts
print(cost)
# cost()


# CHECK-LABEL: func.func @__nvqpp__mlirgen__cost() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
Expand Down Expand Up @@ -62,12 +64,16 @@ def cost():
ry(np.pi, q[i])
i -= 1

counts = cudaq.sample(cost)
assert len(counts) == 1
assert '000111' in counts
print(cost)


# CHECK-LABEL: func.func @__nvqpp__mlirgen__cost() attributes {"cudaq-entrypoint", "cudaq-kernel"} {
# CHECK-DAG: %[[VAL_0:.*]] = arith.constant 1 : i64
# CHECK-DAG: %[[VAL_1:.*]] = arith.constant 3.1415926535897931 : f64
# CHECK-DAG: %[[VAL_10:.*]] = arith.constant 2 : i64
# CHECK-DAG: %[[VAL_2:.*]] = arith.constant 14 : i64
# CHECK-DAG: %[[VAL_3:.*]] = arith.constant false
# CHECK-DAG: %[[VAL_4:.*]] = arith.constant 0 : i64
Expand All @@ -77,16 +83,22 @@ def cost():
# CHECK: cc.store %[[VAL_5]], %[[VAL_7]] : !cc.ptr<i64>
# CHECK: cc.loop while {
# CHECK: %[[VAL_8:.*]] = cc.load %[[VAL_7]] : !cc.ptr<i64>
# CHECK: %[[VAL_9:.*]] = arith.cmpi sgt, %[[VAL_8]], %[[VAL_4]] : i64
# CHECK: %[[VAL_10:.*]] = arith.cmpi eq, %[[VAL_9]], %[[VAL_3]] : i1
# CHECK: %[[VAL_11:.*]] = cc.if(%[[VAL_10]]) -> i1 {
# CHECK: %[[VAL_9:.*]] = arith.cmpi sle, %[[VAL_8]], %[[VAL_4]] : i64
# CHECK: %[[VAL_11:.*]] = cc.if(%[[VAL_9]]) -> i1 {
# CHECK: cc.continue %[[VAL_3]] : i1
# CHECK: } else {
# CHECK: %[[VAL_12:.*]] = cc.load %[[VAL_7]] : !cc.ptr<i64>
# CHECK: %[[VAL_13:.*]] = arith.cmpi slt, %[[VAL_12]], %[[VAL_2]] : i64
# CHECK: cc.continue %[[VAL_13]] : i1
# CHECK: %[[VAL_13:.*]] = arith.cmpi sge, %[[VAL_12]], %[[VAL_2]] : i64
# CHECK: %[[VAL_20:.*]] = cc.if(%[[VAL_13]]) -> i1 {
# CHECK: cc.continue %[[VAL_3]] : i1
# CHECK: } else {
# CHECK: %[[VAL_21:.*]] = cc.load %[[VAL_7]] : !cc.ptr<i64>
# CHECK: %[[VAL_22:.*]] = arith.cmpi ne, %[[VAL_21]], %[[VAL_10]] : i64
# CHECK: cc.continue %[[VAL_22]] : i1
# CHECK: }
# CHECK: cc.continue %[[VAL_20:.*]]
# CHECK: }
# CHECK: cc.condition %[[VAL_14:.*]]
# CHECK: cc.condition %[[VAL_11:.*]]
# CHECK: } do {
# CHECK: %[[VAL_15:.*]] = cc.load %[[VAL_7]] : !cc.ptr<i64>
# CHECK: %[[VAL_16:.*]] = quake.extract_ref %[[VAL_6]]{{\[}}%[[VAL_15]]] : (!quake.veq<6>, i64) -> !quake.ref
Expand Down
5 changes: 2 additions & 3 deletions python/tests/mlir/bug_1875.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ def kernel_break():
# CHECK: %[[VAL_7:.*]] = quake.mz %[[VAL_3]] name "aux_2" : (!quake.ref) -> !quake.measure
# CHECK: %[[VAL_8:.*]] = quake.discriminate %[[VAL_7]] : (!quake.measure) -> i1
# CHECK: %[[VAL_9:.*]] = cc.cast unsigned %[[VAL_6]] : (i1) -> i64
# CHECK: %[[VAL_10:.*]] = arith.cmpi eq, %[[VAL_9]], %[[VAL_1]] : i64
# CHECK: %[[VAL_11:.*]] = arith.cmpi eq, %[[VAL_10]], %[[VAL_0]] : i1
# CHECK: %[[VAL_12:.*]] = cc.if(%[[VAL_11]]) -> i1 {
# CHECK: %[[VAL_10:.*]] = arith.cmpi ne, %[[VAL_9]], %[[VAL_1]] : i64
# CHECK: %[[VAL_12:.*]] = cc.if(%[[VAL_10]]) -> i1 {
# CHECK: cc.continue %[[VAL_0]] : i1
# CHECK: } else {
# CHECK: %[[VAL_13:.*]] = cc.cast unsigned %[[VAL_8]] : (i1) -> i64
Expand Down
Loading
Loading