Skip to content

Commit

Permalink
Fix @reindex! when virtual indices intersect
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Aug 2, 2024
1 parent 5995710 commit b7a3b11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Quantum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ function reindex!(a::Quantum, ioa, b::Quantum, iob)
return b
end

resetindex_mapping = resetindex!(Val(:return_mapping), TensorNetwork(b); init=ninds(TensorNetwork(a)))
replacements = merge!(resetindex_mapping, Dict(replacements))
replace!(TensorNetwork(b), replacements...)

for site in sitesb
Expand Down
10 changes: 7 additions & 3 deletions src/TensorNetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,13 @@ See also: [`ntensors`](@ref)
"""
ninds(tn::TensorNetwork) = length(tn.indexmap)

function resetindex!(tn::TensorNetwork)
gen = IndexCounter()
mapping = Dict{Symbol,Symbol}([i => nextindex!(gen) for i in inds(tn)])
function resetindex!(::Val{:return_mapping}, tn::TensorNetwork; init::Int=1)
gen = IndexCounter(init)
return Dict{Symbol,Symbol}([i => nextindex!(gen) for i in inds(tn)])
end

function resetindex!(tn::TensorNetwork; init::Int=1)
mapping = resetindex!(Val(:return_mapping), tn; init=init)
return replace!(tn, mapping)
end

Expand Down

0 comments on commit b7a3b11

Please sign in to comment.