@@ -498,6 +498,41 @@ def test_euler_decomposition_zsx_2(self):
498
498
result = passmanager .run (circuit )
499
499
self .assertEqual (circuit , result , f"Circuit:\n { circuit } \n Result:\n { result } " )
500
500
501
+ def test_optimize_run_of_u_to_single_u_on_target_no_error (self ):
502
+ """U(pi/3, 0, 0) * U(pi/3, 0, 0) * U(pi/3, 0, 0) -> U(pi, 0, 0). See #9701."""
503
+ qr = QuantumRegister (1 , "qr" )
504
+ circuit = QuantumCircuit (qr )
505
+ for _ in range (3 ):
506
+ circuit .append (UGate (np .pi / 3 , 0.0 , 0.0 ), [qr [0 ]])
507
+
508
+ expected = QuantumCircuit (qr )
509
+ expected .append (UGate (np .pi , 0.0 , 0.0 ), [qr [0 ]])
510
+
511
+ passmanager = PassManager ()
512
+ passmanager .append (Optimize1qGatesDecomposition (target = target_rz_ry_u_noerror ))
513
+ result = passmanager .run (circuit )
514
+
515
+ msg = f"expected:\n { expected } \n result:\n { result } "
516
+ self .assertEqual (expected , result , msg = msg )
517
+
518
+ def test_optimize_run_of_u_to_single_u_no_target (self ):
519
+ """U(pi/3, 0, 0) * U(pi/3, 0, 0) * U(pi/3, 0, 0) -> U(pi, 0, 0). See #9701."""
520
+ qr = QuantumRegister (1 , "qr" )
521
+ circuit = QuantumCircuit (qr )
522
+ for _ in range (3 ):
523
+ circuit .append (UGate (np .pi / 3 , 0.0 , 0.0 ), [qr [0 ]])
524
+
525
+ expected = QuantumCircuit (qr )
526
+ expected .append (UGate (np .pi , 0.0 , 0.0 ), [qr [0 ]])
527
+
528
+ basis = ["u" ]
529
+ passmanager = PassManager ()
530
+ passmanager .append (Optimize1qGatesDecomposition (basis ))
531
+ result = passmanager .run (circuit )
532
+
533
+ msg = f"expected:\n { expected } \n result:\n { result } "
534
+ self .assertEqual (expected , result , msg = msg )
535
+
501
536
def test_optimize_u_to_phase_gate (self ):
502
537
"""U(0, 0, pi/4) -> p(pi/4). Basis [p, sx]."""
503
538
qr = QuantumRegister (2 , "qr" )
0 commit comments