| 1375 | |
| 1376 | |
| 1377 | def test_draw(): |
| 1378 | print() |
| 1379 | bar, q = cudaq.make_kernel(cudaq.qreg) |
| 1380 | bar.rx(np.e, q[0]) |
| 1381 | bar.ry(np.pi, q[1]) |
| 1382 | bar.rz(-np.pi, q[2]) # how to do adj in builder? |
| 1383 | |
| 1384 | zaz, q = cudaq.make_kernel(cudaq.qubit) |
| 1385 | zaz.sdg(q) |
| 1386 | |
| 1387 | kernel = cudaq.make_kernel() |
| 1388 | q = kernel.qalloc(4) |
| 1389 | |
| 1390 | kernel.h(q) |
| 1391 | # Broadcast |
| 1392 | kernel.cx(q[0], q[1]) |
| 1393 | kernel.cy([q[0], q[1]], q[2]) |
| 1394 | kernel.cy([q[2], q[0]], q[1]) |
| 1395 | kernel.cy([q[1], q[2]], q[0]) |
| 1396 | kernel.z(q[2]) |
| 1397 | |
| 1398 | kernel.r1(3.14159, q[0]) |
| 1399 | kernel.tdg(q[1]) |
| 1400 | kernel.s(q[2]) |
| 1401 | |
| 1402 | kernel.swap(q[0], q[2]) |
| 1403 | kernel.swap(q[1], q[2]) |
| 1404 | kernel.swap(q[0], q[1]) |
| 1405 | kernel.swap(q[0], q[2]) |
| 1406 | kernel.swap(q[1], q[2]) |
| 1407 | kernel.cswap(q[3], q[0], q[1]) |
| 1408 | kernel.cswap([q[0], q[3]], q[1], q[2]) |
| 1409 | kernel.cswap(q[1], q[0], q[3]) |
| 1410 | kernel.cswap([q[1], q[2]], q[0], q[3]) |
| 1411 | kernel.apply_call(bar, q) |
| 1412 | kernel.control(zaz, q[1], q[0]) |
| 1413 | kernel.adjoint(bar, q) |
| 1414 | |
| 1415 | circuit = cudaq.draw(kernel) |
| 1416 | print(circuit) |
| 1417 | expected_str = ''' ╭───╮ ╭───╮╭───────────╮ ╭───────╮» |
| 1418 | q0 : ┤ h ├──●────●────●──┤ y ├┤ r1(3.142) ├──────╳─────╳──╳─────╳──●─┤> ├» |
| 1419 | ├───┤╭─┴─╮ │ ╭─┴─╮╰─┬─╯╰──┬─────┬──╯ │ │ │ │ │ │ │» |
| 1420 | q1 : ┤ h ├┤ x ├──●──┤ y ├──●─────┤ tdg ├─────────┼──╳──╳──┼──╳──╳──╳─┤● ├» |
| 1421 | ├───┤╰───╯╭─┴─╮╰─┬─╯ │ ╰┬───┬╯ ╭───╮ │ │ │ │ │ │ │ swap │» |
| 1422 | q2 : ┤ h ├─────┤ y ├──●────●──────┤ z ├────┤ s ├─╳──╳─────╳──╳──┼──╳─│ │» |
| 1423 | ├───┤ ╰───╯ ╰───╯ ╰───╯ │ │ │ │» |
| 1424 | q3 : ┤ h ├──────────────────────────────────────────────────────●──●─┤> ├» |
| 1425 | ╰───╯ ╰───────╯» |
| 1426 | |
| 1427 | ################################################################################ |
| 1428 | |
| 1429 | ╭───────╮╭───────────╮ ╭─────╮ ╭────────────╮ |
| 1430 | ┤> ├┤ rx(2.718) ├────┤ sdg ├───┤ rx(-2.718) ├ |
| 1431 | │ │├───────────┤ ╰──┬──╯ ├────────────┤ |
| 1432 | ┤● ├┤ ry(3.142) ├───────●──────┤ ry(-3.142) ├ |
| 1433 | │ swap │├───────────┴╮╭───────────╮╰────────────╯ |
| 1434 | ┤● ├┤ rz(-3.142) ├┤ rz(3.142) ├────────────── |