From 002662360b65994db12d3745275ec8a8254505fd Mon Sep 17 00:00:00 2001 From: Joey Date: Fri, 12 Apr 2024 11:10:18 -0400 Subject: [PATCH] Construct correct identity_network in BiLinearFormNetwork --- src/formnetworks/bilinearformnetwork.jl | 2 +- src/itensornetwork.jl | 12 ++++++++---- test/test_forms.jl | 1 - 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/formnetworks/bilinearformnetwork.jl b/src/formnetworks/bilinearformnetwork.jl index b7408e4c..bcb59704 100644 --- a/src/formnetworks/bilinearformnetwork.jl +++ b/src/formnetworks/bilinearformnetwork.jl @@ -59,7 +59,7 @@ function BilinearFormNetwork( ) @assert issetequal(externalinds(bra), externalinds(ket)) operator_inds = union_all_inds(siteinds(ket), dual_site_index_map(siteinds(ket))) - O = delta_network(operator_inds) + O = ITensorNetwork(Op("I"), operator_inds) return BilinearFormNetwork(O, bra, ket; dual_site_index_map, kwargs...) end diff --git a/src/itensornetwork.jl b/src/itensornetwork.jl index 96f4b604..a2d4af3f 100644 --- a/src/itensornetwork.jl +++ b/src/itensornetwork.jl @@ -164,10 +164,14 @@ function generic_state(a::AbstractArray, inds::Vector) end function generic_state(x::Op, inds::NamedTuple) # TODO: Figure out what to do if there is more than one site. - @assert length(inds.siteinds) == 2 - i = inds.siteinds[findfirst(i -> plev(i) == 0, inds.siteinds)] - @assert i' ∈ inds.siteinds - site_tensors = [op(x.which_op, i)] + if !isempty(inds.siteinds) + @assert length(inds.siteinds) == 2 + i = inds.siteinds[findfirst(i -> plev(i) == 0, inds.siteinds)] + @assert i' ∈ inds.siteinds + site_tensors = [op(x.which_op, i)] + else + site_tensors = [] + end link_tensors = [[onehot(i => 1) for i in inds.linkinds[e]] for e in keys(inds.linkinds)] return contract(reduce(vcat, link_tensors; init=site_tensors)) end diff --git a/test/test_forms.jl b/test/test_forms.jl index 4ff3e2d0..a9a0e453 100644 --- a/test/test_forms.jl +++ b/test/test_forms.jl @@ -8,7 +8,6 @@ using ITensorNetworks: QuadraticFormNetwork, bra_network, bra_vertex, - delta_network, dual_index_map, environment, externalinds,