Refactor MPSTensor construction to fix type piracy#475
Open
VinceNeede wants to merge 2 commits into
Open
Conversation
`MPSTensor` used type piracy, the new struct `MPSMapSpace` allows to keep the default leg convention `Vl * Vp <- Vr` in one place, and overload `rand`, `randn` and `zeros` constructor
Codecov Report❌ Patch coverage is
... and 65 files with indirect coverage changes 🚀 New features to boost your workflow:
|
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.
Closes #471.
Not really my place to be doing bigger refactors yet (this is only my second PR, after my
DMRG3S implementation), but the discussion in #471 pointed pretty directly at a concrete fix,
so I wanted to give it a try rather than just patching
zeros!→zerovector!and leavingthe type piracy in place.
What this does
Removes the old
MPSTensor(f, T, P, Vₗ, Vᵣ)/MPSTensor(::UndefInitializer, ...)/MPSTensor(d, Dₗ, Dᵣ)constructors, rather than just fixing thezeros!call inside them.As @lkdvos noted, these were type piracy (
MPSTensoris aconstalias forAbstractTensorMap, not a type MPSKit owns), and the original issue was really just asymptom of that.
Introduces a small
MPSMapSpace{S, Sₚ}struct that holds(Vₗ, P, Vᵣ), so theVₗ ⊗ P ← Vᵣleg convention lives in exactly one place instead of being repeated in everyconstructor/accessor.
Extends
Base.rand/Base.randn/Base.zerosforMPSMapSpace, giving essentially thezeros(T, Vl * P, Vr)-style interface you mentioned as a preferred option, e.g.:These are added as genuine
Base.rand/Base.randn/Base.zerosmethods (not a new typealias constructor), so there's no piracy here —
MPSMapSpaceis a type this package owns.What this does not do
I left out a dedicated
mpstensor(...)convenience function for now.MPSTensorwas neverexported, and grepping both MPSKit (src, test, docs, examples) and PEPSKit.jl for
MPSTensor(/MPSTensor.(turns up zero call sites outside the old constructor definitionsthemselves, so I don't think there's a hidden dependency on the old constructor shapes. Given
that, it felt safer to start minimal and let you decide whether a convenience wrapper on top
of
MPSMapSpaceis actually wanted, rather than guessing at a signature nobody's using yet.Happy to add
mpstensor(or renameMPSMapSpaceto something else, ifVl * Pcompositenotation is what you'd rather standardize on) if that's preferred — this is very much open
to being redirected.