From f55d9590be421fcab0a246c8d363c6fbe4327df9 Mon Sep 17 00:00:00 2001 From: jofrevalles Date: Thu, 31 Oct 2024 12:06:23 +0100 Subject: [PATCH] Add and extend tests --- test/Quantum_test.jl | 19 +++++++++++++++++++ test/TensorNetwork_test.jl | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/test/Quantum_test.jl b/test/Quantum_test.jl index cb15401b8..5d463d2bd 100644 --- a/test/Quantum_test.jl +++ b/test/Quantum_test.jl @@ -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 diff --git a/test/TensorNetwork_test.jl b/test/TensorNetwork_test.jl index 3a82c2acd..73fbea7ac 100644 --- a/test/TensorNetwork_test.jl +++ b/test/TensorNetwork_test.jl @@ -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))