Skip to content

Commit

Permalink
Revert
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Jun 12, 2024
1 parent 322dca4 commit 54f41c0
Showing 1 changed file with 1 addition and 69 deletions.
70 changes: 1 addition & 69 deletions src/solvers/insert/insert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,72 +46,4 @@ function default_inserter(
state[v] *= phi
state = set_ortho_region(state, [v])
return state, nothing
end

function bp_inserter(
ψ::AbstractITensorNetwork,
ψAψ_bpcs::Vector{<:BeliefPropagationCache},
ψIψ_bpc::BeliefPropagationCache,
state::ITensor,
region;
cache_update_kwargs=(;),
kwargs...,
)
spec = nothing

form_network = unpartitioned_graph(partitioned_tensornetwork(ψIψ_bpc))
ψAψ_bpcs = BeliefPropagationCache[reset_messages(ψAψ_bpc) for ψAψ_bpc in ψAψ_bpcs]
ψIψ_bpc = reset_messages(ψIψ_bpc)
@show messages(ψIψ_bpc)
if length(region) == 1
states = [state]
elseif length(region) == 2
v1, v2 = region[1], region[2]
e = edgetype(ψ)(v1, v2)
pe = partitionedge(
ψIψ_bpc, ket_vertex(form_network, v1) => bra_vertex(form_network, v2)
)
stateᵥ₁, stateᵥ₂, spec = factorize_svd(
state, uniqueinds(ψ[v1], ψ[v2]); ortho="none", tags=edge_tag(e), kwargs...
)
states = noprime.([stateᵥ₁, stateᵥ₂])
#TODO: Insert spec into the message tensor guess here?!
end

for (i, v) in enumerate(region)
state = states[i]
state_dag = copy(state)
form_bra_v, form_ket_v = bra_vertex(form_network, v), ket_vertex(form_network, v)
ψ[v] = state
state_dag = replaceinds(
dag(state_dag), inds(state_dag), dual_index_map(form_network).(inds(state_dag))
)
ψAψ_bpcs = BeliefPropagationCache[
update_factor(ψAψ_bpc, form_ket_v, state) for ψAψ_bpc in ψAψ_bpcs
]
ψAψ_bpcs = BeliefPropagationCache[
update_factor(ψAψ_bpc, form_bra_v, state_dag) for ψAψ_bpc in ψAψ_bpcs
]
ψIψ_bpc = update_factor(ψIψ_bpc, form_ket_v, state)
ψIψ_bpc = update_factor(ψIψ_bpc, form_bra_v, state_dag)
end

ψAψ_bpcs = BeliefPropagationCache[
update(ψAψ_bpc; cache_update_kwargs...) for ψAψ_bpc in ψAψ_bpcs
]

ψIψ_bpc = update(ψIψ_bpc; cache_update_kwargs...)

updated_ψIψ = unpartitioned_graph(partitioned_tensornetwork(ψIψ_bpc))
numerator_terms = [
scalar(
unpartitioned_graph(partitioned_tensornetwork(ψAψ_bpc));
(cache!)=Ref(ψAψ_bpc),
alg="bp",
) for ψAψ_bpc in ψAψ_bpcs
]
eigval = sum(numerator_terms) / scalar(updated_ψIψ; (cache!)=Ref(ψIψ_bpc), alg="bp")
@show eigval
@show scalar(only(ψAψ_bpcs); alg="exact") / scalar(ψIψ_bpc; alg="exact")
return ψ, ψAψ_bpcs, ψIψ_bpc, spec, (; eigvals=[eigval])
end
end

0 comments on commit 54f41c0

Please sign in to comment.