This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Quac as weak dep and QrochetQuacExt as extension * Integrate Quac in Qrochet * Add QFT quantum circuit test * Include QrochetQuacExt tests * Move QrochetQuacExt test to integration tests * Add Quac dependency for tests * Rename testsets Co-authored-by: Sergio Sánchez Ramírez <[email protected]> * Make qft test more complete * Clean qft test * Enhance comment syntax Co-authored-by: Sergio Sánchez Ramírez <[email protected]> * Refactor expression * Skip "all inner indices are not sites" test * Add comment --------- Co-authored-by: Sergio Sánchez Ramírez <[email protected]> Co-authored-by: Jofre Vallès Muns <[email protected]>
- Loading branch information
1 parent
7b4d4ef
commit 71c761d
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@testset "Quac" begin | ||
using Quac | ||
|
||
@testset "QFT" begin | ||
n = 3 | ||
qftcirc = Quac.Algorithms.QFT(n) | ||
qftqtn = Quantum(qftcirc) | ||
|
||
# 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 | ||
# TODO too strict condition. remove? | ||
notsiteinds = setdiff(inds(TensorNetwork(qftqtn)), siteinds) | ||
@test_skip issetequal(inds(TensorNetwork(qftqtn), :inner), notsiteinds) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters