Merge axes names after contraction
As discussed in https://github.com/google/TensorNetwork/issues/179, we should merge axes names after contraction and throw an error if the user tries to access an ambiguous name.
I can sure give this a try! One thing I'm immediately wondering is whether we should exploit a node's name to introduce uniqueness. I tend to reuse a name like "physical_index" for multiple MPS nodes, but I would give the nodes different names.
For instance, a Node Awith axis names [a, b, c]and another node B with the same axis names. After contracting the a axis we can return a Node with axis names [A_b, A_c, B_b, B_c] ... What do you think?
That might get messy once you start contracting multiple nodes together. Also, unless you specify a node name, the new node created after contraction will have a default name "__Node_X".
Yes, you are right. I always specify node names, but unless we make this a required property (which we should not I think), we can't assume the user will do this and than it can become a complete jungle very quickly.
Should we throw an error immediately when a contraction is done that leaves unambiguous axis, or delay this as long as possible (only for instance when user makes explicit reference to such axis name?)
I think when the user does it explicitly.
Currently we are throwing that error at Node creation time (see add_axis_names method)? Should we change this also and only throw errors when axis is requested not when names are added? Or treat nodes added and nodes created from contraction differently. The latter feels awkward to me.
@Thenerdstation You want it when user does it explicitly? See my remake above :)
Sorry for the late response.
I see what you mean by the latter feeling awkward, but right now I think it's the best compromise we can do. It makes sense to throw an error when a user writes it, as it can be easily fixed, but it's the best compromise we could come up with when the axis names collide after contraction.
Hey been looking at this project for a while, wanted to contribute. Seems like if you wanted to only throw an exception on lookup of a ambiguous axis name, instead of on creation of a node with ambiguous axis name, one could add an 'set_unsafe_axes_name' method to the base node with which to add axes_names to newly created nodes in contract_between and then throw an exception in the get_axis_number lookup function when a lookup is performed on the ambiguous name. Does that seem like a reasonable approach?
Also, would you want to try to retain axes names on an outer product call?
Yeah I think that seems ok by me! And yes please include this with outer_product
Great, I'm adding this behavior to contract_between, outer_product, and contract. Do we also want to preserve remaining axis names after a call to _contract_trace?
It also appears that _flatten_trace_edges reshapes the node tensor, but does not regenerate the axis_names list leaving a mismatching number of names. This differs from flatten_edges. I assume this is not intentional?
Yes, please include support for all of the functions you listed including _contract_trace.
And yes that is a bug. A PR for that would also be awesome! (they can be separate PRs).
was it fixed in the main package? how do I use the fixed version?