From 2e92e387fac46caacbfb12744869f2967a38f999 Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 15 Feb 2024 16:32:28 +0100 Subject: [PATCH 01/13] Add Quac as weak dep and QrochetQuacExt as extension --- Project.toml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Project.toml b/Project.toml index 253a3e7..7281e97 100644 --- a/Project.toml +++ b/Project.toml @@ -8,7 +8,14 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Tenet = "85d41934-b9cd-44e1-8730-56d86f15f3ec" ValSplit = "0625e100-946b-11ec-09cd-6328dd093154" +[weakdeps] +Quac = "b9105292-1415-45cf-bff1-d6ccf71e6143" + +[extensions] +QrochetQuacExt = "Quac" + [compat] +Quac = "0.2" Tenet = "0.5" ValSplit = "0.1" julia = "1.9" From 97b4da0d968c71c5d8e21db0f9d853c3d83fad5a Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 15 Feb 2024 16:32:48 +0100 Subject: [PATCH 02/13] Integrate Quac in Qrochet --- ext/QrochetQuacExt.jl | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ext/QrochetQuacExt.jl diff --git a/ext/QrochetQuacExt.jl b/ext/QrochetQuacExt.jl new file mode 100644 index 0000000..bcfb289 --- /dev/null +++ b/ext/QrochetQuacExt.jl @@ -0,0 +1,42 @@ +module QrochetQuacExt + +using Qrochet +using Tenet +using Quac: Circuit, lanes, arraytype, Swap + +function Qrochet.Quantum(circuit::Circuit) + n = lanes(circuit) + wire = [[Tenet.letter(i)] for i in 1:n] + tensors = Tensor[] + + i = n + 1 + for gate in circuit + G = arraytype(gate) + array = G(gate) + + if gate isa Swap + (a, b) = lanes(gate) + wire[a], wire[b] = wire[b], wire[a] + continue + end + + inds = map(lanes(gate)) do l + from, to = last(wire[l]), Tenet.letter(i) + i += 1 + push!(wire[l], to) + (from, to) + end |> x -> zip(x...) |> Iterators.flatten |> collect + + tensor = Tensor(array, tuple(inds...)) + push!(tensors, tensor) + end + + sites = merge( + Dict([Site(site; dual=true) => first(index) for (site, index) in enumerate(wire)]), + Dict([Site(site; dual=false) => last(index) for (site, index) in enumerate(wire)]) + ) + + Quantum(Tenet.TensorNetwork(tensors), sites) +end + +end \ No newline at end of file From 5ca5a85090296b0527bb9b6bce4735fb294ba62f Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 15 Feb 2024 16:33:31 +0100 Subject: [PATCH 03/13] Add QFT quantum circuit test --- test/integration/QrochetQuacExt_test.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/integration/QrochetQuacExt_test.jl diff --git a/test/integration/QrochetQuacExt_test.jl b/test/integration/QrochetQuacExt_test.jl new file mode 100644 index 0000000..19e4aea --- /dev/null +++ b/test/integration/QrochetQuacExt_test.jl @@ -0,0 +1,18 @@ +@testset "QrochetQuacExt" begin + using Quac + + @testset "QFT_3qubits" begin + qft3circ = Quac.Algorithms.QFT(3) + qft3qrochet = Quantum(qft3circ) + + # test sites (inputs and outputs) of the quantum circuit + for site in values(qft3qrochet.sites) + @test length(qft3qrochet.tn.indexmap[site]) == 1 + end + + # test inner tensors + for notsite in filter(idx -> idx ∉ values(qrqft3.sites), keys(qrqft3.tn.indexmap)) + @test length(qft3qrochet.tn.indexmap[notsite]) > 1 + end + end +end \ No newline at end of file From 0c1f3e188c0ad5f254a28dff63ebffbd8856d4f9 Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 15 Feb 2024 16:44:56 +0100 Subject: [PATCH 04/13] Include QrochetQuacExt tests --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index b4a3d3d..8a34a32 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,6 +6,7 @@ using Qrochet include("Quantum_test.jl") include("Ansatz/Product_test.jl") include("Ansatz/Chain_test.jl") + include("integration/QrochetQuacExt_test.jl") end @testset "Integration tests" verbose = true begin end From 0ce352a199954f3f5114cc5326cb88af59c7cf89 Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 15 Feb 2024 16:52:44 +0100 Subject: [PATCH 05/13] Move QrochetQuacExt test to integration tests --- test/runtests.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 8a34a32..ffceb90 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,10 +6,11 @@ using Qrochet include("Quantum_test.jl") include("Ansatz/Product_test.jl") include("Ansatz/Chain_test.jl") - include("integration/QrochetQuacExt_test.jl") end -@testset "Integration tests" verbose = true begin end +@testset "Integration tests" verbose = true begin + include("integration/QrochetQuacExt_test.jl") +end if haskey(ENV, "ENABLE_AQUA_TESTS") @testset "Aqua" verbose = true begin From 4d85ad3635ea80a54286df8b48ad5584d08783a1 Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 15 Feb 2024 16:56:21 +0100 Subject: [PATCH 06/13] Add Quac dependency for tests --- test/Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Project.toml b/test/Project.toml index f6fa720..dfed1ae 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -2,3 +2,4 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Tenet = "85d41934-b9cd-44e1-8730-56d86f15f3ec" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +Quac = "b9105292-1415-45cf-bff1-d6ccf71e6143" From b91e6fe401eab709c079f690475661aec2a37d4d Mon Sep 17 00:00:00 2001 From: Todorbsc <145352308+Todorbsc@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:32:38 +0100 Subject: [PATCH 07/13] Rename testsets 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/integration/QrochetQuacExt_test.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/QrochetQuacExt_test.jl b/test/integration/QrochetQuacExt_test.jl index 19e4aea..4e818ef 100644 --- a/test/integration/QrochetQuacExt_test.jl +++ b/test/integration/QrochetQuacExt_test.jl @@ -1,7 +1,7 @@ -@testset "QrochetQuacExt" begin +@testset "Quac" begin using Quac - @testset "QFT_3qubits" begin + @testset "QFT" begin qft3circ = Quac.Algorithms.QFT(3) qft3qrochet = Quantum(qft3circ) From 2b3ca8c2b54dcc59254ad3d30584513ad1610ee8 Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 15 Feb 2024 18:57:38 +0100 Subject: [PATCH 08/13] Make qft test more complete --- test/integration/QrochetQuacExt_test.jl | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/test/integration/QrochetQuacExt_test.jl b/test/integration/QrochetQuacExt_test.jl index 4e818ef..b1b6243 100644 --- a/test/integration/QrochetQuacExt_test.jl +++ b/test/integration/QrochetQuacExt_test.jl @@ -2,17 +2,20 @@ using Quac @testset "QFT" begin - qft3circ = Quac.Algorithms.QFT(3) - qft3qrochet = Quantum(qft3circ) + n = 3 + qftcirc = Quac.Algorithms.QFT(n) + qftqtn = Quantum(qftcirc) - # test sites (inputs and outputs) of the quantum circuit - for site in values(qft3qrochet.sites) - @test length(qft3qrochet.tn.indexmap[site]) == 1 - end + siteinds = getindex.((qftqtn,), sites(qftqtn)) + notsiteinds = filter(idx -> idx ∉ getindex.((qftqtn,), sites(qftqtn)), keys(TensorNetwork(qftqtn).indexmap)) - # test inner tensors - for notsite in filter(idx -> idx ∉ values(qrqft3.sites), keys(qrqft3.tn.indexmap)) - @test length(qft3qrochet.tn.indexmap[notsite]) > 1 - end + # correct number of inputs and outputs + @test ninputs(qftqtn) == n + @test noutputs(qftqtn) == n + @test socket(qftqtn) == Operator() + # all open indices are sites + @test issetequal(inds(TensorNetwork(qftqtn), :open), siteinds) + # all inner indices are not sites + @test issetequal(inds(TensorNetwork(qftqtn), :inner), notsiteinds) end end \ No newline at end of file From a5a62a8d2e89cd7223d867a51acadfe6dc2038dd Mon Sep 17 00:00:00 2001 From: Todorbsc Date: Thu, 15 Feb 2024 19:00:20 +0100 Subject: [PATCH 09/13] Clean qft test --- test/integration/QrochetQuacExt_test.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/integration/QrochetQuacExt_test.jl b/test/integration/QrochetQuacExt_test.jl index b1b6243..5b7f8a6 100644 --- a/test/integration/QrochetQuacExt_test.jl +++ b/test/integration/QrochetQuacExt_test.jl @@ -6,16 +6,15 @@ qftcirc = Quac.Algorithms.QFT(n) qftqtn = Quantum(qftcirc) - siteinds = getindex.((qftqtn,), sites(qftqtn)) - notsiteinds = filter(idx -> idx ∉ getindex.((qftqtn,), sites(qftqtn)), keys(TensorNetwork(qftqtn).indexmap)) - # correct number of inputs and outputs @test ninputs(qftqtn) == n @test noutputs(qftqtn) == n @test socket(qftqtn) == Operator() # all open indices are sites + siteinds = getindex.((qftqtn,), sites(qftqtn)) @test issetequal(inds(TensorNetwork(qftqtn), :open), siteinds) # all inner indices are not sites + notsiteinds = filter(idx -> idx ∉ siteinds, keys(TensorNetwork(qftqtn).indexmap)) @test issetequal(inds(TensorNetwork(qftqtn), :inner), notsiteinds) end end \ No newline at end of file From 65bc6bc651d22411cdfd97e7fb3b5ba88e2dea4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jofre=20Vall=C3=A8s=20Muns?= <61060572+jofrevalles@users.noreply.github.com> Date: Fri, 16 Feb 2024 09:30:01 +0100 Subject: [PATCH 10/13] Enhance comment syntax 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/integration/QrochetQuacExt_test.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/integration/QrochetQuacExt_test.jl b/test/integration/QrochetQuacExt_test.jl index 5b7f8a6..277fa62 100644 --- a/test/integration/QrochetQuacExt_test.jl +++ b/test/integration/QrochetQuacExt_test.jl @@ -10,9 +10,11 @@ @test ninputs(qftqtn) == n @test noutputs(qftqtn) == n @test socket(qftqtn) == Operator() + # all open indices are sites siteinds = getindex.((qftqtn,), sites(qftqtn)) @test issetequal(inds(TensorNetwork(qftqtn), :open), siteinds) + # all inner indices are not sites notsiteinds = filter(idx -> idx ∉ siteinds, keys(TensorNetwork(qftqtn).indexmap)) @test issetequal(inds(TensorNetwork(qftqtn), :inner), notsiteinds) From ff1bc11094353fcd54b38f80f59f012a32eed010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20S=C3=A1nchez=20Ram=C3=ADrez?= <15837247+mofeing@users.noreply.github.com> Date: Fri, 16 Feb 2024 10:16:04 +0000 Subject: [PATCH 11/13] Refactor expression --- test/integration/QrochetQuacExt_test.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/QrochetQuacExt_test.jl b/test/integration/QrochetQuacExt_test.jl index 277fa62..7bde614 100644 --- a/test/integration/QrochetQuacExt_test.jl +++ b/test/integration/QrochetQuacExt_test.jl @@ -16,7 +16,7 @@ @test issetequal(inds(TensorNetwork(qftqtn), :open), siteinds) # all inner indices are not sites - notsiteinds = filter(idx -> idx ∉ siteinds, keys(TensorNetwork(qftqtn).indexmap)) + notsiteinds = setdiff(inds(TensorNetwork(qftqtn)), siteinds) @test issetequal(inds(TensorNetwork(qftqtn), :inner), notsiteinds) end end \ No newline at end of file From e5c09eee3ec7474a52ae7b17f7a4f829fba6b160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20S=C3=A1nchez=20Ram=C3=ADrez?= <15837247+mofeing@users.noreply.github.com> Date: Fri, 16 Feb 2024 10:18:27 +0000 Subject: [PATCH 12/13] Skip "all inner indices are not sites" test --- test/integration/QrochetQuacExt_test.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/QrochetQuacExt_test.jl b/test/integration/QrochetQuacExt_test.jl index 7bde614..3123f2d 100644 --- a/test/integration/QrochetQuacExt_test.jl +++ b/test/integration/QrochetQuacExt_test.jl @@ -17,6 +17,6 @@ # all inner indices are not sites notsiteinds = setdiff(inds(TensorNetwork(qftqtn)), siteinds) - @test issetequal(inds(TensorNetwork(qftqtn), :inner), notsiteinds) + @test_skip issetequal(inds(TensorNetwork(qftqtn), :inner), notsiteinds) end end \ No newline at end of file From c0339922f84c14307057da0abd6a673a4b62a877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20S=C3=A1nchez=20Ram=C3=ADrez?= <15837247+mofeing@users.noreply.github.com> Date: Fri, 16 Feb 2024 10:19:05 +0000 Subject: [PATCH 13/13] Add comment --- test/integration/QrochetQuacExt_test.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/QrochetQuacExt_test.jl b/test/integration/QrochetQuacExt_test.jl index 3123f2d..eefaeeb 100644 --- a/test/integration/QrochetQuacExt_test.jl +++ b/test/integration/QrochetQuacExt_test.jl @@ -16,6 +16,7 @@ @test issetequal(inds(TensorNetwork(qftqtn), :open), siteinds) # all inner indices are not sites + # TODO too strict condition. remove? notsiteinds = setdiff(inds(TensorNetwork(qftqtn)), siteinds) @test_skip issetequal(inds(TensorNetwork(qftqtn), :inner), notsiteinds) end