Skip to content

Commit 9d4fbc4

Browse files
committed
adding test
1 parent 547e490 commit 9d4fbc4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/qasm2/test_native.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
import textwrap
33

44
import cirq
5+
import numpy as np
56
import cirq.testing
67
import cirq.contrib.qasm_import as qasm_import
78
import cirq.circuits.qasm_output as qasm_output
89
from pytest import mark
910
from kirin.rewrite import walk
1011

1112
from bloqade import qasm2
13+
from bloqade.pyqrack import DynamicMemorySimulator
1214
from bloqade.qasm2.rewrite.native_gates import (
1315
RydbergGateSetRewriteRule,
1416
one_qubit_gate_to_u3_angles,
@@ -153,3 +155,25 @@ def kernel():
153155

154156
# simple-stupid test to see if the rewrite injected a bunch of new lines
155157
assert new_qasm2.count("\n") > prog.count("\n")
158+
159+
160+
def test_ccx_rewrite():
161+
162+
@qasm2.extended
163+
def main():
164+
q = qasm2.qreg(3)
165+
qasm2.ccx(q[0], q[1], q[2])
166+
167+
return q
168+
169+
main2 = main.similar()
170+
171+
walk.Walk(RydbergGateSetRewriteRule(main.dialects)).rewrite(main.code)
172+
173+
sim = DynamicMemorySimulator()
174+
175+
state = sim.state_vector(main)
176+
state2 = sim.state_vector(main2)
177+
assert (
178+
np.abs(np.vdot(state, state2)) - 1 < 1e-6
179+
) # Should be close to 1 if the states are equal

0 commit comments

Comments
 (0)