-
Notifications
You must be signed in to change notification settings - Fork 125
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
[ITensors] Add docstrings for tr and update ITensor example #1186
Conversation
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #1186 +/- ##
===========================================
- Coverage 85.38% 67.38% -18.01%
===========================================
Files 88 87 -1
Lines 8405 8385 -20
===========================================
- Hits 7177 5650 -1527
- Misses 1228 2735 +1507
☔ View full report in Codecov by Sentry. |
src/mps/mpo.jl
Outdated
@@ -531,6 +531,15 @@ function logdot(M1::MPO, M2::MPO; make_inds_match::Bool=false, kwargs...) | |||
return _log_or_not_dot(M1, M2, true; make_inds_match=make_inds_match) | |||
end | |||
|
|||
""" | |||
tr(M::MPO, kwargs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(M::MPO, kwargs...) | |
tr(M::MPO; kwargs...) |
# the prime levels and tags. Indices that are not in pairs | ||
# are not traced over, corresponding to a "batched" trace. | ||
""" | ||
tr(T::ITensor, kwargs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(T::ITensor, kwargs...) | |
tr(T::ITensor; kwargs...) |
Thanks. Yeah, the idea was to allow specifying more general pairs of indices to trace over, say with a syntax: tr(A, i => j, k => l) but we could leave that for a future PR. I think I held off on it since I didn't come across a particular need for it yet and therefore wanted to wait to see if an application would help guide what the functionality and interface might be. I also believe I didn't document this function since I wasn't so sure about the For example, I could imagine a more general interface like: tr(A; mapinds=(i -> i'))
tr(A; mapinds=(i -> replacetags(i, "a" => "b"))) as a more general version of Explicitly specifying pairs of indices could even be handled through that common interface, for example: tr(A; mapinds=(x -> Dict(i => j, k => l)[x])) though of course we could have the convenient shorthand I think also it may be nice to think about how a tr(A::ITensorNetwork; mapinds=(i -> i')) = tr(ITensorNetworkMap(tn; mapinds)) The I think however those more general issues play out, the syntax |
Interesting. I really like the No problem to leave off the keyword args for now. We could tell users to simply prepare their tensors to have the same tags and the 0=>1 prime level patter for now. One very off-hand thought is that it might be interesting to unify the concept of an ITensorNetworkMap with the idea of a unitary ITensor, which would also "know" which are its two sets of indices. But that might be a bit of overkill as well. |
Another complication is that I'm not sure if the current implementation of I agree that the |
@@ -531,6 +531,11 @@ function logdot(M1::MPO, M2::MPO; make_inds_match::Bool=false, kwargs...) | |||
return _log_or_not_dot(M1, M2, true; make_inds_match=make_inds_match) | |||
end | |||
|
|||
""" | |||
tr(M::MPO; kwargs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(M::MPO; kwargs...) | |
tr(M::MPO) |
""" | ||
tr(M::MPO; kwargs...) | ||
|
||
Compute the trace of the MPO `M`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe cross reference tr(T::ITensor)
for which indices it traces over?
# the prime levels and tags. Indices that are not in pairs | ||
# are not traced over, corresponding to a "batched" trace. | ||
""" | ||
tr(T::ITensor; kwargs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tr(T::ITensor; kwargs...) | |
tr(T::ITensor) |
Trace an ITensor over pairs of indices determined by | ||
the optional prime levels and tags passed as keyword arguments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should reword to say it is over pairs of indices with prime levels 0 and 1.
This PR does the following:
tr(::ITensor)
tr(::MPO)
tr
function) and another more general case where one can use adelta
tensor.Do we want to allow users to provide Index objects to the
tr
function instead of using adelta
tensor? We could keep things as they are for now and consider this in the future.