Skip to content

Commit

Permalink
Fix indexing problems in simple_update_1site!
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Sep 19, 2024
1 parent de73a6a commit 9b22b13
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Ansatz/Ansatz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,26 +174,28 @@ function simple_update!(ψ::AbstractAnsatz, gate; threshold=nothing, maxdim=noth
return simple_update!(form(ψ), ψ, gate; kwargs...)
end

# TODO a lot of problems with merging... maybe we don't to merge manually
function simple_update_1site!::AbstractAnsatz, gate)
@assert nlanes(gate) == 1 "Gate must act only on one lane"
@assert ninputs(gate) == 1 "Gate must have only one input"
@assert noutputs(gate) == 1 "Gate must have only one output"

# shallow copy to avoid problems if errors in mid execution
gate = copy(gate)
resetindex!(gate; init=ninds(ψ))

contracting_index = gensym(:tmp)
targetsite = only(sites(gate; set=:inputs))'

# reindex output of gate to match TN sitemap
replace!(gate, inds(gate; at=only(sites(gate; set=:outputs))) => inds(ψ; at=targetsite))

# reindex contracting index
replace!(ψ, inds(ψ; at=targetsite) => contracting_index)
replace!(gate, inds(gate; at=targetsite') => contracting_index)

# reindex output of gate to match TN sitemap
replace!(gate, inds(gate; at=only(sites(gate; set=:outputs))) => inds(ψ; at=targetsite))

# contract gate with TN
merge!(ψ, gate)
merge!(ψ, gate; reset=false)
return contract!(ψ, contracting_index)
end

Expand Down

0 comments on commit 9b22b13

Please sign in to comment.