Skip to content

Commit

Permalink
Add and extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jofrevalles committed Nov 4, 2024
1 parent a9221e9 commit f55d959
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/Quantum_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@
@test_throws ErrorException Quantum(tn, Dict(site"1" => :j))
@test_throws ErrorException Quantum(tn, Dict(site"1" => :i))

@testset "Base.adjoint" begin
_tensors = Tensor[
Tensor(rand(ComplexF64, 2, 4, 2), [:i, :link, :j]), Tensor(rand(ComplexF64, 2, 4, 2), [:k, :link, :l])
]
tn = TensorNetwork(_tensors)
qtn = Quantum(tn, Dict(site"1" => :i, site"2" => :k, site"1'" => :j, site"2'" => :l))

adjoint_qtn = adjoint(qtn)

@test nsites(adjoint_qtn; set=:inputs) == nsites(adjoint_qtn; set=:outputs) == 2
@test issetequal(sites(adjoint_qtn), [site"1", site"2", site"1'", site"2'"])
@test socket(adjoint_qtn) == Operator()
@test inds(adjoint_qtn; at=site"1'") == :i # now the indices are flipped
@test inds(adjoint_qtn; at=site"1") == :j
@test inds(adjoint_qtn; at=site"2'") == :k
@test inds(adjoint_qtn; at=site"2") == :l
@test isapprox(tensors(adjoint_qtn), replace.(conj.(_tensors), :link => Symbol(:link, "'")))
end

@testset "reindex!" begin
@testset "manual indices" begin
# mps-like tensor network
Expand Down
8 changes: 8 additions & 0 deletions test/TensorNetwork_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,14 @@
@test issetequal(inds(projvirttn), [:i, :k])
end

@testset "Base.conj" begin
tensor1 = Tensor(rand(ComplexF64, 3, 4), (:i, :j))
tensor2 = Tensor(rand(ComplexF64, 4, 5), (:j, :k))
complextn = TensorNetwork([tensor1, tensor2])

@test -imag.(tensors(complextn)) == imag.(tensors(conj(complextn)))
end

@testset "Base.conj!" begin
@testset "for complex" begin
tensor1 = Tensor(rand(ComplexF64, 3, 4), (:i, :j))
Expand Down

0 comments on commit f55d959

Please sign in to comment.