2
2
3
3
import pytest
4
4
5
- from opensquirrel import Circuit , CircuitBuilder , H , I , Rx , Ry , X
5
+ from opensquirrel import Circuit , CircuitBuilder , H , I , Rx , Ry , X , Y , Z
6
6
from opensquirrel .ir import BlochSphereRotation , Float
7
7
from opensquirrel .passes .merger .general_merger import compose_bloch_sphere_rotations , rearrange_barriers
8
8
@@ -19,29 +19,45 @@ def test_compose_bloch_sphere_rotations_different_axis() -> None:
19
19
a = BlochSphereRotation (qubit = 123 , axis = (1 , 0 , 0 ), angle = math .pi / 2 )
20
20
b = BlochSphereRotation (qubit = 123 , axis = (0 , 0 , 1 ), angle = - math .pi / 2 )
21
21
c = BlochSphereRotation (qubit = 123 , axis = (0 , 1 , 0 ), angle = math .pi / 2 )
22
- composed = compose_bloch_sphere_rotations (a , compose_bloch_sphere_rotations (b , c ) )
22
+ composed = compose_bloch_sphere_rotations (compose_bloch_sphere_rotations (c , b ), a )
23
23
assert composed == BlochSphereRotation (qubit = 123 , axis = (1 , 1 , 0 ), angle = math .pi )
24
24
25
25
26
26
@pytest .mark .parametrize (
27
27
("bsr_a" , "bsr_b" , "expected_result" ),
28
28
[
29
+ (Y (0 ), X (0 ), BlochSphereRotation (0 , axis = (0 , 0 , 1 ), angle = math .pi , phase = math .pi )),
30
+ (X (0 ), Y (0 ), BlochSphereRotation (0 , axis = (0 , 0 , - 1 ), angle = math .pi , phase = math .pi )),
31
+ (Z (0 ), Y (0 ), BlochSphereRotation (0 , axis = (1 , 0 , 0 ), angle = math .pi , phase = math .pi )),
32
+ (Y (0 ), Z (0 ), BlochSphereRotation (0 , axis = (- 1 , 0 , 0 ), angle = math .pi , phase = math .pi )),
33
+ (Z (0 ), X (0 ), BlochSphereRotation (0 , axis = (0 , - 1 , 0 ), angle = math .pi , phase = math .pi )),
34
+ (X (0 ), Z (0 ), BlochSphereRotation (0 , axis = (0 , 1 , 0 ), angle = math .pi , phase = math .pi )),
35
+ (
36
+ Rx (0 , theta = math .pi ),
37
+ Ry (0 , theta = - math .pi / 2 ),
38
+ BlochSphereRotation (0 , axis = (0.70711 , 0.0 , 0.70711 ), angle = math .pi , phase = 0.0 ),
39
+ ),
29
40
(I (0 ), Rx (0 , theta = math .pi ), Rx (0 , theta = math .pi )),
30
41
(Rx (0 , theta = math .pi ), I (0 ), Rx (0 , theta = math .pi )),
31
42
(X (0 ), X (0 ), I (0 )),
32
43
(H (0 ), H (0 ), I (0 )),
33
44
(Rx (0 , theta = math .pi ), Rx (0 , theta = math .pi ), I (0 )),
34
45
(Rx (0 , theta = math .pi / 2 ), Rx (0 , theta = math .pi / 2 ), Rx (0 , theta = math .pi )),
35
- (Rx (0 , theta = math .pi ), Ry (0 , theta = math .pi / 2 ), BlochSphereRotation (0 , axis = (1 , 0 , 1 ), angle = math .pi )),
36
46
],
37
47
ids = [
48
+ "[bsr_a = Y, bsr_b = X] X * Y = iZ" ,
49
+ "[bsr_a = X, bsr_b = Y] Y * X = -iZ" ,
50
+ "[bsr_a = Z, bsr_b = Y] Y * Z = iX" ,
51
+ "[bsr_a = Y, bsr_b = Z] Z * Y = -iX" ,
52
+ "[bsr_a = Z, bsr_b = X] X * Z = -iY" ,
53
+ "[bsr_a = X, bsr_b = Z] Z * X = iY" ,
54
+ "[bsr_a = Rx(pi), bsr_b = Ry(-pi/2)] Ry(-pi/2) * Rx(pi) ~ H" ,
38
55
"[bsr_a == I]" ,
39
56
"[bsr_b == I]" ,
40
57
"[bsr_a.generator == bsr_b.generator] X * X == I" ,
41
58
"[bsr_a.generator == bsr_b.generator] H * H == I" ,
42
59
"[bsr_a.generator == bsr_b.generator] Rx(pi) * Rx(pi) == I" ,
43
60
"[bsr_a.generator == bsr_b.generator] Rx(pi/2) * Rx(pi/2) = Rx(pi) ~ X" ,
44
- "[bsr_a.generator != bsr_b.generator] Rx(pi) * Ry(pi/2) ~ H" ,
45
61
],
46
62
)
47
63
def test_compose_bloch_sphere_rotations (
0 commit comments