Test that we can broadcast the sample call over a number of argument sets
()
| 508 | |
| 509 | |
| 510 | def test_sample_n(): |
| 511 | """ |
| 512 | Test that we can broadcast the sample call over a number of argument sets |
| 513 | """ |
| 514 | circuit, inSize = cudaq.make_kernel(int) |
| 515 | qubits = circuit.qalloc(inSize) |
| 516 | circuit.h(qubits[0]) |
| 517 | # can pass concrete integers for both |
| 518 | circuit.for_loop(0, inSize - 1, |
| 519 | lambda index: circuit.cx(qubits[index], qubits[index + 1])) |
| 520 | # circuit.mz(qubits) |
| 521 | print(circuit) |
| 522 | |
| 523 | allCounts = cudaq.sample(circuit, [3, 4, 5, 6, 7]) |
| 524 | first0 = '000' |
| 525 | first1 = '111' |
| 526 | for c in allCounts: |
| 527 | print(c) |
| 528 | assert first0 in c and first1 in c |
| 529 | first0 += '0' |
| 530 | first1 += '1' |
| 531 | |
| 532 | testNpArray = np.random.randint(3, high=8, size=6) |
| 533 | print(testNpArray) |
| 534 | allCounts = cudaq.sample(circuit, testNpArray) |
| 535 | for i, c in enumerate(allCounts): |
| 536 | print(c) |
| 537 | assert '0' * testNpArray[i] in c and '1' * testNpArray[i] in c |
| 538 | |
| 539 | circuit, angles = cudaq.make_kernel(list) |
| 540 | q = circuit.qalloc(2) |
| 541 | circuit.rx(angles[0], q[0]) |
| 542 | circuit.ry(angles[1], q[0]) |
| 543 | circuit.cx(q[0], q[1]) |
| 544 | |
| 545 | runtimeAngles = np.array([[1.41075134, 1.16822118], [1.4269374, 1.61847813], |
| 546 | [2.67020804, |
| 547 | 2.05479927], [2.09230621, 1.11112451], |
| 548 | [1.57397959, 2.27463287], [1.38422446, 2.4457557], |
| 549 | [2.44441489, |
| 550 | 2.51129809], [1.98279822, 2.38289909], |
| 551 | [2.48570709, 2.27008174], [3.05499814, |
| 552 | 1.4933275]]) |
| 553 | print(runtimeAngles) |
| 554 | allCounts = cudaq.sample(circuit, runtimeAngles) |
| 555 | for i, c in enumerate(allCounts): |
| 556 | print(runtimeAngles[i, :], c) |
| 557 | assert len(c) == 2 |
| 558 | |
| 559 | |
| 560 | def test_index_out_of_range(): |