Skip to content

Add PEPS initialization based on fidelity maximization#257

Open
pbrehmer wants to merge 46 commits intomasterfrom
pb/fidelity-initialization
Open

Add PEPS initialization based on fidelity maximization#257
pbrehmer wants to merge 46 commits intomasterfrom
pb/fidelity-initialization

Conversation

@pbrehmer
Copy link
Copy Markdown
Collaborator

@pbrehmer pbrehmer commented Sep 12, 2025

This PR adds tools to initialize a PEPS based on maximizing the fidelity with respect to another PEPS. As we discussed on Tuesday, this would be useful e.g. to extract a single-site approximation of a SU evolved PEPS on a $2\times2$ unit cell. This would be great to have since SU/FU evolved initial PEPS can then be used for single-site variational optimization.

Note that I use TensorKit's embed branch in order to use the embed! function:

] add TensorKit#ld-embed

@pbrehmer pbrehmer marked this pull request as draft September 12, 2025 14:44
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 12, 2025

Codecov Report

❌ Patch coverage is 93.84615% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/algorithms/approximate.jl 93.84% 4 Missing ⚠️
Files with missing lines Coverage Δ
src/Defaults.jl 85.71% <ø> (ø)
src/PEPSKit.jl 100.00% <ø> (ø)
src/algorithms/approximate.jl 93.84% <93.84%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pbrehmer
Copy link
Copy Markdown
Collaborator Author

@leburgel, @lkdvos I tried to recreate what you explained on Tuesday but I'm still a bit unsure about some things here:

  • It's not quite clear how to treat unit cells in the fidelity iteration in maximize_fidelity!
  • To compute the fidelity, should I use network_value which takes care of environment normalization or do we really just need to contract the ket and bra with the environment (as in contract_local_norm)?
  • The procedure is not yet properly normalized since the fidelity will get larger than 1 sometimes

I'll figure this out over the next days, but I'm happy about any hints/comments.

Copy link
Copy Markdown
Member

@lkdvos lkdvos left a comment

Choose a reason for hiding this comment

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

I'll try and go over this in a bit more detail later, just wanted to leave these small comments before I forget

Comment thread src/algorithms/time_evolution/fidelity_maximization.jl Outdated
Comment thread src/algorithms/time_evolution/fidelity_maximization.jl Outdated
@Yue-Zhengyuan
Copy link
Copy Markdown
Member

Yue-Zhengyuan commented Sep 18, 2025

I think it will be straightforward to do this for mixed states (PEPOs) as well? One particular application is first obtaining exp(-βH) from simple/full update, tracing out the physical axes, and putting it on a periodic lattice and contracting using TNR (when we want to extract CFT information). For TNR, afaik it is often cumbersome to work with non-trivial unit cells. Anyway, there are other ways to directly obtain the exp(-βH) PEPO with trivial unit cell (e.g. HOTRG, cluster expansion) and we don't need to do this right now.

@pbrehmer pbrehmer marked this pull request as ready for review September 18, 2025 15:30
@pbrehmer
Copy link
Copy Markdown
Collaborator Author

The new tests should pass once a new TensorKit version is released since we need absorb!. Other than that I think the fidelity maximization is now somewhat working. I will test this with SU evolved 2x2 PEPS as initial states for optimization in the next days.

Comment thread src/algorithms/optimization/fidelity_initialize.jl Outdated
Comment thread src/algorithms/optimization/fidelity_initialize.jl Outdated
Comment thread src/algorithms/optimization/fidelity_initialize.jl Outdated
Comment thread test/toolbox/fidelity_initialize.jl Outdated
Comment thread src/PEPSKit.jl Outdated
@leburgel
Copy link
Copy Markdown
Member

leburgel commented Apr 9, 2026

@pbrehmer, how would you feel about splitting off and adding the approximate part of this at least? I think the single-site replacement was a bit tricky conceptually, but the crude fidelity optimization by itself could be a very useful tool, so I think it might be good to revive that part.

@pbrehmer
Copy link
Copy Markdown
Collaborator Author

@pbrehmer, how would you feel about splitting off and adding the approximate part of this at least? I think the single-site replacement was a bit tricky conceptually, but the crude fidelity optimization by itself could be a very useful tool, so I think it might be good to revive that part.

I agree, the crude fidelity approximate would indeed be helpful. Then I will remove the single-site initialization and just leave the approximate part as is.

@pbrehmer
Copy link
Copy Markdown
Collaborator Author

I removed the single-site initialization and fixed the test. Of course one could add more test cases but I think this is also fine as is. Would be good to go for me.

@pbrehmer pbrehmer marked this pull request as ready for review April 13, 2026 11:58
Comment thread src/algorithms/approximate.jl Outdated
Comment thread src/algorithms/approximate.jl
Comment thread test/toolbox/approximate.jl Outdated
Comment thread src/algorithms/approximate.jl
Comment thread src/algorithms/approximate.jl Outdated
Comment on lines +100 to +101
env₀, = leading_boundary(CTMRGEnv(peps_init, envspace), peps_init, alg.boundary_alg)
peps_init /= sqrt(abs(_local_norm(peps_init, peps_init, env₀))) # normalize to ensure that fidelity is bounded by 1
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In Julia, doing ψ /= nrm is exactly equivalent to ψ = ψ / nrm (@lkdvos correct me if I'm wrong, or the behavior is defined differently for PEPS/TensorMaps). After this assignment (rebinding), any changes to ψ does not affect the input variable. Then the function is not mutating, and we can avoid introducing new names like peps_init, peps.

Also, env₀ being the environment for ψ, and env being the environment for ψ₀ looks off to me.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I introduced new names on purpose since I felt that was a bit cleaner and made it easier to read to iterative process. Note that env₀ is the environment of peps₀ (see updated name) and env of peps, i.e. the index refers to the zeroth iteration step of the approximate routine, not the initial guess. Instead, the first iteration step is determined by the initial guess ψ₀ since a perfect initial guess would immediately terminate the iteration. This is all slightly confusing so I wanted to work with different names.

Copy link
Copy Markdown
Member

@Yue-Zhengyuan Yue-Zhengyuan left a comment

Choose a reason for hiding this comment

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

Some more nitpicky comments

Comment thread test/toolbox/approximate.jl
Comment thread src/algorithms/approximate.jl Outdated
Comment thread src/algorithms/approximate.jl Outdated
Comment thread src/algorithms/approximate.jl Outdated
Comment thread src/algorithms/approximate.jl Outdated
)
)

@test peps_approx1 ≈ peps_approx2
Copy link
Copy Markdown
Member

@Yue-Zhengyuan Yue-Zhengyuan Apr 21, 2026

Choose a reason for hiding this comment

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

As a less trivial test, can we do two approximations with two different seeds (leading to different CTMRGEnv during the run), and finally check if the fidelity of the two results is close enough to 1?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I'll add that to the existing test set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On my Mac this new test fails miserably...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

How miserably does it fail? In general I think we can't expect the fidelities to approach 1 very closely since the algorithm is rather crude but I thought that being within 10% should be possible. Does is get better for other seeds?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay, trying around with different seeds this test will always fail. Maybe the tolerance is too strict: If one evaluates the fidelity of two random PEPS, it will in general be very small. So perhaps it is enough if the fidelity is already of the order of $10^{-1}$ (as opposed to $10^{-7}$ for two random PEPS).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For me the fidelity between two runs with different seeds can be ad low as 0.3. If random states are hard, how about using SU to get a physical state and try to approximate it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think the problem is the initial state, it's rather the algorithm itself which will only bring two states in the same ballpark. One can already see in the convergence itself that it is hard to converge the fidelity below an error of $10^{-2}$. But it would be interesting to see what happens if one initializes with SU.

Comment thread src/algorithms/approximate.jl Outdated
@Yue-Zhengyuan
Copy link
Copy Markdown
Member

If I take a random PEPS ψ1, and obtain another ψ2 by performing a gauge transformation (inserting X inv(X) on virtual bonds), will the crude fidelity defined here evaluates to 1? This is not obvious to me by looking at the code.

Comment thread test/toolbox/approximate.jl Outdated
@pbrehmer
Copy link
Copy Markdown
Collaborator Author

pbrehmer commented Apr 22, 2026

If I take a random PEPS ψ1, and obtain another ψ2 by performing a gauge transformation (inserting X inv(X) on virtual bonds), will the crude fidelity defined here evaluates to 1? This is not obvious to me by looking at the code.

I don't think it will evaluate to 1 due to the way CTMRG (without spatial symmetries) is not gauge-invariant if you insert a gauge transformation on the virtual bonds since the north and east edge will absorb $X$ whereas the south and west edge will absorb $X^{-1}$. It would only be one if that inner product contraction environment of InfiniteSquareNetwork(ψ1, ψ2) would produce the same network value as the respective ψ1 and ψ2 norm networks - which it generally won't due to the gauge transformation, I believe.

Edit: If that is true, then that also kind of answers why the fidelity test won't approach 1, since two different initializations won't end up in the same gauge.

@Yue-Zhengyuan
Copy link
Copy Markdown
Member

Then I suggest we also explain in docstring how the fidelity is crudely approximated so that users can have the right expectations.

@Yue-Zhengyuan
Copy link
Copy Markdown
Member

Just remembered this discussion #316 that is very relevant.

@Yue-Zhengyuan
Copy link
Copy Markdown
Member

Yue-Zhengyuan commented Apr 22, 2026

I think that's all I wanted to say. @leburgel do you have additional comments?

@Yue-Zhengyuan Yue-Zhengyuan requested a review from leburgel April 22, 2026 16:14
@Yue-Zhengyuan
Copy link
Copy Markdown
Member

Oh, can we maybe use BP gauging fixing during the iteration to improve the robustness?

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.

4 participants