Repository navigation
Conversation
Fixes tenpy#763. Co-Authored-By: Gemini 4 Neon <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On
v2_main, running iDMRG or finite DMRG on a unit cell with a non-trivial total charge (aHiddenLegTensorcarrying!MPS_total_charge) fails inDMRGEngine.diagand breaks MPS gauging across three interacting places:full_diag_effH/DMRGEngine.diag(tenpy/algorithms/dmrg.py): At a charged boundary bond (e.g., bondL-1in iDMRG),theta_guesscarries the hidden leg in its codomain, whilefull_diag_effHreturns the eigenvector with the hidden leg in its domain (or squeezes a trivial hidden leg even underkeep_sector=True).lasy.inner(theta_guess, theta)inDMRGEngine.diagthen raises a leg-partition mismatch. Underdiag_method='ED_all', the returned eigenvector can also switch charge sectors or hidden-leg placement, which likewise breakslasy.inner.TwoSiteDMRGEngine.mixed_svd&_permute_theta_for_svd(tenpy/algorithms/dmrg.py,tenpy/networks/mps.py):mixed_svdcallslasy.planar_permute_legs(theta, codomain=['vL', 'p0'], domain=['vR', 'p1']), which lets the hidden leg migrate off the final site during sweeps (breakingis_gauged/total_charge_leg, even thoughget_total_charge()still fuses per-site charges). The existing_permute_theta_for_svdhelper inmps.pyalso slicestheta.labelsdirectly (LegLabelsis not sliceable, raisingTypeError).OneSiteH.matvec,TwoSiteH.matvec,ZeroSiteH.matvec(tenpy/algorithms/mps_common.py): All three passcodomain=labels, domain=[], flattening a domain hidden leg into the codomain so Lanczos fails withValueError: Different number of legson charged finite chains and charged iDMRG (start_env=0).Who hits this: TeNPy v2 users running finite or infinite DMRG on any MPS whose unit cell carries a non-trivial conserved charge (
SpinChainwithconserve='Sz'/'parity',FermionChainwithconserve='N'/'parity', or anyHiddenLegTensorstate, #763).Changes
tenpy/algorithms/dmrg.py:full_diag_effH: preservetheta_guess's hidden-leg dual whenkeep_sector=False, avoid squeezing a trivial hidden leg whenkeep_sector=Trueon aHiddenLegTensor, and restore(theta_guess.codomain_labels, theta_guess.domain_labels)vialasy.planar_permute_legswhenkeep_sector=True.DMRGEngine.diag: fordiag_method='ED_all', align same-sectorHiddenLegTensorplacements beforelasy.innerand treat sector changes as zero overlap (ov_change = 1.0).TwoSiteDMRGEngine.mixed_svd: whennot self.combine, use_permute_theta_for_svd(theta, charge_leg_right)withcharge_leg_right = self.psi.finite or self.psi._to_valid_site_index(i0) != self.psi.L - 1so the hidden leg stays pinned on the final site across sweeps.tenpy/networks/mps.py:_permute_theta_for_svdto converttheta.labelsviatheta.labels.as_list()before slicing.tenpy/algorithms/mps_common.py:(theta.codomain_labels, theta.domain_labels)instead of flattening all labels intocodomaininOneSiteH.matvec,TwoSiteH.matvec, andZeroSiteH.matvec.tests/test_dmrg.py&tests/test_infinite_dmrg.py:full_diag_effH(ED_blockacross all hidden-leg layouts andED_allsector switches),_permute_theta_for_svd(including odd-parity and complex cases), charged finite DMRG sweeps (L=3, 4), charged iDMRG (SpinChainSz/parity, staggeredFermionChainN/parity), and narrow thetest_free_fermions_infinite_dmrg[N]xfail expectation to the separate#762/#765failures.Scope & Coordination
v2_main(ff9e6c99) so this PR can be reviewed independently of [v2] Use planar leg permutations and level-separated hidden-leg restoration in mps_common #796 (#762). The 6-line(codomain_labels, domain_labels)change intenpy/algorithms/mps_common.pyoverlaps cleanly with [v2] Use planar leg permutations and level-separated hidden-leg restoration in mps_common #796's hidden-leg restoration inmps_common.py; whichever merges second is a straightforward rebase.FermionChainiDMRG with defaultdiag_method='lanczos'still hits#762(addressed in [v2] Use planar leg permutations and level-separated hidden-leg restoration in mps_common #796),psi.apply_local_opon charged states is#765, andcombine=Truewith hidden legs remains#694.Verification
full_diag_effH:36/36ED_blockhidden-leg partitions preserved;ED_allhandlesSector([4]) -> Sector([2])across all 3 placements (ov_change = 1.0, residual5.56e-17); all72aligned signed eigen-residuals< 1.6e-15.L=3andL=4sweeps keep the hidden leg on the final site across all150and200updates, passtest_sanity()(normerror<= 1.38e-15), matchconserve=Noneenergies to<= 4.62e-14and localSzto<= 2.67e-15, and match an independent 4-site exact Hamiltonian ground-state energy (-0.9571067811865476vs-0.9571067811865477).E/site = 0.25; staggeredFermionChain(conserve='N'and'parity') agrees with an independent 4096-point Bloch band sum to2.11e-9and Jordan-WignerSpinChainto< 3e-14.121 passed, 6 skipped, 4 xfailed(up from87 passedonv2_main,34new cases), and all 4 CI linters (ruff check,ruff format --diff,flake8 --select RST,python ./tests/linting.py) pass.Fixes #763
🤖 Generated with Claude Code
https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N