@@ -37,5 +37,32 @@ julia> Pkg.add("ITensorQuantumOperatorDefinitions")
3737
3838# ## Examples
3939
40- using ITensorQuantumOperatorDefinitions: ITensorQuantumOperatorDefinitions
41- # Examples go here.
40+ using ITensorBase: ITensor, Index, tags
41+ using ITensorQuantumOperatorDefinitions:
42+ OpName, SiteType, StateName, ValName, op, siteind, siteinds, state, val
43+ using Test: @test
44+
45+ # States and operators as Julia arrays
46+ @test val (ValName (" Up" ), SiteType (" S=1/2" )) == 1
47+ @test val (ValName (" Dn" ), SiteType (" S=1/2" )) == 2
48+ @test state (StateName (" Up" ), SiteType (" S=1/2" )) == [1 , 0 ]
49+ @test state (StateName (" Dn" ), SiteType (" S=1/2" )) == [0 , 1 ]
50+ @test op (OpName (" X" ), SiteType (" S=1/2" )) == [0 1 ; 1 0 ]
51+ @test op (OpName (" Z" ), SiteType (" S=1/2" )) == [1 0 ; 0 - 1 ]
52+
53+ # Index constructors
54+ @test siteind (" S=1/2" ) isa Index
55+ @test Int (length (siteind (" S=1/2" ))) == 2
56+ @test " S=1/2" in tags (siteind (" S=1/2" ))
57+ @test siteinds (" S=1/2" , 4 ) isa Vector{<: Index }
58+ @test length (siteinds (" S=1/2" , 4 )) == 4
59+ @test all (s -> " S=1/2" in tags (s), siteinds (" S=1/2" , 4 ))
60+
61+ # States and operators as ITensors
62+ s = Index (2 , " S=1/2" )
63+ @test val (s, " Up" ) == 1
64+ @test val (s, " Dn" ) == 2
65+ @test state (" Up" , s) == ITensor ([1 , 0 ], (s,))
66+ @test state (" Dn" , s) == ITensor ([0 , 1 ], (s,))
67+ @test op (" X" , s) == ITensor ([0 1 ; 1 0 ], (s' , s))
68+ @test op (" Z" , s) == ITensor ([1 0 ; 0 - 1 ], (s' , s))
0 commit comments