Hilbert spaces, states and linear operators
KeldyshED.Hilbert
— ModuleThis module defines types of Hilbert spaces, state vectors and linear operators acting in these spaces. It also implements the space autopartition algorithm described in Computer Physics Communications 200, March 2016, 274-284 (section 4.2).
Ordered set of compound indices
KeldyshED.Hilbert.SetOfIndices
— TypeMapping from a compound operator index IndicesType
to a linear integer index. It provides a dictionary-like iteration interface, supports indexed read-only access, functions keys()
, values()
and pairs()
, as well as the operator in
.
Fields
map_index_n::DataStructures.SortedDict{Vector{Union{Int64, String}}, Int64}
: TheIndicesType
-> linear index map
Base.insert!
— Methodinsert!(
soi::KeldyshED.Hilbert.SetOfIndices,
indices::Vector{Union{Int64, String}}
) -> DataStructures.SortedDict{Vector{Union{Int64, String}}, Int64, Base.Order.ForwardOrdering}
Insert a new compound operator index indices
into soi
.
Base.insert!
— Methodinsert!(
soi::KeldyshED.Hilbert.SetOfIndices,
indices...
) -> DataStructures.SortedDict{Vector{Union{Int64, String}}, Int64, Base.Order.ForwardOrdering}
Insert a new compound operator index built out of arguments indices...
into soi
.
KeldyshED.Hilbert.reversemap
— Methodreversemap(
soi::KeldyshED.Hilbert.SetOfIndices
) -> Vector{Vector{Union{Int64, String}}}
Build and return the reverse map Int
-> IndicesType
out of a SetOfIndices
object.
KeldyshED.Hilbert.matching_indices
— Functionmatching_indices(
soi_from::KeldyshED.Hilbert.SetOfIndices,
soi_to::KeldyshED.Hilbert.SetOfIndices
) -> Vector{Int64}
For each compound index in the set soi_from
, find the linear index of that compound index within soi_to
and collect the found linear indices.
Full Hilbert spaces and their subspaces
KeldyshED.Hilbert.FockState
— Typeprimitive type UInt64 <: Unsigned 64
Fermionic Fock state encoded as a sequence of zeros (unoccupied single-particle states) and ones (occupied states) in the binary representation of an integer.
KeldyshED.Hilbert.translate
— Functiontranslate(
fs::UInt64,
bit_map::Vector{Int64};
reverse
) -> UInt64
Reshuffle single-particle states (bits) of a Fock state fs
according to a given map bit_map
. bit_map
is understood as a reverse map if reverse = true
.
KeldyshED.Hilbert.HilbertSpace
— TypeAbstract supertype for Hilbert space types.
KeldyshED.Hilbert.FullHilbertSpace
— TypeA Hilbert space spanned by all fermionic Fock states generated by a given set of creation/annihilation operators. This type supports vector-like iteration over Fock states, read-only indexed access and the operator in
.
Fields
soi::KeldyshED.Hilbert.SetOfIndices
: Set of compound operator indices used to generate this spacedim::UInt64
: Dimension of the space
KeldyshED.Hilbert.FullHilbertSpace
— MethodFullHilbertSpace(
soi::KeldyshED.Hilbert.SetOfIndices
) -> KeldyshED.Hilbert.FullHilbertSpace
Make a Hilbert space generated by creation/annihilation operators carrying compound indices from a given set soi
.
Base.getindex
— Methodgetindex(
fhs::KeldyshED.Hilbert.FullHilbertSpace,
soi_indices::Set{Vector{Union{Int64, String}}}
) -> UInt64
Return the Fock state $|\psi\rangle \propto c^\dagger_i c^\dagger_j c^\dagger_k \ldots |0\rangle$, where the compound indices $i,j,k,\ldots$ form a given set soi_indices
and the creation operators act in a Hilbert space fhs
.
KeldyshED.Hilbert.:⊗
— Method⊗(
H_A::KeldyshED.Hilbert.FullHilbertSpace,
H_B::KeldyshED.Hilbert.FullHilbertSpace
) -> KeldyshED.Hilbert.FullHilbertSpace
Construct a direct product of full Hilbert spaces $H_A \otimes H_B$ under the assumption that the sets of indices generating $H_A$ and $H_B$ are disjoint.
Base.:/
— Method/(
H_AB::KeldyshED.Hilbert.FullHilbertSpace,
H_A::KeldyshED.Hilbert.FullHilbertSpace
) -> KeldyshED.Hilbert.FullHilbertSpace
Construct a quotient space $H_{AB} / H_A$ under the assumption that the sets of indices generating $H_{AB}$ and $H_A$ satisfy $soi(H_A) \subseteq soi(H_{AB})$.
KeldyshED.Hilbert.product_basis_map
— Functionproduct_basis_map(
H_A::KeldyshED.Hilbert.FullHilbertSpace,
H_B::KeldyshED.Hilbert.FullHilbertSpace,
H_AB::KeldyshED.Hilbert.FullHilbertSpace
) -> Matrix{Int64}
Given three Hilbert spaces $H_A$, $H_B$ and $H_{AB}$, construct all product Fock states $|\psi\rangle_{AB} = |\psi\rangle_A ⊗ |\psi\rangle_B$, where $|\psi\rangle_A ∈ H_A, |\psi\rangle_B ∈ H_B, |\psi\rangle_{AB} ∈ H_{AB}$. Return a mapping (an integer-valued matrix) $i, j \mapsto k$, where $i$, $j$ and $k$ are linear indices of $|\psi\rangle_A$, $|\psi\rangle_B$ and $|\psi\rangle_{AB}$ within their respective spaces.
Sets of indices $soi(H_A)$, $soi(H_B)$ must be disjoint and satisfy $soi(H_A) \subseteq soi(H_{AB})$, $soi(H_B) \subseteq soi(H_{AB})$.
KeldyshED.Hilbert.factorized_basis_map
— Functionfactorized_basis_map(
H_AB::KeldyshED.Hilbert.FullHilbertSpace,
H_A::KeldyshED.Hilbert.FullHilbertSpace
) -> Vector{Tuple{Int64, Int64}}
Given a Hilbert space $H_{AB}$ and its divisor $H_A$, factorize all Fock states $|\psi\rangle_{AB} \in H_{AB}$ into a direct product $|\psi\rangle_A \otimes |\psi\rangle_B$, where $|\psi\rangle_A \in H_A$, $|\psi\rangle_B \in H_{AB} / H_A$. Return a mapping (a vector of integer pairs) $k \mapsto (i, j)$, where $i$, $j$ and $k$ are linear indices of $|\psi\rangle_A$, $|\psi\rangle_B$ and $|\psi\rangle_{AB}$ within their respective spaces.
Sets of indices $soi(H_{AB})$, $soi(H_A)$ must satisfy $soi(H_A) \subseteq soi(H_{AB})$.
KeldyshED.Hilbert.HilbertSubspace
— TypeSubspace of a Hilbert space, as a list of basis Fock states.
This type supports vector-like iteration over Fock states, read-only indexed access and the operator in
.
Fields
fock_states::Vector{UInt64}
: List of all Fock states spanning the spacefock_to_index::Dict{UInt64, Int64}
: Reverse map to quickly find the index of a basis Fock state
Base.insert!
— Methodinsert!(
hss::KeldyshED.Hilbert.HilbertSubspace,
fs::UInt64
) -> Int64
Insert a basis Fock state fs
into a subspace hss
.
KeldyshED.Hilbert.getstateindex
— Functiongetstateindex(
fhs::KeldyshED.Hilbert.FullHilbertSpace,
fs::UInt64
) -> Int64
Find the index of a given Fock state fs
within a full Hilbert space fhs
.
getstateindex(
hss::KeldyshED.Hilbert.HilbertSubspace,
fs::UInt64
) -> Int64
Find the index of a given Fock state fs
within a subspace hss
.
Quantum states
KeldyshED.Hilbert.State
— TypeAbstract supertype of quantum state types
KeldyshED.Hilbert.StateVector
— TypeQuantum state in a Hilbert space/subspace implemented as a vector of amplitudes.
The amplitudes can be accessed using the indexing interface and iterated over. States support addition/subtraction and multiplication/division by a constant scalar.
Fields
hs::KeldyshED.Hilbert.HilbertSpace
: Hilbert space this state belongs toamplitudes::Vector
: Amplitudes of basis states contributing to this state
KeldyshED.Hilbert.StateVector
— MethodStateVector{HSType, S}(hs::HSType) where {HSType, S}
Create a vector-based state in a Hilbert space/subspace hs
with all amplitudes set to zero.
KeldyshED.Hilbert.StateDict
— TypeQuantum state in a Hilbert space/subspace implemented as a (sparse) dictionary of amplitudes.
The amplitudes can be accessed using the indexing interface and iterated over. States support addition/subtraction and multiplication/division by a constant scalar.
Fields
hs::KeldyshED.Hilbert.HilbertSpace
: Hilbert space this state belongs toamplitudes::Dict{Int64}
: Non-vanishing amplitudes of basis states contributing to this state. Each element of this dictionary is a pair (index of the basis state withinhs
, amplitude).
KeldyshED.Hilbert.StateDict
— MethodStateDict{HSType, S}(hs::HSType) where {HSType, S}
Create a dictionary-based state in a Hilbert space/subspace hs
with zero non-vanishing amplitudes.
Base.similar
— Functionsimilar(
sv::KeldyshED.Hilbert.StateVector{HSType, S}
) -> KeldyshED.Hilbert.StateVector
Create a vector-based state similar to sv
with all amplitudes set to zero.
similar(
sd::KeldyshED.Hilbert.StateDict{HSType, S}
) -> KeldyshED.Hilbert.StateDict
Create a dictionary-based state similar to sd
with zero non-vanishing amplitudes.
KeldyshED.Hilbert.dot
— Functiondot(
sv1::KeldyshED.Hilbert.StateVector,
sv2::KeldyshED.Hilbert.StateVector
) -> Any
Compute the scalar product of two vector-based states sv1
and sv2
.
dot(
sd1::KeldyshED.Hilbert.StateDict{HSType, S},
sd2::KeldyshED.Hilbert.StateDict{HSType, S}
) -> Any
Compute the scalar product of two dictionary-based states sd1
and sd2
.
KeldyshED.Hilbert.project
— Functionproject(
sv::KeldyshED.Hilbert.StateVector{HSType, S},
target_space
) -> KeldyshED.Hilbert.StateVector
Project a vector-based state sv
from one Hilbert space onto another Hilbert space/subspace target_space
.
project(
sd::KeldyshED.Hilbert.StateDict{HSType, S},
target_space
) -> KeldyshED.Hilbert.StateVector
Project a dictionary-based state sd
from one Hilbert space onto another Hilbert space/subspace target_space
.
Base.show
— Methodshow(io::IO, sv::KeldyshED.Hilbert.StateVector{HSType, S})
Print a vector-based state.
Base.show
— Methodshow(io::IO, sd::KeldyshED.Hilbert.StateDict{HSType, S})
Print a dictionary-based state.
Operators acting in Hilbert spaces
KeldyshED.Hilbert.Operator
— TypeQuantum-mechanical operator acting on states in a Hilbert space.
KeldyshED.Hilbert.Operator
— MethodOperator{HSType, S}(op_expr::OperatorExpr{S}, soi::SetOfIndices) where {HSType, S}
Make a linear operator acting on a Hilbert space/subspace out of a polynomial expression
op_expr
. The set soi
is used to establish a correspondence between compound indices of creation/annihilation operators met in op_expr
and the single-particle states – bits of FockState
.
Base.:*
— Method*(
op::KeldyshED.Hilbert.Operator,
st::KeldyshED.Hilbert.State
) -> Any
Act with an operator op
on a state st
and return the resulting state.
Space autopartition algorithm
KeldyshED.Hilbert.SpacePartition
— TypePartition of a Hilbert space into a set of disjoint subspaces invariant under action of a given Hermitian operator (Hamiltonian).
A detailed description of the algorithm can be found in Section 4.2 of Computer Physics Communications 200, March 2016, 274-284.
SpacePartition
supports iteration over pairs (index of a basis state of the Hilbert space, index of the invariant subspace that state belongs to).
Fields
hs::KeldyshED.Hilbert.HilbertSpace
: Full Hilbert space subject to partitioningsubspaces::DataStructures.IntDisjointSets
: Disjoint set of subspacesroot_to_index::Dict{Int64, Int64}
: Map root index to subspace indexmatrix_elements::SparseArrays.SparseMatrixCSC{ScalarType, Int64} where ScalarType<:Number
: Matrix elements of the Hamiltonian
KeldyshED.Hilbert.SpacePartition
— MethodSpacePartition{HSType, S}(hs::HSType,
H::OperatorType,
store_matrix_elements::Bool = true) where {
HSType <: HilbertSpace, S <: Number, OperatorType <: Operator}
Create a SpacePartition
structure by performing Phase I of the automatic partitioning algorithm, i.e. discovering the invariant subspaces of the Hermitian operator H
acting on the Hilbert space hs
.
If store_matrix_elements = true
, the field matrix_elements
of the created structure contains a sparse-matrix representation of H
.
KeldyshED.Hilbert.merge_subspaces!
— Functionmerge_subspaces!(sp, op)
merge_subspaces!(sp, op, store_matrix_elements)
Merge some of the invariant subspaces in sp
to ensure that the resulting subspaces are also invariant w.r.t. a given operator op
.
If store_matrix_elements = true
, a sparse-matrix representation of op
is returned.
merge_subspaces!(sp, Cd, C)
merge_subspaces!(sp, Cd, C, store_matrix_elements)
Perform Phase II of the automatic partition algorithm.
Merge some of the invariant subspaces in sp
to ensure that a given operator Cd
and its Hermitian conjugate C
generate only one-to-one connections between the subspaces.
If store_matrix_elements = true
, a tuple of two sparse matrices representing Cd
and C
is returned.
KeldyshED.Hilbert.numsubspaces
— Functionnumsubspaces(sp::KeldyshED.Hilbert.SpacePartition) -> Int64
Return the number of subspaces in a space partition sp
.
Base.getindex
— Methodgetindex(
sp::KeldyshED.Hilbert.SpacePartition,
index
) -> Int64
Find the invariant subspace within a partition sp
, the state with a given index
belongs to.