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

Commit

Permalink
Fix reindex! function to do nothing if reindex is not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
jofrevalles committed Apr 17, 2024
1 parent e4b9ff8 commit 80ee10f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Quantum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ Tenet.select(tn::Quantum, ::Val{:index}, site::Site) = tn[site]
Tenet.select(tn::Quantum, ::Val{:tensor}, site::Site) = select(TensorNetwork(tn), :any, tn[site]) |> only

function reindex!(a::Quantum, ioa, b::Quantum, iob)
ioa [:inputs, :outputs] || error("Invalid argument: :$ioa")
sitesa = if ioa === :inputs
inputs(a)
elseif ioa === :outputs
outputs(a)
else
error("Invalid argument: :$ioa")
end

sitesb = if iob === :inputs
inputs(b)
Expand All @@ -163,6 +169,10 @@ function reindex!(a::Quantum, ioa, b::Quantum, iob)
error("Invalid argument: :$iob")
end

if sitesa == sitesb
return b
end

replacements = map(sitesb) do site
select(b, :index, site) => select(a, :index, ioa != iob ? site' : site)
end
Expand Down

0 comments on commit 80ee10f

Please sign in to comment.