bsc-quantic / Tenet.jl

Composable Tensor Network library in Julia
https://bsc-quantic.github.io/Tenet.jl/
Apache License 2.0
17 stars 1 forks source link

Enhance `replace!(tn::TensorNetwork, ...)` function for more flexible `Tensor` replacements #56

Closed jofrevalles closed 1 month ago

jofrevalles commented 1 year ago

Summary

Currently, the replace! function can replace a Tensor within a TensorNetwork but only under the condition that the new Tensor has the same labels as the original one. This restriction imposes a considerable limitation on our usage of this function, especially in scenarios where we might want to replace a tensor with another one that differs in size and consequently, in labels.

At the moment, this implementation could potentially introduce problems. Specifically, the TensorNetwork has an inds field that links indexes with tensors. In its current form, we cannot add a new index to a TensorNetwork because of the immutable nature of this struct.

The recent refactor presented in PR #55 removes the inds field, allowing a more generalized replacement of tensors like the one just explained.

jofrevalles commented 1 year ago

Marked with the "on hold" label, since we are waiting for the new refactor to be merged

mofeing commented 1 year ago

55 includes a new replace! method that can replace a Tensor with a TensorNetwork as long as the open indices of the TensorNetwork match the labels of the Tensor.

jofrevalles commented 1 year ago

We could now enhance the replace! function so it enables the replacement of tensors that have different labels. However, we should discuss how we want that and what happens to the other tensors connected to the replaced tensor.

jofrevalles commented 1 year ago

Update: this can be already implemented

mofeing commented 1 year ago

Update: this can be already implemented

But we haven't discussed the semantics yet... I have concerns on adding new labels not in the Tensor Network (or renaming) or resizing an index from a Tensor.

If you suggest some coherent semantics, I will consider them.

mofeing commented 1 month ago

@jofrevalles I think we can close this since we now have @unsafe_region right?

jofrevalles commented 1 month ago

Yes!