Skip to content

Commit

Permalink
adding some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weinbe58 committed Feb 22, 2025
1 parent a7ab3c1 commit d109531
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/bloqade/pyqrack/qasm2/uop.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def csx(self, interp: interp.Interpreter, frame: interp.Frame, stmt: uop.CSX):

@interp.impl(uop.Swap)
def swap(self, interp: interp.Interpreter, frame: interp.Frame, stmt: uop.Swap):
qarg1: SimQubit["QrackSimulator"] = frame.get(stmt.qarg)
qarg2: SimQubit["QrackSimulator"] = frame.get(stmt.ctrl)
qarg1: SimQubit["QrackSimulator"] = frame.get(stmt.ctrl)
qarg2: SimQubit["QrackSimulator"] = frame.get(stmt.qarg)
if qarg1.is_active() and qarg2.is_active():
qarg1.sim_reg.swap(qarg1.addr, qarg2.addr)
return ()
Expand Down
15 changes: 15 additions & 0 deletions test/runtime/test_qrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@ def program():
qasm2.x(q[1])
qasm2.y(q[2])
qasm2.z(q[0])
qasm2.barrier((q[0], q[1]))
qasm2.id(q[1])
qasm2.s(q[1])
qasm2.sdg(q[2])
qasm2.t(q[0])
qasm2.tdg(q[1])
qasm2.sx(q[2])
qasm2.sxdg(q[0])

sim_reg = run_mock(3, program)
sim_reg.assert_has_calls(
Expand All @@ -38,6 +42,8 @@ def program():
call.adjs(2),
call.t(0),
call.adjt(1),
call.u(2, math.pi / 2, math.pi / 2, -math.pi / 2),
call.u(0, math.pi * (1.5), math.pi / 2, math.pi / 2),
]
)

Expand Down Expand Up @@ -90,6 +96,8 @@ def program():
qasm2.cy(q[1], q[2])
qasm2.cz(q[2], q[0])
qasm2.ch(q[0], q[1])
qasm2.csx(q[1], q[2])
qasm2.swap(q[0], q[2])

sim_reg = run_mock(3, program)
sim_reg.assert_has_calls(
Expand All @@ -98,6 +106,8 @@ def program():
call.mcy([1], 2),
call.mcz([2], 0),
call.mch([0], 1),
call.mcu([1], 2, math.pi / 2, math.pi / 2, -math.pi / 2),
call.swap(0, 2),
]
)

Expand All @@ -111,6 +121,8 @@ def program():
qasm2.cu1(q[1], q[2], 0.5)
qasm2.cu3(q[2], q[0], 0.5, 0.2, 0.1)
qasm2.ccx(q[0], q[1], q[2])
qasm2.cu(q[0], q[1], 0.5, 0.2, 0.1, 0.8)
qasm2.cswap(q[0], q[1], q[2])

sim_reg = run_mock(3, program)
sim_reg.assert_has_calls(
Expand All @@ -119,5 +131,8 @@ def program():
call.mcu([1], 2, 0, 0, 0.5),
call.mcu([2], 0, 0.5, 0.2, 0.1),
call.mcx([0, 1], 2),
call.u(0, 0.0, 0.0, 0.8),
call.mcu([0], 1, 0.5, 0.2, 0.1),
call.cswap([0], 1, 2),
]
)

0 comments on commit d109531

Please sign in to comment.