Skip to content

BUG: failure to assign charges to MPO legs when H=0 #487

@aaronszaszG

Description

@aaronszaszG

Describe the bug
If a Hamiltonian is exactly 0 (no terms added before generating MPO), charges cannot be correctly assigned to legs of the MPO. This seems like a useless case, but it can come up in some corner cases, and it would be nice if it could be handled gracefully.

Minimal example or code extract

from tenpy.models.model import CouplingMPOModel
from tenpy.models.lattice import Chain
from tenpy.networks.site import SpinHalfSite

class TestModel(CouplingMPOModel):
    default_lattice = Chain
    force_default_lattice = True
    
    def init_sites(self, model_params):
        site = SpinHalfSite(conserve='parity', sort_charge=True)
        return site

    def init_terms(self, model_params):
        pass
        # done

def test_build_model():
    model_params = {'L':5}
    M = TestModel(model_params)

Error traceback
Last part is

raise ValueError("can't determine all charges on the very right leg of the MPO!")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfix after v2This will not be worked on until after v2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions