MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / test_for_loop

Function test_for_loop

python/tests/builder/test_sample.py:491–507  ·  view source on GitHub ↗

Test that we can build a kernel expression with a for loop.

()

Source from the content-addressed store, hash-verified

489
490
491def 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
510def test_sample_n():

Callers

nothing calls this directly

Calls 5

printFunction · 0.50
qallocMethod · 0.45
for_loopMethod · 0.45
sampleMethod · 0.45
dumpMethod · 0.45

Tested by

no test coverage detected