Repository navigation
Refactors Sites / DegreesOfFreedom - #317
Open
jhauschild wants to merge 8 commits into
Open
jhauschild wants to merge 8 commits into
jhauschild wants to merge 8 commits into
Conversation
…resent so it works when rebuilding
…utes of Site instead of subclassing
This was referenced Nov 12, 2026
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.
Motivation is to address #164 , which is essentially the part 2 inheritance of #254 for #255.
The second commit here does this, making the DegreeOfFreedom attributes of the Site instead of subclassing them.
Downstream: Site DOF composition (lasyten) → TeNPy
v2_mainFollow-up for the lasyten Site/DOF composition refactor (issues #164 / #254; call-site map:
convert_SiteDOF.md).After #611, TeNPy models already go through lasyten
Sites +Couplingfactories. That path is mostly unchanged. What breaks is anything that still assumes DOF mixininheritance (
SpinSiteis-aSpinDOF, flat attrs on the site,isinstance(site, FermionicDOF), etc.).What changed in lasyten (Python)
SpinSite/SpinHalfFermionSite/ … subclass DOF mixinsSiteonlysite.spin_vectorsite.spin.spin_vector(orsite.dofs["spin"].spin_vector)site.Nmax/n_tot/JW/number_operators/ …site.occupation.<attr>site.clock_operatorssite.clock.clock_operatorsisinstance(site, SpinDOF)/FermionicDOF/ …site.spin is not None/isinstance(site.occupation, FermionicDOF)/ …site.creation_annihilation_ops(...)(via MI)lasy.FermionicDOF.creation_annihilation_ops(...)(static on the DOF type)site.num_specieson every occupation siteSpinlessFermionSite; forSpinHalfFermionSiteusesite.occupation.num_species"spin","occupation","clock","anyon".Does not need changes (if used as today)
SpinSite(...),SpinlessBosonSite(Nmax=...),SpinHalfFermionSite(...), …)site.get_op(...)/add_onsite_operator/ modeladd_onsite/add_*_couplingwith op namesspin_spin_coupling,hopping,clock_clock_coupling, Hubbard-style factories, …) — they takeSites and resolve DOFs internallyisinstance(x, lasy.Site)/ concrete site classes (SpinSite,SpinHalfFermionSite, …)Required TeNPy edits on
v2_main(checked against current tree)1.
tenpy/models/spins.py— only production hit_onsite_matrix:site.spin_vector→site.spin.spin_vector_coupling_matrix:site1.spin_vector/site2.spin_vector→site1.spin.spin_vector/ …DipolarSpinChain.init_couplings:s.spin_vector→s.spin.spin_vector2.
tests/test_model.py—test_model_plus_hcs.spin_vector→s.spin.spin_vectors.creation_annihilation_ops(s.num_species)→ e.g.lasy.FermionicDOF.creation_annihilation_ops(s.occupation.num_species)(and use
s.occupation.num_speciesforSpinHalfFermionSite;SpinlessFermionSite.num_speciesstill exists on the site)Explicitly not broken by this refactor (on
v2_main)tf_ising,clock,fermions_spinless,hubbard,haldane,hofstadter, …): they construct sites and define couplings by name / factories — no flat DOF attribute access found.Nmax=/conserve=/filling=into site constructors.Suggested smoke checklist after bumping lasyten
SpinModel/SpinChain/DipolarSpinChainconstruct and build Htest_model.py::test_model_plus_hcforspin,fermion,spin-fermionSpinHalfFermionSitemodel (e.g. Hubbard) still builds — should already, but confirms coupling factories