-
Notifications
You must be signed in to change notification settings - Fork 27
Add CTMRG support for regular 2D partition functions #111
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
Add CTMRG support for regular 2D partition functions #111
Conversation
lkdvos
left a comment
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.
Starting to look good!
I left some remarks alreayd, but some general remarks here:
For the docstrings, I don't think, it makes sense to have separate docstrings for both the partition function and PEPS (and eventually PEPO) implementations. Rather, we could use A in the figure, and then specify that A might be either bra-ket, partition function or bra-pepo-ket combinations. As a result, we should probably also agree on a style of drawings (let's do this in a separate PR) that uses the same character for drawing tensor connections, and maybe either never draw boxes around tensors or always draw boxes.
(I am assuming that you left some of the docstrings unattached to functions on purposes as this is still a WIP port?)
For naming things, InfinitePartitionFunction seems like the best we can do, since I really cannot come up with anything better. Given that it is rather long, how would you feel about InfinitePF, similar to InfinitePEPS? (Along with PFTensor etc)
Sounds good, I'll try to standardize as much as I can here. I agree we should be more systematic about the diagrams, I'm happy to put some effort into that soon.
I don't really like the 'PF' acronym, for the simple reason that no one really uses it so there's no way of knowing what it means without actually reading the docstring. This is quite different for 'PEPS' I think. I'd be happy to use the shorter names as internal aliases, but I wouldn't like to export |
Add internal convenience aliases for different flavors of edge tensors Co-authored-by: Lukas Devos <ldevos98@gmail.com>
|
Thanks a lot for the effort! To me the PR mostly looks quite nice already. On the topic of naming things: I am a bit confused by calling the Also: let me know if I can contribute or finish up something! I anyway wanted to add 2D partition function support at some point so I'm happy to help. |
I agree using 'partition function' might imply some additional physical properties rather than just a network structure, which is really only what we mean here. The reason we didn't just reuse I would personally be okay with using the term 'partition function' for things with no stat mech origin, or at least more than I would be with using 'MPO' for 2D network structures. We could also go for |
|
Well, in principle partition functions could also be a 1D or 3D thing, right? So I feel a bit icky about using I do think it could make sense to use the |
|
To be fair, matrix product operator really does not make too much sense either in the 2D grid case... |
|
The I'll finish up the rest tomorrow :-) |
|
There is a design decision to be made if we want to generalize our CTMRG code to also support different ket and bras, as well as PEPOs, and I'm not sure what the best way forward is. Right now, all CTMRG contractions support different The problem is that there is no |
I think it makes sense to have all the lowest level methods for things like
I don't know if having these as actual types is necessary, it might be but it's not clear to me. Just a union type of tuples for all different possible sandwiches would do the job to start. I certainly don't think it makes sense to make these potential full sandwich types subtypes of
I'm a bit biased of course since I want to start using this as soon as I can, but purely in terms of compartmentalizing features I think it would make sense to just restrict this PR to working partition functions. Just to keep additions from growing bigger and bigger I would break out additional discussions as issues or follow up PRs. Of course I'm not in that much of a rush, but it seems we're moving away from the initial purpose a bit already. |
|
I'm certainly not against that. I know we previously have done so, and called it PEPSSandwich, and PEPOSandwich. I do quite like those names 😉 [edit] |
I have also considered this but the problem with tuples as sandwiches is that you need to be able to index the sandwich. But I do agree that it doesn't make sense to subtype the sandwiches as Anyways, I agree that we're putting too many additions into this PR and should probably generalize the CTMRG interface in another PR - I will open up an issue! I will finish up the contraction business and then the PR is good to go for me. |
|
Alright, I'd be fine with merging this as is :-) (once the lights turn green) |
|
I added an Aside from that, while the generalization of the local tensor contraction is nice, it's not covered by the tests and to be honest I can't immediately think of a relevant test withing the current test model. It's also not really clear to me what the I at least added a docstring to indicate what the current possibilities are. I guess since there's no concrete use case for the more general methods right now this is fine for the time being. |
That's true and I'd like to add tests. Locally, I tested that at least the code runs and captures all the cases I could think of. To test for correctness, it would be nice to at least compare to an Ising correlation function perhaps? I'm not sure if there are exact expressions/integrals we could reference against.
You do need the |
To just check the code I think we could use a 2x2 patch with one magnetization/energy tensor and the other three just regular partition function tensors, both in matrix form and blocked to cover all cases.
I see. Then the docstring I added should cover the proper usage I think, and maybe we could add a consistency check on the rank after determining the patch size from the given |
Good ideas! I will cook this up now. |
lkdvos
left a comment
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.
I left a few remarks in the code, but honestly this is getting absolutely intractable to make sense of what is going on... (+1833,-519) lines of code, split over multiple topics is really hard to follow...
For future PRs, I would suggest we try and keep features and changes separated into different PRs, and before making large organizational overhauls, make sure that everyone is on board with the changes?
Let's try and simplify this so we can merge this ASAP, and then re-evaluate what needs to change. I would suggest the following:
- This PR is mostly about having CTMRG for partition functions, so I would really refrain from going overboard with the features such as elaborate
expectation_valuevariants, which we can definitely add in a separate PR. Can we maybe fix the argument order to have the interface in line with MPSKit, and simply have a working implementation of just inserting an operator into the partition function? We can always refactor later. - Given that this is now intimately tied to the
InfiniteSquareNetworkrewrite, I'm okay with merging that as is, but can we re-discuss how we want to organize that here: #116, and then decide on an implementation afterwards? - Can we open a separate issue/PR for a round of docstring fixes where we first decide on a style, and then work together to implement that?
src/algorithms/toolbox.jl
Outdated
| Alternatively, `O` can be a single higher-rank tensor map, in which case it is inserted | ||
| inside a rectangular region defined by the indices in `inds`, where in addition to the |
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.
This sounds to me like something that is not too well defined. It's a bit odd to me to now all of a sudden use inds to signify rectangular regions instead of actual positions, and since we don't have any conventions for how this plaquette tensor would then look like, why are we defining this? Can we simply do this later?
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.
Yes, there is an ambiguity in working with higher-rank tensor maps and supplying the inds. The annoying thing in the current implementation is that only really the indices that specify the corners of the rectangular patch matter, so I agree that it's not a nice way of implementing multi-site operators.
Maybe to restore the original way of using the inds we could also do the following: Instead of supplying a higher-rank tensor map or matrix of tensor maps, we could just supply a tuple of Pair{CartesianIndex(2),TensorMap{S,2,2}} (similar to how a LocalOperator works) as well as the partition function to the contract_local_tensor function. Then the supplied tensors would just replace the partition function on the supplied indices. (If no tensors are supplied, then the function just computes the norm as in contract_local_norm.)
I don't want to further blow up the PR so I'm also happy to go for a simpler alternative. But I think the main contractions are already implemented to generalize the partition function operator evaluation to it should just be a matter of reorganizing that.
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.
Yes, there is an ambiguity in working with higher-rank tensor maps and supplying the
inds. The annoying thing in the current implementation is that only really the indices that specify the corners of the rectangular patch matter, so I agree that it's not a nice way of implementing multi-site operators.
For now, I would just remove the higher-rank tensor case. It's a bit random to come up with an interface for this kind of thing if we don't even have a use case in mind. Since this is making things more difficult here, I suggest we drop it altogether and think about reintroducing it once we have a specific need for it.
Maybe to restore the original way of using the
indswe could also do the following: Instead of supplying a higher-rank tensor map or matrix of tensor maps, we could just supply a tuple ofPair{CartesianIndex(2),TensorMap{S,2,2}}(similar to how aLocalOperatorworks) as well as the partition function to thecontract_local_tensorfunction. Then the supplied tensors would just replace the partition function on the supplied indices. (If no tensors are supplied, then the function just computes the norm as incontract_local_norm.)
This seems reasonable, and also allows to solve the above issues. I don't really see the need to have a version of contract_local_tensor where no tensors are supplied though. It would be more transparent to just do the explicit call where you pass the partition function tensors (I assume you're referring to the denominator in expectation_value?). A rename to contract_local_tensors would then be appropriate of course...
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.
I would definitely agree that we should scrap the AbstractTensorMap{S,M,M} case since that is not nice to work with and to implement.
I could still see that the rest is salvageable :-) I don't find the case of correlation functions too random - so if someone wants to evaluate e.g. nearest-neighbor correlators that is not super exotic, right? If you want I could still try to clean up/simplify the general contraction mechanism using Vector{Pair{CartesianIndex{2},AbstractTensorMap{S,2,2}}} so that it is more in line with the LocalOperator way of computing the expectation value. But if we want to scrap that for now, I'd also be fine with that - so feel free to remove the relevant code bits.
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.
In any case, this is completely decoupled from this PR, so we can separate that out to get reorganized :)
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.
Yes let's do that. Then let's remove the multi-site operator functionality from this PR (reverting back to @leburgel original 1-site operator code) and then I will open up another PR where we can discuss this further :-) In there I can push my current idea of what would be the most organized approach with the least ambiguities.
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.
Before you go all-in with implementing, we might want to discuss first, unless you are okay with possibly having to make large changes if we find a better approach?
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.
Yes let's do that. Then let's remove the multi-site operator functionality from this PR (reverting back to @leburgel original 1-site operator code) and then I will open up another PR where we can discuss this further :-) In there I can push my current idea of what would be the most organized approach with the least ambiguities.
I reverted (not a clean one, but everything is still in the commit history here anyway) back to the simple one-site case and matched the expectation_value syntax to the other methods. Happy to discuss extensions in follow-ups. I'll try to remember what kinds of stat mech quantities we might want to be able to compute, it's been a while :)
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.
Before you go all-in with implementing, we might want to discuss first, unless you are okay with possibly having to make large changes if we find a better approach?
Sure, I definitely had discussions in mind. What I was planning could maybe serve as a good starting point for discussion/further refinements.
lkdvos
left a comment
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.
I think we can merge this like this if the tests all pass.
Rebased from @Sander-De-Meyer's initial work here.
Some todos left:
W ⊗ S ← N ⊗ Eand document