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 #82
This PR implements the
indices
kwarg inSelector
s, and in doing so introduces some heavy refactoring of the wholeSelector
engine. See the updatedsiteselector
andhopselector
docstrings for details.We now have
ResolvedSelector
in addition toSiteSelector
andHopSelector
.ResolvedSelector
is produced byresolve(::Selector, ::AbstractLattice)
, which now simply replaces sublat names with sublat indices, but does not do any further clever transformation of selection specs (i.e. things like(:A, :B) => (:C, :D)
become(1,2) => (3,4)
, but not(1=>3, 1=>4, 2=>3, 2=>4)
anymore). The actual interpretation of the different selector directives is done when querying whether a site or site pair is selected by theResolvedSelector
. This is now done using theBase.in
function, which is more idiomatic than what we had before.This change is motivated by the fact that, upon introducing
indices
in selectors, it makes much sense to allow ranges such ashopselector(indices = 1:100 => 101:200)
, for example. If we were to expand that, checking membership as in1=>2 in resolved_selector
would be very inefficient. Leaving the input form unexpanded and using dispatch is the optimal approach forindices
, so we might as well extend that tosublats
while we are at it.Together with this we now have to new functions in the API,
sitepositions(h; kw...)
(which replacessites
) andsiteindices(h; kw...)
. These return a (lazy) generator, that can be used in comprehensions to iterate over selected site positions and indices. Note that, as per the current Julia design, such generators have no eltype of length defined, so collecting them is not as fast as it could be. Iterating over them, however, is plenty fast.siteindices
also allows to refactor theapplyterms!
machinery used to build Hamiltonian from models. This PR also includes such refactor. It has the advantage that whatever future extension to selectors that we do will be automatically applied to Hamiltonian building.So, with this PR we now have, amongst other combinations, the following type of possibilities,