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

Function test_QuakeValueInForLoop

python/tests/builder/test_quake_value.py:112–130  ·  view source on GitHub ↗

Tests QuakeValue used in as loop indices

()

Source from the content-addressed store, hash-verified

110
111
112def 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)

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected