Skip to content

Increase test coverage for CTMRG contractions#358

Open
leburgel wants to merge 8 commits intomasterfrom
lb/test_ctmrg_contractions
Open

Increase test coverage for CTMRG contractions#358
leburgel wants to merge 8 commits intomasterfrom
lb/test_ctmrg_contractions

Conversation

@leburgel
Copy link
Copy Markdown
Member

@leburgel leburgel commented Apr 13, 2026

Adds coverage for all of the sparse CTMRG contractions that were previously untested, by directly comparing their results to the dense equivalents. Quite a few of these were broken or even missing, so I fixed things up where necessary and added the missing parts so that we can actually do everything we would need using sparse environments.

There's one part that's a bit unclear to me, in the application of a (half or full infinite) environment to a vector, which I think we plan to use for fully matrix-free sparse SVDs in the future. There I'm not sure if for the "right" action we need the contraction tensorcontract(env, x) or the multiplication env * x instead, and the same for the "left" action. I chose contraction for now since that was the easiest and there is currently no use case to check this on. But if we need multiplication we'll have to add some additional twists. If we want the use of svdsolve to correspond to an svd_trunc on the dense environment, then application should correspond to proper tensor composition, so env * x. I updated the implementation and test accordingly.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

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

Files with missing lines Patch % Lines
src/algorithms/contractions/ctmrg/fullinf_env.jl 86.66% 4 Missing ⚠️
src/algorithms/contractions/ctmrg/halfinf_env.jl 83.33% 4 Missing ⚠️
src/algorithms/contractions/ctmrg/projector.jl 92.85% 4 Missing ⚠️
src/algorithms/ctmrg/sparse_environments.jl 90.90% 4 Missing ⚠️
src/utility/util.jl 57.14% 3 Missing ⚠️
Files with missing lines Coverage Δ
...rc/algorithms/contractions/ctmrg/enlarge_corner.jl 68.18% <100.00%> (+3.18%) ⬆️
src/algorithms/contractions/ctmrg/expr.jl 100.00% <100.00%> (+17.94%) ⬆️
...lgorithms/contractions/ctmrg/renormalize_corner.jl 94.73% <100.00%> (+42.10%) ⬆️
src/networks/local_sandwich.jl 89.09% <100.00%> (+1.09%) ⬆️
src/operators/infinitepepo.jl 77.77% <100.00%> (ø)
src/utility/util.jl 71.29% <57.14%> (-0.99%) ⬇️
src/algorithms/contractions/ctmrg/fullinf_env.jl 88.33% <86.66%> (+85.43%) ⬆️
src/algorithms/contractions/ctmrg/halfinf_env.jl 86.04% <83.33%> (+79.22%) ⬆️
src/algorithms/contractions/ctmrg/projector.jl 93.84% <92.85%> (+55.38%) ⬆️
src/algorithms/ctmrg/sparse_environments.jl 90.35% <90.90%> (+40.98%) ⬆️

... and 2 files with indirect coverage changes

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

@leburgel leburgel marked this pull request as ready for review April 14, 2026 09:21
@leburgel leburgel requested a review from pbrehmer April 14, 2026 12:35
@leburgel
Copy link
Copy Markdown
Member Author

leburgel commented Apr 15, 2026

Aside from the conceptual question above about what we want the environment application to mean exactly in the presence of fermionic symmetries, there's three more things to be addressed here I think:

  • I copied over twistnondual from Local truncation for two layers of InfinitePEPO #311, since I naturally needed it to fix the computation of the right projector by multiplying in a right isometry which requires twists one some of its domain spaces. I don't think that's a problem, we just have to remove it from whichever one gets merged first.
  • I added rrules for both twistdual and twistnondual, since these out-of-place implementations call in-place methods on a copy and are therefore not automatically differentiable. I did this because the CTMRG subroutines should really be differentiable, but since the sparse routines are currently not used for optimization there rules are not covered by tests right now. I can just remove them for now and add them in when we actually need them, I think that might be better. I removed the unused rrules, they're easy to add again once they're needed.
  • There's something weird going on with codecov and @tensor begin ... end blocks, and all of these show up as uncovered even though they are actually used in the tests. In particular, this leads to bad coverage being reported for src/algorithms/contractions/ctmrg/enlarge_corner.jl, where some of the contractions were fully written out to minimize permutations using @tensor begin ... end blocks. I don't know if there's something that can be done about this, or if it would actually be worth it.

@leburgel leburgel requested a review from lkdvos April 16, 2026 08:00
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.

1 participant