From 748f07bcbc40e0265aac6342bf785fe460a9a82a Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Fri, 8 Mar 2024 18:15:16 +0100 Subject: [PATCH 1/3] Include tests for Rx, Ry, Rz, U2, U3, Hz & FSim --- test/Array_test.jl | 179 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/test/Array_test.jl b/test/Array_test.jl index fee8c1f..0beff84 100644 --- a/test/Array_test.jl +++ b/test/Array_test.jl @@ -160,6 +160,22 @@ end @testset "Correctness" begin + @testset "Rx" begin + @test begin + g = Rx(1, θ = 0) + Matrix(g) ≈ LinearAlgebra.I(2^length(g)) + end + + @test begin + g = Rx(1, θ = π / 2) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1im; -1im 1] + end + + @test begin + g = Rx(1, θ = π) + Matrix(g) ≈ [0 -1im; -1im 0] + end + end @testset "Rxx" begin @test begin g = Rxx(1, 2, θ = 0) @@ -178,6 +194,23 @@ end end + @testset "Ry" begin + @test begin + g = Ry(1, θ = 0) + Matrix(g) ≈ LinearAlgebra.I(2^length(g)) + end + + @test begin + g = Ry(1, θ = π / 2) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1; 1 1] + end + + @test begin + g = Ry(1, θ = π) + Matrix(g) ≈ [0 -1; 1 0] + end + end + @testset "Ryy" begin @test begin g = Ryy(1, 2, θ = 0) @@ -196,6 +229,23 @@ end end + @testset "Rz" begin + @test begin + g = Rz(1, θ = 0) + Matrix(g) ≈ LinearAlgebra.I(2^length(g)) + end + + @test begin + g = Rz(1, θ = π / 2) + Matrix(g) ≈ [1 0; 0 1im] + end + + @test begin + g = Rz(1, θ = π) + Matrix(g) ≈ [1 0; 0 -1] + end + end + @testset "Rzz" begin @test begin g = Rzz(1, 2, θ = 0) @@ -213,5 +263,134 @@ Matrix(g) ≈ -1im * reshape(permutedims(reshape(kron(vec(x), vec(x)), 2, 2, 2, 2), (1, 3, 2, 4)), 4, 4) end end + + @testset "U2" begin + @test begin + g = U2(1, ϕ = 0, λ = 0) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1; 1 1] + end + + @test begin + g = U2(1, ϕ = 0, λ = π / 2) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1im; 1 1im] + end + + @test begin + g = U2(1, ϕ = 0, λ = π) + Matrix(g) ≈ 1 / sqrt(2) * [1 1; 1 -1] + end + + @test begin + g = U2(1, ϕ = π / 2, λ = 0) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1; 1im 1im] + end + + @test begin + g = U2(1, ϕ = π / 2, λ = π / 2) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1im; 1im -1] + end + + @test begin + g = U2(1, ϕ = π / 2, λ = π) + Matrix(g) ≈ 1 / sqrt(2) * [1 1; 1im -1im] + end + + @test begin + g = U2(1, ϕ = π, λ = 0) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1; -1 -1] + end + + @test begin + g = U2(1, ϕ = π, λ = π / 2) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1im; -1 -1im] + end + + @test begin + g = U2(1, ϕ = π, λ = π) + Matrix(g) ≈ 1 / sqrt(2) * [1 1; -1 1] + end + end + + @testset "U3" begin + @test begin + g = U3(1, θ = 0, ϕ = 0, λ = 0) + Matrix(g) ≈ LinearAlgebra.I(2^length(g)) + end + + @test begin + g = U3(1, θ = π / 2, ϕ = π / 2, λ = π / 2) + Matrix(g) ≈ 1 / sqrt(2) * [1 -1im; 1im -1] + end + + @test begin + g = U3(1, θ = π, ϕ = π, λ = π) + Matrix(g) ≈ [0 1; -1 0] + end + end + + @testset "Hz" begin + @test begin + g = Hz(1, θ = 0, ϕ = 0) + Matrix(g) ≈ LinearAlgebra.I(2^length(g)) + end + + @test begin + g = Hz(1, θ = π / 2, ϕ = π / 2) + Matrix(g) ≈ 1 / 2 * [1+1im 1-1im; -1+1im 1+1im] + end + + @test begin + g = Hz(1, θ = π, ϕ = π) + Matrix(g) ≈ [0 1; 1 0] + end + end + + @testset "FSim" begin + @test begin + g = FSim(1, 2, θ = 0, ϕ = 0) + Matrix(g) ≈ LinearAlgebra.I(2^length(g)) + end + + @test begin + g = FSim(1, 2, θ = 0, ϕ = π / 2) + Matrix(g) ≈ [1 0 0 0; 0 1 -1im 0; 0 -1im 1 0; 0 0 0 1] + end + + @test begin + g = FSim(1, 2, θ = 0, ϕ = π) + Matrix(g) ≈ LinearAlgebra.I(2^length(g)) + end + + @test begin + g = FSim(1, 2, θ = π / 2, ϕ = 0) + Matrix(g) ≈ [1 0 0 0; 0 0 0 0; 0 0 0 0; 0 0 0 1] + end + + @test begin + g = FSim(1, 2, θ = π / 2, ϕ = π / 2) + Matrix(g) ≈ [1 0 0 0; 0 0 -1im 0; 0 -1im 0 0; 0 0 0 1] + end + + @test begin + g = FSim(1, 2, θ = π / 2, ϕ = π) + Matrix(g) ≈ [1 0 0 0; 0 0 0 0; 0 0 0 0; 0 0 0 1] + end + + @test begin + g = FSim(1, 2, θ = π, ϕ = 0) + Matrix(g) ≈ [1 0 0 0; 0 -1 0 0; 0 0 -1 0; 0 0 0 1] + end + + @test begin + g = FSim(1, 2, θ = π, ϕ = π / 2) + Matrix(g) ≈ [1 0 0 0; 0 -1 -1im 0; 0 -1im -1 0; 0 0 0 1] + end + + @test begin + g = FSim(1, 2, θ = π, ϕ = π) + Matrix(g) ≈ [1 0 0 0; 0 -1 0 0; 0 0 -1 0; 0 0 0 1] + end + end + end end From a29d40d8a6d1a003fe7223a3cd6db10a238db287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jofre=20Vall=C3=A8s=20Muns?= <61060572+jofrevalles@users.noreply.github.com> Date: Fri, 8 Mar 2024 18:54:39 +0100 Subject: [PATCH 2/3] Remove empty line --- test/Array_test.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Array_test.jl b/test/Array_test.jl index 0beff84..7ac7a23 100644 --- a/test/Array_test.jl +++ b/test/Array_test.jl @@ -391,6 +391,5 @@ Matrix(g) ≈ [1 0 0 0; 0 -1 0 0; 0 0 -1 0; 0 0 0 1] end end - end end From e3ec3c7b8d7176b7e6628364fd88e7a3f5037fb4 Mon Sep 17 00:00:00 2001 From: Todorbsc <145352308+Todorbsc@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:10:00 +0100 Subject: [PATCH 3/3] Add new line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sergio Sánchez Ramírez <15837247+mofeing@users.noreply.github.com> --- test/Array_test.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Array_test.jl b/test/Array_test.jl index 7ac7a23..a2054a6 100644 --- a/test/Array_test.jl +++ b/test/Array_test.jl @@ -176,6 +176,7 @@ Matrix(g) ≈ [0 -1im; -1im 0] end end + @testset "Rxx" begin @test begin g = Rxx(1, 2, θ = 0)