@@ -4,6 +4,8 @@ using LinearAlgebra
44
55@testset " nlevel" begin
66
7+ D (op1:: AbstractOperator , op2:: AbstractOperator ) = abs (tracedistance_nh (dense (op1), dense (op2)))
8+
79N = 3
810b = NLevelBasis (N)
911
@@ -26,4 +28,52 @@ b = NLevelBasis(N)
2628@test norm (dagger (nlevelstate (b, 1 ))* nlevelstate (b, 2 )) == 0.
2729@test norm (dagger (nlevelstate (b, 1 ))* transition (b, 1 , 2 )* nlevelstate (b, 2 )) == 1.
2830
31+ for N= [2 , 3 , 4 , 5 ]
32+ b = NLevelBasis (N)
33+ I = identityoperator (b)
34+ Zero = SparseOperator (b)
35+ px = paulix (b)
36+ pz = pauliz (b)
37+
38+ @test 1e-14 > abs (tr (px))
39+ @test 1e-14 > abs (tr (pz))
40+ @test 1e-14 > D (px^ N, I)
41+ @test 1e-14 > D (pz^ N, I)
42+ for m= 2 : N
43+ @test 1e-14 > D (px^ m, paulix (b,m))
44+ @test 1e-14 > D (pz^ m, pauliz (b,m))
45+ end
46+
47+ for m= 1 : N,n= 1 : N
48+ @test 1e-14 > D (px^ m * pz^ n, exp (2 π* 1im * m* n/ N) * pz^ n * px^ m)
49+ end
50+ end
51+
52+
53+ # Test special relations for qubit pauli
54+ b = NLevelBasis (2 )
55+ I = identityoperator (b)
56+ Zero = SparseOperator (b)
57+ px = paulix (b)
58+ py = pauliy (b)
59+ pz = pauliz (b)
60+
61+ antikommutator (x, y) = x* y + y* x
62+
63+ @test 1e-14 > D (antikommutator (px, px), 2 * I)
64+ @test 1e-14 > D (antikommutator (px, py), Zero)
65+ @test 1e-14 > D (antikommutator (px, pz), Zero)
66+ @test 1e-14 > D (antikommutator (py, px), Zero)
67+ @test 1e-14 > D (antikommutator (py, py), 2 * I)
68+ @test 1e-14 > D (antikommutator (py, pz), Zero)
69+ @test 1e-14 > D (antikommutator (pz, px), Zero)
70+ @test 1e-14 > D (antikommutator (pz, py), Zero)
71+ @test 1e-14 > D (antikommutator (pz, pz), 2 * I)
72+
73+ # Test if involutory for spin 1/2
74+ @test 1e-14 > D (px* px, I)
75+ @test 1e-14 > D (py* py, I)
76+ @test 1e-14 > D (pz* pz, I)
77+ @test 1e-14 > D (- 1im * px* py* pz, I)
78+
2979end # testset
0 commit comments