Test that we can build a kernel expression with a for loop.
()
| 489 | |
| 490 | |
| 491 | def test_for_loop(): |
| 492 | """ |
| 493 | Test that we can build a kernel expression with a for loop. |
| 494 | """ |
| 495 | circuit, inSize = cudaq.make_kernel(int) |
| 496 | qubits = circuit.qalloc(inSize) |
| 497 | circuit.h(qubits[0]) |
| 498 | # can pass concrete integers for both |
| 499 | circuit.for_loop(0, inSize - 1, |
| 500 | lambda index: circuit.cx(qubits[index], qubits[index + 1])) |
| 501 | print(circuit) |
| 502 | counts = cudaq.sample(circuit, 5) |
| 503 | assert len(counts) == 2 |
| 504 | assert '0' * 5 in counts |
| 505 | assert '1' * 5 in counts |
| 506 | |
| 507 | counts.dump() |
| 508 | |
| 509 | |
| 510 | def test_sample_n(): |