Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeyT1994 committed Feb 12, 2024
1 parent b0a46f0 commit ef930ce
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/FormNetworks/abstractformnetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
)
Expand Down
2 changes: 1 addition & 1 deletion src/FormNetworks/bilinearformnetwork.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 18 additions & 6 deletions src/FormNetworks/quadraticformnetwork.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions test/test_forms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

0 comments on commit ef930ce

Please sign in to comment.