Repository navigation
refactor label handling - #310
Open
jhauschild wants to merge 3 commits into
Open
jhauschild wants to merge 3 commits into
jhauschild wants to merge 3 commits into
Conversation
Member
Author
|
This is ready for merge, but requires downstream changes, see tenpy/tenpy#715 |
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
This PR adresses the first part of #254: It renames the
LabelledLegsclass toLegLabels, and removes theLabelledLegsfrom theTensor/TensorPlaceholderMRO, i.e. they are no longer subclasses, but now own aLegLabels labelsinstance member instead.This comes with an few changes for the calling interface, as given below (and in
docs/cpp_conversion/convert_LegLabels.md). I hope/think that these should make the calls actually more intuitive.Moreover, I opted to replace the
Nonestanding for "no label set" with an empty string, i.e. non-set labels appear/need to be set as empty strings , unifying the type for the label list.Call-site map (Python)
LabelledLegsLegLabelst.labels/t.labels()as a listt.labels(LegLabels); copy viat.labels.as_list()t.set_labels(x)t.labels.set(x)ort.labels = xt.set_label(i, x)t.labels[i] = xt.relabel(m)t.labels.update(m)t.get_leg_idcs(x)[0]t.labels.index(x)t.get_leg_idcs([...])t.labels.indices([...])t.has_label(...)t.labels.has(...)or'x' in t.labelst.labels_are(...)t.labels.are(...)t.is_fully_labelledt.labels.is_fully_labelledt._labels/t._labelmapt.labelsor useas_list())for x in t.labels/list(t.labels)for x in t.labels.as_list()/t.labels.as_list()assert t.labels == [a, None, b]assert t.labels == [a, '', b]Label values
OptionalLabel/std::optional<std::string>std::stringOptionalLabelsstd::vector<std::string>(LegLabelList)std::nullopt/ PythonNoneas unset""if (lab)/lab.has_value()!lab.empty()LegLabelssupports equality,len,[]get/set (int or str key), andassignment from a sequence. It does not implement
__iter__.relabel1/relabel2kwargs oncompose/tdot/outer/ etc. are unchanged(function arguments, not tensor methods).
Chaining note: old
t.relabel(m)returnedself;t.labels.update(m)returnsthe
LegLabelsmember. Split chains:HDF5
"labels"stores a string list; load oldNoneentries as"".LegLabels::{save_hdf5,from_hdf5}.Bindings / stubs
pybind/tensors/py_labels.cpp: bindLegLabels; sequences ofstronly.labelsproperty and_labelmapfrom the old holder API.lasyten/_core.pyi:list[str], notlist[str | None].