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

Relax `push!` constrains under specific conditions #147

Closed jofrevalles closed 3 weeks ago

jofrevalles commented 1 month ago

Summary

A common procedure in Tensor Networks is replacing some given tensors with new ones. For example, we may have an mps and evolve it with some operator to obtain new tensors, which share the same indices but change their size. The way to do this in now Tenet I believe is quite cumbersome, and could be improved if we relaxed the conditions in push!. Currently, Tenet checks that the new pushed tensor does match in size for all their indices. This can be a problem if we wanted to update a tensor T that has increased in bond dimension, but we still have not computed its neighbor tensor that shares indices with. My suggestion is that we can put a keyword argument in replace! that relaxes the mentioned constrains in push!.

mofeing commented 1 month ago

Allowing users to push tensors with different index sizes is something that scares me due to the possibility of introducing subtle and difficult to track bugs.

But I completely agree that this makes some code super cumbersome.

My idea for this is that we could allow this but through a higher-level interface such that Tenet still checks the dimensions but (and this is the key) after a wrapped region (and not on each push! call).

Here is a prototype code:

Tenet.@unsafe_region tn begin
    # here go the push!, pop!, replace!, ...
    ...
end

When this block of code finishes, Tenet will check if the index dimensions remain consistent and throw an error if not.

jofrevalles commented 1 month ago

I like this idea!

mofeing commented 3 weeks ago

Implemented in #149