Skip to content

Correlator for purified iPEPO and right-to-left contraction#399

Open
Yue-Zhengyuan wants to merge 13 commits into
QuantumKitHub:mainfrom
Yue-Zhengyuan:pepo-cor-purified
Open

Correlator for purified iPEPO and right-to-left contraction#399
Yue-Zhengyuan wants to merge 13 commits into
QuantumKitHub:mainfrom
Yue-Zhengyuan:pepo-cor-purified

Conversation

@Yue-Zhengyuan

@Yue-Zhengyuan Yue-Zhengyuan commented Jul 1, 2026

Copy link
Copy Markdown
Member

This PR improves the correlator function by adding support for purified iPEPO and removing some constraints on sites js, with some under-the-hood deduplications.

  • Deduplicate iPEPS and one-layer iPEPO trace correlator logic through private correlator context/adapters.
  • Add purified iPEPO correlators:
    correlator(bra::InfinitePEPO, O, i, js, ket::InfinitePEPO, env::CTMRGEnv)
    matching the purified-state convention used by expectation_value.
  • Generalize horizontal correlators so js may contain targets on either side of i.
    • js no longer need to be sorted.
    • js can contain sites on both sides of i.
    • Output order follows vec(js).
    • j == i is rejected with ArgumentError.
  • Vertical correlators inherit the same behavior through dispatching to horizontal correlators via rotation.
  • Add right-to-left correlator contractions and the corresponding edge_transfer_right paths for js on the left of i.

Implementation Notes

The shared correlator implementation now dispatches through private context types:

  • _PEPSCorrelator
  • _PEPOPurifiedCorrelator
  • _PEPOTraceCorrelator

The horizontal sweep partitions js into right and left sites internally:

  • right targets use the existing left-to-right contraction path;
  • left targets use a mirrored right-to-left contraction path;
  • results are written back into the original target order.

Low-level tensor contractions remain separate where the tensor ranks genuinely differ.

Comment thread src/algorithms/correlators.jl Outdated
c = i # current column being handled
Vn, Vo = start_correlator_left(c, bra, O[1], ket, env)
j_last = last(js)
return map(enumerate(js)) do (_, j)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When I try just writing map(js) do j, the test test/utility/correlator.jl starts to use lots of memory and becomes slow. Would like some guide from @lkdvos in understanding what's going on...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I realized that this may be due to things inside map modifying c, Vn, Vo that are defined outside. I've restored the old approach to first pre-allocate the correlator vector.

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.69231% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/algorithms/correlator_adapters.jl 84.61% 18 Missing ⚠️
src/algorithms/transfermatrix.jl 90.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
.../algorithms/contractions/correlator/pepo_1layer.jl 100.00% <100.00%> (ø)
...lgorithms/contractions/correlator/pepo_purified.jl 100.00% <100.00%> (ø)
src/algorithms/contractions/correlator/peps.jl 100.00% <100.00%> (ø)
src/algorithms/contractions/transfer.jl 91.66% <100.00%> (+22.91%) ⬆️
src/algorithms/correlators.jl 100.00% <100.00%> (+3.12%) ⬆️
src/algorithms/toolbox.jl 96.92% <ø> (ø)
src/networks/local_sandwich.jl 85.71% <100.00%> (+0.52%) ⬆️
src/algorithms/transfermatrix.jl 80.00% <90.00%> (+13.33%) ⬆️
src/algorithms/correlator_adapters.jl 84.61% <84.61%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Yue-Zhengyuan Yue-Zhengyuan changed the title Refactor correlator functions for improved clarity Correlator for purified iPEPO Jul 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It turns out that none of edge_transfer_right is used in PEPSKit. Instead of commenting them out, I prefer to just remove them, keeping things minimal.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@leburgel Since you helped introduce EdgeTransferMatrix back in #274, can you have a look and see if you actually wanted to use edge_transfer_right somewhere else?

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.

I agree removing them is the cleanest thing to do, but can you add a corresponding entry in the "Removed" section of the changelog with a link to this PR? That way we can find them in the git history easily, since this will be impossible to spot just from the PR title alone.

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.

@leburgel Since you helped introduce EdgeTransferMatrix back in #274, can you have a look and see if you actually wanted to use edge_transfer_right somewhere else?

I am using them somewhere in a project that depends on PEPSKit, but I can just pin that to a version that still has them. I don't have a use case within PEPSKit itself yet, so it's indeed best to just remove them for now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually I wanted to implement correlators for j on the left of i. In this case, if we don't want to rotate the state by 180 degrees, we need to contract from right to left, and use edge_transfer_right. This way we can test and save them in the package.

@Yue-Zhengyuan Yue-Zhengyuan changed the title Correlator for purified iPEPO Correlator for purified iPEPO and right-to-left contraction Jul 2, 2026
function end_correlator_numerator(
j::CartesianIndex{2}, V::CTMRGEdgeTensor{T, S, 3},
function end_correlator_right_numerator(
j::CartesianIndex{2}, V::AbstractTensorMap{T, S, 3, 1},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since the V tensors (partially contracted correlator network) are not actually CTMRG edge tensors, I prefer just annotate their type using AbstractTensorMap.

@Yue-Zhengyuan Yue-Zhengyuan requested a review from leburgel July 2, 2026 03:03
@Yue-Zhengyuan Yue-Zhengyuan marked this pull request as ready for review July 3, 2026 11:35
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