diff --git a/src/FormNetworks/abstractformnetwork.jl b/src/FormNetworks/abstractformnetwork.jl index e23424ba..83ce06ed 100644 --- a/src/FormNetworks/abstractformnetwork.jl +++ b/src/FormNetworks/abstractformnetwork.jl @@ -34,13 +34,13 @@ end function Graphs.induced_subgraph(f::AbstractFormNetwork, vertices::Vector) return induced_subgraph(tensornetwork(f), vertices) end -function bra(f::AbstractFormNetwork) +function bra_network(f::AbstractFormNetwork) return rename_vertices(inv_vertex_map(f), first(induced_subgraph(f, bra_vertices(f)))) end -function ket(f::AbstractFormNetwork) +function ket_network(f::AbstractFormNetwork) return rename_vertices(inv_vertex_map(f), first(induced_subgraph(f, ket_vertices(f)))) end -function operator(f::AbstractFormNetwork) +function operator_network(f::AbstractFormNetwork) return rename_vertices( inv_vertex_map(f), first(induced_subgraph(f, operator_vertices(f))) ) diff --git a/src/FormNetworks/bilinearformnetwork.jl b/src/FormNetworks/bilinearformnetwork.jl index ecbbe01b..a502ecc0 100644 --- a/src/FormNetworks/bilinearformnetwork.jl +++ b/src/FormNetworks/bilinearformnetwork.jl @@ -48,5 +48,5 @@ function BilinearFormNetwork( ) operator_inds = union_all_inds(siteinds(bra), siteinds(ket)) O = delta_network(operator_inds) - return BilinearFormNetwork(bra, O, ket; kwargs...) + return BilinearFormNetwork(O, bra, ket; kwargs...) end diff --git a/src/FormNetworks/quadraticformnetwork.jl b/src/FormNetworks/quadraticformnetwork.jl index fff50740..3189d786 100644 --- a/src/FormNetworks/quadraticformnetwork.jl +++ b/src/FormNetworks/quadraticformnetwork.jl @@ -1,10 +1,11 @@ default_index_map = prime default_inv_index_map = noprime -struct QuadraticFormNetwork{V,FormNetwork<:BilinearFormNetwork{V},IndexMap} <: +struct QuadraticFormNetwork{V,FormNetwork<:BilinearFormNetwork{V},IndexMap,InvIndexMap} <: AbstractFormNetwork{V} formnetwork::FormNetwork dual_index_map::IndexMap + dual_inv_index_map::InvIndexMap end bilinear_formnetwork(qf::QuadraticFormNetwork) = qf.formnetwork @@ -13,10 +14,11 @@ function QuadraticFormNetwork( bra::AbstractITensorNetwork, ket::AbstractITensorNetwork; dual_index_map=default_index_map, + dual_inv_index_map=default_inv_index_map, kwargs..., ) return QuadraticFormNetwork( - BilinearFormNetwork(operator, bra, ket; kwargs...), dual_index_map + BilinearFormNetwork(operator, bra, ket; kwargs...), dual_index_map, dual_inv_index_map ) end @@ -37,27 +39,37 @@ for f in [ end dual_index_map(qf::QuadraticFormNetwork) = qf.dual_index_map +dual_inv_index_map(qf::QuadraticFormNetwork) = qf.dual_inv_index_map function copy(qf::QuadraticFormNetwork) - return QuadraticFormNetwork(copy(bilinear_formnetwork(qf)), dual_index_map(qf)) + return QuadraticFormNetwork( + copy(bilinear_formnetwork(qf)), dual_index_map(qf), dual_inv_index_map(qf) + ) end function QuadraticFormNetwork( operator::AbstractITensorNetwork, ket::AbstractITensorNetwork; dual_index_map=default_index_map, + dual_inv_index_map=default_inv_index_map, kwargs..., ) bra = map_inds(dual_index_map, dag(ket)) - return QuadraticFormNetwork(operator, bra, ket; dual_index_map, kwargs...) + blf = BilinearFormNetwork(operator, bra, ket; kwargs...) + return QuadraticFormNetwork(blf, dual_index_map, dual_inv_index_map) end function QuadraticFormNetwork( - ket::AbstractITensorNetwork; dual_index_map=default_index_map, kwargs... + ket::AbstractITensorNetwork; + dual_index_map=default_index_map, + dual_inv_index_map=default_inv_index_map, + kwargs..., ) s = siteinds(ket) operator_inds = union_all_inds(s, dual_index_map(s; links=[])) operator = delta_network(operator_inds) - return QuadraticFormNetwork(operator, ket; kwargs...) + bra = map_inds(dual_index_map, dag(ket)) + blf = BilinearFormNetwork(operator, bra, ket; kwargs...) + return QuadraticFormNetwork(blf, dual_index_map, dual_inv_index_map) end function bra_ket_vertices(qf::QuadraticFormNetwork, state_vertices::Vector) diff --git a/test/test_forms.jl b/test/test_forms.jl index c391bd53..74982629 100644 --- a/test/test_forms.jl +++ b/test/test_forms.jl @@ -9,9 +9,9 @@ using ITensorNetworks: bra_vertex_map, ket_vertex_map, dual_index_map, - bra, - ket, - operator + bra_network, + ket_network, + operator_network using Test using Random @@ -30,9 +30,9 @@ using Random @test nv(blf) == nv(ψket) + nv(ψbra) + nv(A) @test isempty(externalinds(blf)) - @test underlying_graph(ket(blf)) == underlying_graph(ψket) - @test underlying_graph(operator(blf)) == underlying_graph(A) - @test underlying_graph(bra(blf)) == underlying_graph(ψbra) + @test underlying_graph(ket_network(blf)) == underlying_graph(ψket) + @test underlying_graph(operator_network(blf)) == underlying_graph(A) + @test underlying_graph(bra_network(blf)) == underlying_graph(ψbra) qf = QuadraticFormNetwork(A, ψket) @test nv(qf) == 2 * nv(ψbra) + nv(A) @@ -46,6 +46,6 @@ using Random dual_index_map(qf_updated)(dag(new_tensor)) @test tensornetwork(qf_updated)[ket_vertex_map(qf_updated)(v)] ≈ new_tensor - @test underlying_graph(ket(qf)) == underlying_graph(ψket) - @test underlying_graph(operator(qf)) == underlying_graph(A) + @test underlying_graph(ket_network(qf)) == underlying_graph(ψket) + @test underlying_graph(operator_network(qf)) == underlying_graph(A) end