-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide wrappers to matrices / vectors to indicate parent Hamiltonian an allow use of siteselector #232
Comments
This issue points to a core problem in current master: we have no concept for an AbstractMatrix defined on the orbitals of a unit cell or, more generally, on a We do have As a result, as you point out @BacAmorim, we cannot do siteselector indexing of the matrices produced by Quantica. So, to summarize the problem:
To address these two needs we need a new concept: a matrix defined over the orbitals in a LatticeSlice that knows about its domain, and the OrbitalStructure defined on it. The struct LatticeSliceMatrix{C,M<:AbstractMatrix{C},L<:LatticeSlice,B} <: AbstractMatrix{C}
parent::M
rows::L
cols::L # can be cols === rows
obstruct::OrbitalBlockStructure{B} # B here is the block type enconding orbitals
end This type could implement the full This indexing behavior is analogous to that of a conventional How would that type be produced by different Quantica objects?
Note: the You mention also the concept of a |
OK, your proposal looks like what I had in mind. Regarding the Does this make sense? |
Note: this issue strongly overlaps with the long and winding #230 discussion, and it is quite a bit simpler. So if @BacAmorim finds this agreeable, I wouldn't be opposed to closing #230 and abandoning for the moment the caching machinery discussed there, which would no longer be needed to implement #229. |
I guessed this is what you had in mind. Yes, it makes sense, but wouldn't a one- or few-column LatticeSliceMatrix work too? Do we really need a new Vector type for that? |
So what would be a sketch for a general struct LatticeSliceArray{C,N,M<:AbstractArray{C,N},L<:LatticeSlice,B} <: AbstractArray{C,N}
parent::M
latslices::NTuple{N,L}
obstruct::OrbitalBlockStructure{B} # B here is the block type enconding orbitals
end So not that bad, we just have to add one more parameter |
From what I understood in your proposal of This is ilustrated by computing the eigenvalues of an Hamiltonian. We get a Matrix Question: could all of this issue be solved by just using |
Ah, that's an excellent point! Fortunately, Julia extremely nice AbstractArray API allows us to do this very cleanly. We need struct OrbitalAxis{T,E,L,B}
latslice::LatticeSlice{T,E,L}
orbstruct::OrbitalBlockStructure{B}
end
struct LatticeSliceArray{C,N,M<:AbstractArray{C,N},A<:NTuple{N,Union{OrbitalAxis,UnitRange}}} <: AbstractArray{C,N}
parent::M
axes::A
end In your StateVector case the axes field would be To make this work we just need to add a method |
I've been iterating the above design of a We currently have EDIT: tweaks of the original post follow The refactor would be as follows: we will have a single parametric type struct CellIndices{L,I,G<:Union{Missing,OrbitalGroups, OrbitalGroupsSkipped}}
cell::SVector{L,Int}
inds::I # can be anything, Int, Colon, Vector{Int}, etc. Represents one or more entities in cell.
groups::G # if G<:OrbitalGroups, `inds` are orbitals, and `groups` are their grouping in sites.
end Then we define a number of aliases:
In const OrbitalGroups = Dictionary{Int,UnitRange{Int}}
struct OrbitalGroupsSkipped end; # singleton type to avoid allocating a Dictionary when we don't need groups
const Subcells{L,C<:CellIndices} = Dictionary{SVector{L,Int},C} Then, we will define slices with a unique type struct LatticeSlice{T,E,L,C<:CellIndices}
lat::Lattice{T,E,L}
subcells::Subcells{L,C}
end What we currently call const OrbitalSubcells{L} = Subcells{L,CellOrbitals{L,Vector{Int}}} which, note, is just a const OrbitalSlice{T,E,L} = LatticeSlice{T,E,L,CellOrbitals{L,Vector{Int}}} Note the use of After such a refactor, the struct OrbitalSliceArray{C,N,M<:AbstractArray{C,N},A<:NTuple{N,Union{OrbitalSlice,UnitRange}}} <: AbstractArray{C,N}
parent::M
axes::A
end which is conceptually much clearer: the type for a matrix defined over a given The above should be implemented in two steps: one PR with an invisible internal refactor, and a second PR introducing |
It would be really useful if one could use the
siteselector
andLatticeSlice
machinery of Quantica with user provided matrices and vectors.Example:
Assume we have a periodic system with Quantica Hamiltonian
h
. We want to evaluate the Green's function in momentum space for a givenk
point as:Here
gk
will be a simple matrix. If would be useful if we could say thatgk
exists in the same space ash
, such that we could use the indexing machinery that works forh
. Maybe this could de achieved by doing something like:This would require some promotion of
matrix
to aHybridSparseMatrix
, such that then it can be internatally interpreted as a Quantica Hamiltonian, thus allowing for the use of indexing.I would also be nice if the same logic could be extended to states or selected columns of an operator. For example if
psi
is an eigenstate ofh
, then by defining someting likethen calling
state(h, psi)
would create a wrapper ofpsi
, promising thatpsi
lives in the same Hilbert space ash
, allowing for the use use of sitelector viapsi[site...]
. The same should also work for collections of states / operator columns. I have no idea how this could be implemented.The text was updated successfully, but these errors were encountered: