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

Add Form-specific constructors for MPS #248

Merged
merged 9 commits into from
Nov 15, 2024
Merged

Add Form-specific constructors for MPS #248

merged 9 commits into from
Nov 15, 2024

Conversation

jofrevalles
Copy link
Member

@jofrevalles jofrevalles commented Nov 13, 2024

This PR adds Form-specific constructors for the MPS struct, which allows us to create Matrix Product States with an specific canonical Form directly on the constructor. I believe this is the proper way to go, and we added a check_canonical_form kwarg that, if true (default), it will check if the MPS fulfills the canonical form.

TO DO:

  • Regroup repeated code into an internal function. Maybe it can be named __tn_mps_from_arrays? @mofeing I can't find a good name. Group code by using NonCanonical constructor.

@jofrevalles jofrevalles requested review from mofeing and starsfordummies and removed request for mofeing November 13, 2024 14:19
Copy link
Member

@mofeing mofeing left a comment

Choose a reason for hiding this comment

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

Great! Thanks! In general everything is great. Just some suggestions for the generic MPS constructors.

Regroup repeated code into an internal function. Maybe it can be named __tn_mps_from_arrays?

You no longer need to prefix internal functions with __ since we'll soon start annotating public API with the new public keyword (well, with the @public macro from Compat.jl).

Also, what I would recommend you is not to refactor it to an internal function, but to leave that code in the NonCanonical constructor. Then Canonical and MixedCanonical would call the NonCanonical constructor and modify it.

  • MixedCanonical calls the NonCanonical constructor and then modifies the form field.
  • Canonical calls the NonCanonical constructor, tensorizes the alphas by requesting bond index name with inds(tn; bond=...), push them to the TN and finally modify the form field.

An example of this pattern can be found in simple_update! for MixedCanonical: it first calls mixed_canonize! to move the orthogonality center to the target sites and then calls NonCanonical version of simple_update!.

src/MPS.jl Outdated Show resolved Hide resolved
@jofrevalles
Copy link
Member Author

Okay, everything should be ready now @mofeing. I separated the checks of the form in two check_form functions that are dispatched over the Form. I think this is a good idea since we would want to use these functions somewhere outside the constructor. In this case, maybe it's even better that they do not throw an error but just return false? I don't know, for me this is still fine.

Copy link
Member

@mofeing mofeing left a comment

Choose a reason for hiding this comment

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

Great! Just some suggestions and we're done.

src/MPS.jl Outdated Show resolved Hide resolved
src/MPS.jl Outdated Show resolved Hide resolved
src/MPS.jl Outdated
function check_form(::Canonical, mps::AbstractMPO)
for i in 1:nsites(mps)
if i > 1
isisometry(contract(mps; between=(Site(i - 1), Site(i)), direction=:right), Site(i); dir=:right) ||
Copy link
Member

Choose a reason for hiding this comment

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

do you need to contract to check? that can be a lil bit costly

@starsfordummies what do you think? is there some other way to check that the gammas are correct?

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 okay with merging it this like for now. But if there's a way to check it without contracting, then we should open an issue to implement it in the future.

src/MPS.jl Outdated Show resolved Hide resolved
src/MPS.jl Outdated Show resolved Hide resolved
src/MPS.jl Outdated Show resolved Hide resolved
src/MPS.jl Outdated Show resolved Hide resolved
@mofeing
Copy link
Member

mofeing commented Nov 15, 2024

Thanks!

@mofeing mofeing merged commit 6b87d0f into master Nov 15, 2024
5 checks passed
@mofeing mofeing deleted the fix/MPS-constructor branch November 15, 2024 09:18
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.

2 participants