From e933bac39bd2aeaba6a475cea05b1ab42cd88b0f Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 16 Jan 2025 16:38:44 +0100 Subject: [PATCH 1/5] Replace type T for type Tensor --- src/Numerics.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Numerics.jl b/src/Numerics.jl index 544681f22..71e40e135 100644 --- a/src/Numerics.jl +++ b/src/Numerics.jl @@ -141,8 +141,8 @@ end Alias for [`contract`](@ref). """ Base.:*(a::Tensor, b::Tensor) = contract(a, b) -Base.:*(a::Tensor, b::Number) = T(parent(a) * b, inds(a)) -Base.:*(a::Number, b::Tensor) = T(a * parent(b), inds(b)) +Base.:*(a::Tensor, b::Number) = Tensor(parent(a) * b, inds(a)) +Base.:*(a::Number, b::Tensor) = Tensor(a * parent(b), inds(b)) function factorinds(tensor, left_inds, right_inds) isdisjoint(left_inds, right_inds) || From 464c9ae8a8bf1f1536ed49d1e01c60388863eaa5 Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 16 Jan 2025 16:48:31 +0100 Subject: [PATCH 2/5] Add tensor-number multiplication tests --- test/Numerics_test.jl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/Numerics_test.jl b/test/Numerics_test.jl index 04a948274..7751ae94b 100644 --- a/test/Numerics_test.jl +++ b/test/Numerics_test.jl @@ -16,6 +16,16 @@ @test parent(D) ≈ parent(A) - permutedims(parent(B), (3, 1, 4, 2)) end + @testset "tensor-number multiplication" begin + data = rand(2, 3, 4) + realnum = 2 + complexnum = 2 + 2im + + A = Tensor(data, (:i, :j, :k)) + @test data * realnum ≈ parent(A * realnum) ≈ parent(realnum * A) + @test data * complexnum ≈ parent(A * complexnum) ≈ parent(complexnum * A) + end + @testset "contract" begin @testset "axis sum" begin A = Tensor(rand(2, 3, 4), (:i, :j, :k)) From ff95936c54e4d833fe124f234674ad1a991ab0c3 Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 16 Jan 2025 17:13:51 +0100 Subject: [PATCH 3/5] Fix convert type to Circuit & site indexing to start from 1 --- ext/TenetPythonCallExt/Qiskit.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/TenetPythonCallExt/Qiskit.jl b/ext/TenetPythonCallExt/Qiskit.jl index f07d209d9..f1989a146 100644 --- a/ext/TenetPythonCallExt/Qiskit.jl +++ b/ext/TenetPythonCallExt/Qiskit.jl @@ -1,4 +1,4 @@ -function Base.convert(::Type{Quantum}, ::Val{:qiskit}, pyobj::Py) +function Base.convert(::Type{Circuit}, ::Val{:qiskit}, pyobj::Py) qiskit = pyimport("qiskit") if !pyissubclass(pytype(pyobj), qiskit.circuit.quantumcircuit.QuantumCircuit) throw( @@ -11,7 +11,7 @@ function Base.convert(::Type{Quantum}, ::Val{:qiskit}, pyobj::Py) circuit = Circuit() for instr in pyobj - gatelanes = map(x -> Lane(pyconvert(Int, x._index)), instr.qubits) + gatelanes = map(x -> Lane(pyconvert(Int, x._index) + 1), instr.qubits) gatesites = [Site.(gatelanes; dual=true)..., Site.(gatelanes)...] # if unassigned parameters, throw From 43a13c4d720aefe667da589b17904c19b7574a40 Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 16 Jan 2025 17:19:45 +0100 Subject: [PATCH 4/5] Remove changes from a different branch --- src/Numerics.jl | 4 ++-- test/Numerics_test.jl | 10 ---------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/Numerics.jl b/src/Numerics.jl index 71e40e135..544681f22 100644 --- a/src/Numerics.jl +++ b/src/Numerics.jl @@ -141,8 +141,8 @@ end Alias for [`contract`](@ref). """ Base.:*(a::Tensor, b::Tensor) = contract(a, b) -Base.:*(a::Tensor, b::Number) = Tensor(parent(a) * b, inds(a)) -Base.:*(a::Number, b::Tensor) = Tensor(a * parent(b), inds(b)) +Base.:*(a::Tensor, b::Number) = T(parent(a) * b, inds(a)) +Base.:*(a::Number, b::Tensor) = T(a * parent(b), inds(b)) function factorinds(tensor, left_inds, right_inds) isdisjoint(left_inds, right_inds) || diff --git a/test/Numerics_test.jl b/test/Numerics_test.jl index 7751ae94b..04a948274 100644 --- a/test/Numerics_test.jl +++ b/test/Numerics_test.jl @@ -16,16 +16,6 @@ @test parent(D) ≈ parent(A) - permutedims(parent(B), (3, 1, 4, 2)) end - @testset "tensor-number multiplication" begin - data = rand(2, 3, 4) - realnum = 2 - complexnum = 2 + 2im - - A = Tensor(data, (:i, :j, :k)) - @test data * realnum ≈ parent(A * realnum) ≈ parent(realnum * A) - @test data * complexnum ≈ parent(A * complexnum) ≈ parent(complexnum * A) - end - @testset "contract" begin @testset "axis sum" begin A = Tensor(rand(2, 3, 4), (:i, :j, :k)) From 700bb3a2cf24692e8bea07a165a9f0c11cac000c Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 23 Jan 2025 10:48:34 +0100 Subject: [PATCH 5/5] Start Sites and Lanes from 1 instead of 0 --- test/integration/python/test_qiskit.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/python/test_qiskit.jl b/test/integration/python/test_qiskit.jl index 0d03d9d9c..c69c65643 100644 --- a/test/integration/python/test_qiskit.jl +++ b/test/integration/python/test_qiskit.jl @@ -13,11 +13,11 @@ tn = convert(Circuit, circuit) @test tn isa Circuit - @test issetequal(sites(tn; set=:inputs), Site.([0, 1, 2]; dual=true)) - @test issetequal(sites(tn; set=:outputs), Site.([0, 1, 2])) + @test issetequal(sites(tn; set=:inputs), Site.([1, 2, 3]; dual=true)) + @test issetequal(sites(tn; set=:outputs), Site.([1, 2, 3])) @test Tenet.ntensors(tn) == 7 @test issetequal( moments(tn), - [Tenet.Moment.(Ref(Lane(0)), 1:4)..., Tenet.Moment.(Ref(Lane(1)), 1:4)..., Tenet.Moment.(Ref(Lane(2)), 1:4)...], + [Tenet.Moment.(Ref(Lane(1)), 1:4)..., Tenet.Moment.(Ref(Lane(2)), 1:4)..., Tenet.Moment.(Ref(Lane(3)), 1:4)...], ) end