Skip to content

Commit

Permalink
Ket <-> Bra, Added Link Map to QuadraticForm
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Feb 8, 2024
1 parent 92e6a24 commit 3cd5222
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/Forms/construct_form.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ function Form(
operator::ITensorNetwork,
ket::ITensorNetwork;
dual_space_map=default_index_map,
link_space_map=default_index_map,
bra_vertex_map=default_bra_vertex_map,
ket_vertex_map=default_ket_vertex_map,
operator_vertex_map=default_operator_vertex_map,
form_type=default_form_type,
)
dual_map = map(dual_space_map, Indices(externalinds(bra)))
dual_map = map(dual_space_map, Indices(externalinds(ket)))

@assert Set(externalinds(bra)) == Set(externalinds(ket))
@assert Set(externalinds(operator)) ==
Expand All @@ -26,14 +27,17 @@ function Form(
bra_renamed = rename_vertices_itn(bra, bra_vs_map)
ket_renamed = rename_vertices_itn(ket, ket_vs_map)
operator_renamed = rename_vertices_itn(operator, operator_vs_map)
ket_renamed_dual = map_inds(dual_space_map, ket_renamed; links=[])
bra_renamed_dual = map_inds(dual_space_map, bra_renamed; links=[])

tn = union(union(bra_renamed, operator_renamed), ket_renamed_dual)
tn = union(union(bra_renamed_dual, operator_renamed), ket_renamed)

if form_type == "Bilinear"
return BilinearForm(tn, bra_vs_map, ket_vs_map, operator_vs_map, dual_map)
elseif form_type == "Quadratic"
return QuadraticForm(tn, bra_vs_map, ket_vs_map, operator_vs_map, dual_map)
link_map = map(link_space_map, Indices(internalinds(ket)))
return QuadraticForm(
tn, bra_vs_map, ket_vs_map, operator_vs_map, dual_map, link_space_map
)
else
return error("Form type not supported")
end
Expand Down
27 changes: 18 additions & 9 deletions src/Forms/quadraticform.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
struct QuadraticForm{V,KetMap,BraMap,OperatorMap,SpaceMap} <:
AbstractForm{V,KetMap,BraMap,OperatorMap,SpaceMap}
struct QuadraticForm{V,KetMap,BraMap,OperatorMap,VectorSpaceMap,LinkSpaceMap} <:
AbstractForm{V,KetMap,BraMap,OperatorMap,VectorSpaceMap}
tn::ITensorNetwork{V}
bra_vs_map::BraMap
ket_vs_map::KetMap
operator_vs_map::OperatorMap
dual_space_map::SpaceMap
dual_space_map::VectorSpaceMap
link_space_map::LinkSpaceMap
end

#Needed for implementation
Expand All @@ -17,22 +18,22 @@ data_graph_type(::Type{<:QuadraticForm}) = data_graph_type(tensornetwork(qf))
data_graph(qf::QuadraticForm) = data_graph(tensornetwork(qf))

function QuadraticForm(
bra::ITensorNetwork, operator::ITensorNetwork; link_space_map=default_index_map, kwargs...
ket::ITensorNetwork, operator::ITensorNetwork; link_space_map=default_index_map, kwargs...
)
ket = link_space_map(dag(bra); sites=[])
return Form(bra, operator, ket; form_type="Quadratic", kwargs...)
bra = link_space_map(dag(ket); sites=[])
return Form(bra, operator, ket; form_type="Quadratic", link_space_map, kwargs...)
end

function QuadraticForm(
bra::ITensorNetwork;
ket::ITensorNetwork;
dual_space_map=default_index_map,
tno_constructor=default_tno_constructor,
kwargs...,
)
s = siteinds(bra)
s = siteinds(ket)
operator_space = union_all_inds(s, dual_space_map(s; links=[]))
operator = tno_constructor(operator_space)
return QuadraticForm(bra, operator; kwargs...)
return QuadraticForm(ket, operator; kwargs...)
end

function bra_ket_vertices(qf::QuadraticForm, state_vertices::Vector)
Expand All @@ -59,3 +60,11 @@ function gradient(
reduced_tn, _ = induced_subgraph(tensornetwork(qf), tn_vertices)
return contract(reduced_tn, contractor_kwargs...)
end

function update_qf!(qf::QuadraticForm, state_vertex, state::ITensor)
setindex_preserve_graph!(tensornetwork(qf)[ket_map(state_vertex)], state, state_vertex)
#Change to be consistent with dual space map and link space map. How can we do this elegantly??
return setindex_preserve_graph!(
tensornetwork(qf)[bra_map(state_vertex)], prime(dag(state)), state_vertex
)
end

0 comments on commit 3cd5222

Please sign in to comment.