Tests the simple case of swapping the states of two qubits.
()
| 437 | |
| 438 | |
| 439 | def 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 | |
| 461 | def test_qubit_reset(): |