Skip to content

build_hamiltonian

Build a Hamiltonian MPO from a list of Interaction objects.

build_hamiltonian

build_hamiltonian(
    interactions: List[Interaction],
    L: int,
    spc: Index,
    trunc: Optional[dict] = None,
    compact_every: int = 10,
) -> MPO

Build a Hamiltonian MPO from a list of Interaction objects.

Each interaction is accumulated term by term into a running MPO via oplus, then the result is compressed with two canonical sweeps. This approach handles arbitrary symmetries — including non-Abelian SU(2) — by delegating sector arithmetic to Nicole's oplus.

All tensor fields (tnsr, leading_tnsr, terminal_tnsr, intermid_tnsr) must be pre-filled (including any coupling constants) before calling this function. build_hamiltonian uses them verbatim.

Parameters:

Name Type Description Default
interactions List[Interaction]

List of Interaction1Site or Interaction2Site objects with all required tensor fields set.

required
L int

Chain length (number of sites).

required
spc Index

Physical Index (space) shared by all sites. Used to construct the site-wise identity tensor.

required
trunc Optional[dict]

Truncation parameters forwarded to MPO.canonical() during the right-to-left compression sweep. Defaults to {'thresh': 1e-14}.

None
compact_every int

Call MPO.compact after every this many accumulated terms. Defaults to 10. Set to 0 to disable intermediate compaction.

10

Returns:

Type Description
MPO

Compressed Hamiltonian MPO with bond itags W{i:02d} / W{i+1:02d} and physical itags s{i:02d} at each site.

Raises:

Type Description
ValueError

If any required tensor slot is None, or if intermid_tnsr is None for a two-site interaction with terminal_site > leading_site + 1.

See Also