@@ -173,28 +173,6 @@ def rewrite_sx(self, node: uop.SX) -> abc.RewriteResult:
173173 cirq .XPowGate (exponent = 0.5 ).on (self .cached_qubits [0 ]), node
174174 )
175175
176- def rewrite_ccx (self , node : uop .CCX ) -> abc .RewriteResult :
177- # from https://algassert.com/quirk#circuit={%22cols%22:[[%22QFT3%22],[%22inputA3%22,1,1,%22+=A3%22],[1,1,1,%22%E2%80%A2%22,%22%E2%80%A2%22,%22X%22],[1,1,1,%22%E2%80%A6%22,%22%E2%80%A6%22,%22%E2%80%A6%22],[1,1,1,1,1,%22H%22],[1,1,1,1,%22%E2%80%A2%22,%22X%22],[1,1,1,1,1,%22Z^-%C2%BC%22],[1,1,1,%22%E2%80%A2%22,1,%22X%22],[1,1,1,1,1,%22Z^%C2%BC%22],[1,1,1,1,%22%E2%80%A2%22,%22X%22],[1,1,1,1,%22Z^%C2%BC%22,%22Z^-%C2%BC%22],[1,1,1,%22%E2%80%A2%22,1,%22X%22],[1,1,1,%22%E2%80%A2%22,%22X%22],[1,1,1,%22Z^%C2%BC%22,%22Z^-%C2%BC%22,%22Z^%C2%BC%22],[1,1,1,%22%E2%80%A2%22,%22X%22],[1,1,1,1,1,%22H%22]]}
178-
179- uop .H (node .qarg ).insert_before (node )
180- uop .CX (ctrl = node .ctrl1 , qarg = node .qarg ).insert_before (node )
181- uop .Tdag (node .qarg ).insert_before (node )
182- uop .CX (ctrl = node .ctrl2 , qarg = node .qarg ).insert_before (node )
183- uop .T (node .qarg ).insert_before (node )
184- uop .CX (ctrl = node .ctrl1 , qarg = node .qarg ).insert_before (node )
185- uop .Tdag (node .qarg ).insert_before (node )
186- uop .T (node .ctrl1 ).insert_before (node )
187- uop .CX (ctrl = node .ctrl2 , qarg = node .qarg ).insert_before (node )
188- uop .CX (ctrl = node .ctrl2 , qarg = node .ctrl1 ).insert_before (node )
189- uop .T (node .ctrl2 ).insert_before (node )
190- uop .Tdag (node .ctrl1 ).insert_before (node )
191- uop .T (node .qarg ).insert_before (node )
192- uop .CX (ctrl = node .ctrl2 , qarg = node .ctrl1 ).insert_before (node )
193- uop .H (node .qarg ).insert_before (node )
194- node .delete () # delete the original CCX gate
195-
196- return abc .RewriteResult (has_done_something = True )
197-
198176 def rewrite_sxdg (self , node : uop .SXdag ) -> abc .RewriteResult :
199177 return self ._rewrite_1q_gates (
200178 cirq .XPowGate (exponent = - 0.5 ).on (self .cached_qubits [0 ]), node
@@ -416,12 +394,9 @@ def _rewrite_1q_gates(
416394 new_gate_stmts = self ._generate_1q_gate_stmts (cirq_gate , node .qarg )
417395 return self ._rewrite_gate_stmts (new_gate_stmts , node )
418396
419- def _generate_multi_ctrl_gate_stmts (
397+ def _generate_2q_ctrl_gate_stmts (
420398 self , cirq_gate : cirq .Operation , qubits_ssa : List [ir .SSAValue ]
421399 ) -> list [ir .Statement ]:
422- qubit_to_ssa_map = {
423- q : ssa for q , ssa in zip (self .cached_qubits [: len (qubits_ssa )], qubits_ssa )
424- }
425400 target_gates = self .gateset .decompose_to_target_gateset (cirq_gate , 0 )
426401 new_stmts = []
427402 for new_gate in target_gates :
@@ -437,39 +412,26 @@ def _generate_multi_ctrl_gate_stmts(
437412 new_stmts .append (phi2_stmt )
438413 new_stmts .append (
439414 uop .UGate (
440- qarg = qubit_to_ssa_map [new_gate .qubits [0 ]],
415+ qarg = qubits_ssa [new_gate .qubits [0 ]. x ],
441416 theta = phi0_stmt .result ,
442417 phi = phi1_stmt .result ,
443418 lam = phi2_stmt .result ,
444419 )
445420 )
446421 else :
447422 # 2q
448- new_stmts .append (
449- uop .CZ (
450- ctrl = qubit_to_ssa_map [new_gate .qubits [0 ]],
451- qarg = qubit_to_ssa_map [new_gate .qubits [1 ]],
452- )
453- )
423+ new_stmts .append (uop .CZ (ctrl = qubits_ssa [0 ], qarg = qubits_ssa [1 ]))
454424
455425 return new_stmts
456426
457427 def _rewrite_2q_ctrl_gates (
458428 self , cirq_gate : cirq .Operation , node : uop .TwoQubitCtrlGate
459429 ) -> abc .RewriteResult :
460- new_gate_stmts = self ._generate_multi_ctrl_gate_stmts (
430+ new_gate_stmts = self ._generate_2q_ctrl_gate_stmts (
461431 cirq_gate , [node .ctrl , node .qarg ]
462432 )
463433 return self ._rewrite_gate_stmts (new_gate_stmts , node )
464434
465- def _rewrite_3q_ctrl_gates (
466- self , cirq_gate : cirq .Operation , node : uop .CCX
467- ) -> abc .RewriteResult :
468- new_gate_stmts = self ._generate_multi_ctrl_gate_stmts (
469- cirq_gate , [node .ctrl1 , node .ctrl2 , node .qarg ]
470- )
471- return self ._rewrite_gate_stmts (new_gate_stmts , node )
472-
473435 def _rewrite_gate_stmts (
474436 self , new_gate_stmts : list [ir .Statement ], node : ir .Statement
475437 ):
0 commit comments