File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 22import textwrap
33
44import cirq
5+ import numpy as np
56import cirq .testing
67import cirq .contrib .qasm_import as qasm_import
78import cirq .circuits .qasm_output as qasm_output
89from pytest import mark
910from kirin .rewrite import walk
1011
1112from bloqade import qasm2
13+ from bloqade .pyqrack import DynamicMemorySimulator
1214from 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
You can’t perform that action at this time.
0 commit comments