Skip to content

Commit

Permalink
Added expect function dispatching on AbstractTTN.
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Kloss committed Jan 24, 2024
1 parent 56fcb93 commit 1f888df
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/treetensornetworks/abstracttreetensornetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,23 @@ function inner(
end
return O[]
end

function expect(
operator::String,
state::AbstractTTN;
sites=siteinds(state),
root_vertex=default_root_vertex(sites), #ToDo: verify that this is a sane default
)
# ToDo: for performance it may be beneficial to also implement expect! and change the orthogonality center in place
# assuming that the next algorithmic step can make use of the orthogonality center being moved to a different vertex
vertices = reverse(post_order_dfs_vertices(sites, root_vertex)) #ToDo: Verify that this is indeed the correct order for performance
ElT = promote_itensor_eltype(state)
res = Dictionary(vertices, Vector{ElT}(undef, length(vertices)))
for v in vertices
state = orthogonalize(state, v)
@assert isone(length(sites[v]))
Op = ITensors.op(operator, only(sites[v])) #ToDo: Add compatibility with more than a single index per vertex
res[v] = scalar(dag(state[v]) * apply(Op, state[v]))
end
return res
end

0 comments on commit 1f888df

Please sign in to comment.