Tests QuakeValue used in as loop indices
()
| 110 | |
| 111 | |
| 112 | def test_QuakeValueInForLoop(): |
| 113 | """Tests QuakeValue used in as loop indices""" |
| 114 | kernel, start, stop = cudaq.make_kernel(int, int) |
| 115 | qubits = kernel.qalloc(stop) |
| 116 | kernel.h(qubits[0]) |
| 117 | |
| 118 | def foo(index: int): |
| 119 | """A function that will be applied to `kernel` in a for loop.""" |
| 120 | kernel.x(qubits[index]) |
| 121 | |
| 122 | # `QuakeValue` as start index |
| 123 | kernel.for_loop(start, 1, foo) |
| 124 | kernel.for_loop(start, stop - 1, foo) |
| 125 | print(kernel) |
| 126 | |
| 127 | # Execute the kernel, passing along concrete values for the |
| 128 | # `start` and `stop` arguments. |
| 129 | counts = cudaq.sample(kernel, 0, 8) |
| 130 | print(counts) |