Refactor TensorNetwork type; add NormNetwork struct. #119
Refactor TensorNetwork type; add NormNetwork struct. #119jack-dunham wants to merge 112 commits into
TensorNetwork type; add NormNetwork struct. #119Conversation
Introduce `BeliefPropagationProblem` wrapper to hold the cache and the error `diff` field. Also simplifies some kwargs wrangling.
…be set from another cache
Also includes some fixes to the way `TensorNetwork` types are constructed based on index structure.
for more information, see https://pre-commit.ci
…instead of trying to operate on existing graphs The reason for this is: - One only cares about the edges of the input graph - A simple graph cannot be used as it "forgets" its edge names resulting in recursion - As shown with `TensorNetwork`, removing edges may not always be defined.
…s from an array.
This was caused by the change to the `cache` being backed by a directed graph.
Defaults to one constructed via `randname`.
for more information, see https://pre-commit.ci
This local refers to a index name not an index itself.
|
|
||
| """ | ||
| similar_norm_message_env(tn) -> MessageCache | ||
| ketnames = linknames(KetView(nn), edge) |
There was a problem hiding this comment.
| ketnames = linknames(KetView(nn), edge) | |
| ketnames = linknames(ketview, edge) |
|
|
||
| # ====================================== interface ======================================= # | ||
|
|
||
| tensornetwork(nn::NormNetwork) = nn.tensornetwork |
There was a problem hiding this comment.
This doesn't seem like a good definition, my first reaction was that it converts to a flat TN (i.e. would flatten the bra with the ket). Field access or KetView seem like fine alternatives.
| function namemap(nn::NormNetwork, name) | ||
| if !has_dimname(nn.tensornetwork, name) | ||
| error("index name $name not found underlying tensor network.") | ||
| end | ||
| return get(nn.namemap, name, name) | ||
| end |
There was a problem hiding this comment.
Is this supposed to take a ket name and map it to the corresponding bra name? If so I think a more descriptive name like braname would be better. Also, I'm confused by get(nn.namemap, name, name), if the name is already checked to be in the ket, why do we need get? Why not nn.namemap[name]? I.e. what would the fallback be for?
|
|
||
| indmap(nn::NormNetwork, ind) = setname(conj(ind), namemap(nn, name(ind))) | ||
|
|
||
| ket(nn::NormNetwork, vertex) = nn.tensornetwork[vertex] |
There was a problem hiding this comment.
I'd prefer something more descriptive like ket_tensor to make it clearer what it is returning.
| # environment-builder interface; the low-level `MessageCache` / `messagecache(...)` | ||
| # constructors are used internally. A parallel `*_norm_ctm_env` family is planned for | ||
| # CTMRG environments. | ||
| function message_environment(::UndefInitializer, nn::NormNetwork) |
There was a problem hiding this comment.
This is clever syntax, but I'd prefer the style similar_message_environment(nn::NormNetwork), I've only seen undef used for constructors (i.e. constructors that take types).
| the name of the corresponding index in the bra layer. | ||
| """ | ||
| struct NormNetwork{T, V, I} <: AbstractITensorNetwork{T, V} | ||
| tensornetwork::ITensorNetwork{T, V, I} |
There was a problem hiding this comment.
Maybe a clearer name for this field would be ket or ket_network.
| # Contract a (possibly double-layer) network into a single tensor by multiplying all | ||
| # of its vertex tensors together. For a `NormNetwork` the vertex data are lazy products | ||
| # `ket * conj(bra)`, so the result is a lazy expression that we materialize. | ||
| contract(tn) = materialize(prod(tn)) |
There was a problem hiding this comment.
Probably should call this contract_network to not have it confused with TensorAlgebra.contract.
This PR refactors the
TensorNetworkdata type to include a reverse index map, and to be stricter about it's construction and how it's tensors can be set.This PR also adds
NormNetworktype, as a wrapper around aTensorNetwork, to represent the norm of a tensor network.