Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility with tensor networks without internal vertices #144

Closed
wants to merge 3 commits into from

Conversation

b-kloss
Copy link
Contributor

@b-kloss b-kloss commented Mar 7, 2024

This PR addresses some issues related to using Tensor Networks where the vertex_data at some vertices is empty, e.g. Index[]. In particular the behaviour of check_hascommoninds which is for example called when computing an inner product between two tensor networks is now comparing empty vertex_data as equal. A test has been added that verifies that an inner product can be taken.

ToDo:

  • Maybe move test for missing siteinds functionality to a different file.
  • Fix issue with specific state constructor for the case of missing siteinds. For example, TTN(s,"Up") is currently not functional if s is an IndsNetwork where at least one vertex has empty vertex_data.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 33.33333% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 73.55%. Comparing base (3eb5362) to head (576bed3).

Files Patch % Lines
src/abstractitensornetwork.jl 33.33% 4 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #144      +/-   ##
==========================================
- Coverage   73.62%   73.55%   -0.08%     
==========================================
  Files          70       70              
  Lines        4118     4122       +4     
==========================================
  Hits         3032     3032              
- Misses       1086     1090       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +801 to +805
if isempty(siteinds(A, v))
!isempty(siteinds(B, v)) && return false
else
!hascommoninds(siteinds(A, v), siteinds(B, v)) && return false
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused by this change. It seems like this catches the case when A doesn't have site indices on vertex v, but B has site indices on vertex v. That seems like a case that hascommoninds should be working for. What goes wrong in hascommoninds in that case?

Copy link
Contributor Author

@b-kloss b-kloss Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When A doesn't have site indices on vertex v, but B has site indices on vertex v, it will return false, while it will continue the loop if both don't have site indices on vertex v. The false would indeed also be caught in the else clause, so it would indeed be more transparent to write

if isempty(siteinds(A,v)) && isempty(siteinds(B,v))
   continue
else
....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks. I see that is a strange corner case. See my comment #144 (comment), I think it would be simpler to just remove these functions entirely, since they are likely doing more harm than good, and we can reassess what kind of checks we really want in this functions, if any.

!hascommoninds(siteinds(A, v), siteinds(B, v)) && error(
"$(typeof(A)) A and $(typeof(B)) B must share site indices. On vertex $v, A has site indices $(siteinds(A, v)) while B has site indices $(siteinds(B, v)).",
)
if isempty(siteinds(A, v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like check_hascommoninds could just call hascommoninds(siteinds, A, B) and return nothing if it is true and error if it is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Comment on lines 798 to 799
::typeof(siteinds), A::AbstractITensorNetwork{V}, B::AbstractITensorNetwork{V}
) where {V}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::typeof(siteinds), A::AbstractITensorNetwork{V}, B::AbstractITensorNetwork{V}
) where {V}
::typeof(siteinds), A::AbstractITensorNetwork, B::AbstractITensorNetwork
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for check_hascommoninds.

Comment on lines +259 to +261
# ToDo: move to a more appropriate file, since this is not related to OpSum to TTN conversion
# test whether Hamiltonian contracts with itself (used to error due to missing siteindices)
@test isa(inner(Hsvd, Hsvd), Number)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Also, it would be good to add tests for hascommoninds and check_hascommoninds with missing site indices.

@mtfishman
Copy link
Member

@b-kloss another approach here would be to just remove hascommoninds(::typeof(siteinds), A::AbstractITensorNetwork, B::AbstractITensorNetwork) and check_hascommoninds(::typeof(siteinds), A::AbstractITensorNetwork, B::AbstractITensorNetwork), I think basically they were copied over to this package from the MPS code in ITensors.jl where we were being more strict about inputs of certain functions but they may be more trouble than they are worth, and inherently may restrict the tensor network structure of certain functions more than we want in general.

This was referenced Mar 27, 2024
@mtfishman
Copy link
Member

This was addressed in #148.

@mtfishman mtfishman closed this Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants