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

Commit

Permalink
Implement merge for Quantum
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Apr 17, 2024
1 parent 80ee10f commit 6b4d701
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Quantum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,23 @@ macro reindex!(expr)
iob, idb = b.args
return :((reindex!(Quantum($(esc(ida))), $(Meta.quot(ioa)), Quantum($(esc(idb))), $(Meta.quot(iob)))); $(esc(idb)))
end

Base.merge(a::Quantum, others::Quantum...) = foldl(merge, others, init = a)
function Base.merge(a::Quantum, b::Quantum)
@assert issetequal(outputs(a), map(adjoint, inputs(b))) "Outputs of $a must match inputs of $b"

@reindex! outputs(a) => inputs(b)
tn = merge(TensorNetwork(a), TensorNetwork(b))

sites = Dict{Site,Symbol}()

for site in inputs(a)
sites[site] = select(a, :index, site)
end

for site in outputs(b)
sites[site] = select(b, :index, site)
end

Quantum(tn, sites)
end

0 comments on commit 6b4d701

Please sign in to comment.