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

Function test_swap_2q

python/tests/builder/test_sample.py:439–458  ·  view source on GitHub ↗

Tests the simple case of swapping the states of two qubits.

()

Source from the content-addressed store, hash-verified

437
438
439def test_swap_2q():
440 """
441 Tests the simple case of swapping the states of two qubits.
442 """
443 kernel = cudaq.make_kernel()
444 # Allocate a register of size 2.
445 qreg = kernel.qalloc(2)
446 qubit_0 = qreg[0]
447 qubit_1 = qreg[1]
448 # Place qubit 0 in the 1-state.
449 kernel.x(qubit_0)
450 # Swap states with qubit 1.
451 kernel.swap(qubit_0, qubit_1)
452 # Check their states.
453 kernel.mz(qreg)
454
455 want_state = "01"
456 result = cudaq.sample(kernel)
457 assert (want_state in result)
458 assert (result[want_state] == 1000)
459
460
461def test_qubit_reset():

Callers

nothing calls this directly

Calls 5

qallocMethod · 0.45
xMethod · 0.45
swapMethod · 0.45
mzMethod · 0.45
sampleMethod · 0.45

Tested by

no test coverage detected