Refactor TensorNetwork type; add NormNetwork struct. #119
Conversation
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.
…type; other small changes.
… the `stopping_criterion` kwarg.
Co-authored-by: Matthew Fishman <mtfishman@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #119 +/- ##
==========================================
- Coverage 73.30% 65.32% -7.98%
==========================================
Files 21 19 -2
Lines 929 845 -84
==========================================
- Hits 681 552 -129
- Misses 248 293 +45
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Your PR no longer requires formatting changes. Thank you for your contribution! |
1310cc2 to
7c51b20
Compare
| B = conjbra(nn, vertex) | ||
| # TODO: implement and use a lazy `conj` via `LazyNamedDimsArrays` here? | ||
| return lazy(A) * lazy(conj(B)) |
There was a problem hiding this comment.
Maybe we can define bra(nn, vertex) = conj(conjbra(nn, vertex))? Agreed we should probably define a lazy conj, it is something that has come up a few places, but eager is ok for now.
| ket(nn::NormNetwork, vertex) = nn.tensornetwork[vertex] | ||
| conjbra(nn::NormNetwork, vertex) = replacedimnames(n -> namemap(nn, n), ket(nn, vertex)) | ||
|
|
||
| lazy_norm(tn::TensorNetwork) = NormNetwork(tn) |
There was a problem hiding this comment.
I think we were calling this norm_network in ITensorNetworksNext. I kind of prefer that name since it indicates what kind of lazy representation it is, i.e. one could imagine lazy_norm might output a lazy expression for the norm. I think norm_network is a bit more descriptive.
| return tn | ||
| end | ||
| # Return the vertices associated with an index. | ||
| function indsites(tn::AbstractGraph, ind) |
| for e in edges(graph) | ||
| show(io, mime, e) | ||
| println(io) | ||
| function has_indname(tn::AbstractGraph, name) |
| index_map = Dictionary{I, I}() | ||
| for (name, vertices) in pairs(tn.index_locations) | ||
| if length(vertices) == 2 | ||
| insert!(index_map, name, randname(name)) |
There was a problem hiding this comment.
It might be nice to have an interface where we can specify the ket names (say if you have a set of messages and want a norm network that matches the names of the messages).
| function TensorNetwork(f::Base.Callable, graph::AbstractGraph) | ||
| return TensorNetwork(graph, Dictionary(map(f, vertices(graph)))) | ||
| end | ||
| for ind in dimnames(tensor) |
There was a problem hiding this comment.
The terminology is definitely kind of tricky. I think if something is just a name, we should refer to it as dimname or name. In my mind, ind would refer to a named axis, though I've gone back and forth about whether we should still use the ind/inds terminology from ITensors.jl or embrace the axis/axes terminology from Base Julia...
|
|
||
| struct TensorNetwork{T, V, I} <: AbstractTensorNetwork{T, V} | ||
| tensors::Dictionary{V, T} | ||
| index_locations::Dictionary{I, Set{V}} |
There was a problem hiding this comment.
Maybe a better name would be dimname_vertices.
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.