Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.

Commit

Permalink
Integrate Quac in Qrochet
Browse files Browse the repository at this point in the history
  • Loading branch information
Todorbsc committed Feb 15, 2024
1 parent 2e92e38 commit 97b4da0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions ext/QrochetQuacExt.jl
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

0 comments on commit 97b4da0

Please sign in to comment.