You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed that the @unsafe_region macro, when applied to a specific TensorNetwork, actually affects all tensor networks within its block, even those not specified. This behavior is unexpected and can lead to potential silent errors.
In this code the @unsafe_region macro is applied only to tn. Inside the block, we also manipulate tn2, which is not specified in the macro. We expect push!(tn2, tensor) to throw a DimensionMismatch error due to inconsistent indices. However, no error is thrown, indicating that @unsafe_region is affecting tn2 as well.
Possible Solutions:
Restrict the scope to specified TensorNetworks:
Modify the @unsafe_region macro to ensure that it only affects the tensor networks explicitly listed.
Change macro to reflect global scope:
If the intended behavior is to apply to all tensor networks within the block, we can consider changing the macro to not require specifying any tensor networks.
For example:
@unsafe_regionbegin# no tn passed as argument here# Code hereend
This would make it clear to users that all tensor networks are affected within the block.
The text was updated successfully, but these errors were encountered:
Summary of the meeting between me and @jofrevalles:
In the particular example above, a second @unsafe_region should be use for tn2
There are cases where the a new TN is created deep inside the call stack and cannot be marked as "unsafe" (e.g. calling adjoint(tn) where tn is unsafe). It's this kind of cases which are considered a bug in this issue.
The solution we agreed to is adding a new unsafe::Ref{Bool} field to TensorNetwork which controls consistency checks in push! and remove the global flag. This way, when copying a TensorNetwork, the field will be propagated and will know that it's unsafe too.
This method has some potential issues like if we copy the Ref as it is, then both TNs will get their values shared. If instead, we don't copy the Ref as it is but we create a new Ref and we copy the value, then the 2nd TN won't know when to run the consistency checks because it won't get notified that the @unsafe_region has ended.
I prefer to bet for the second option of copying the Bool and create a new Ref, and let's figure out how to solve this issue with @unsafe_region once we have the PR.
Summary
I've noticed that the
@unsafe_region
macro, when applied to a specificTensorNetwork
, actually affects all tensor networks within its block, even those not specified. This behavior is unexpected and can lead to potential silent errors.Example
In this code the
@unsafe_region
macro is applied only totn
. Inside the block, we also manipulatetn2
, which is not specified in the macro. We expectpush!(tn2, tensor)
to throw aDimensionMismatch
error due to inconsistent indices. However, no error is thrown, indicating that@unsafe_region
is affectingtn2
as well.Possible Solutions:
TensorNetwork
s:@unsafe_region
macro to ensure that it only affects the tensor networks explicitly listed.For example:
This would make it clear to users that all tensor networks are affected within the block.
The text was updated successfully, but these errors were encountered: