Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
kyungminlee committed Aug 30, 2020
2 parents e7265a1 + 825c03e commit 82af2bc
Show file tree
Hide file tree
Showing 27 changed files with 102 additions and 57 deletions.
7 changes: 0 additions & 7 deletions .travis.yml
Expand Up @@ -20,13 +20,6 @@ matrix:
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder()); Coveralls.submit(process_folder())'
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- julia --project=docs/ docs/make.jl
- julia: 1.6
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- git clone https://github.com/JuliaRegistries/General.git $HOME/.julia/registries/General
- git clone https://github.com/kyungminlee/KyungminLeeRegistry.jl.git $HOME/.julia/registries/KyungminLeeRegistry
- julia --project -e 'import Pkg; Pkg.build()'
- JULIA_NUM_THREADS=2 julia --project --check-bounds=yes -e 'import Pkg; Pkg.test(; coverage=false)'
- julia: nightly
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
Expand Down
6 changes: 2 additions & 4 deletions Project.toml
@@ -1,18 +1,16 @@
name = "ExactDiagonalization"
uuid = "cf149b0a-e8f7-4f00-9ab4-03e4f5ec5cff"
authors = ["Kyungmin Lee <kyungmin.lee.42@gmail.com>"]
version = "0.11"
version = "0.12.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
LatticeTools = "8a267902-5e0e-44c3-8ef8-9b2b5c352816"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Memento = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
TightBindingLattice = "f0da6d2f-861b-4198-860c-d50f6f65dfeb"

[compat]
TightBindingLattice = ">= 0.6"
julia = ">= 1.5"

[extras]
Expand Down
2 changes: 0 additions & 2 deletions appveyor.yml
@@ -1,13 +1,11 @@
environment:
matrix:
- julia_version: 1.5
- julia_version: 1.6
- julia_version: nightly
platform:
- x64
matrix:
allow_failures:
- julia_version: 1.6
- julia_version: nightly
branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Expand Up @@ -2,6 +2,6 @@
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
ExactDiagonalization = "cf149b0a-e8f7-4f00-9ab4-03e4f5ec5cff"
LatticeTools = "8a267902-5e0e-44c3-8ef8-9b2b5c352816"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
TightBindingLattice = "f0da6d2f-861b-4198-860c-d50f6f65dfeb"
4 changes: 3 additions & 1 deletion docs/make.jl
Expand Up @@ -16,7 +16,9 @@ makedocs(
"Representation" => "representation.md",
"Symmetry" => "symmetry.md"
],
"Examples" => "examples.md",
"Examples" => [
"examples/spinhalf.md",
],
"Index" => "links.md",
"API" => "api.md",
]
Expand Down
6 changes: 2 additions & 4 deletions docs/src/examples.md → docs/src/examples/spinhalf.md
@@ -1,14 +1,12 @@
# Examples

## S=1/2 Heisenberg Chain
# Example 1: S=1/2 Heisenberg Chain

```@example
using SparseArrays
using LinearAlgebra
using Arpack
using Plots
using TightBindingLattice
using LatticeTools
using ExactDiagonalization
println("# S=1/2 Heisenberg Chain")
Expand Down
33 changes: 23 additions & 10 deletions docs/src/hilbertspace.md
Expand Up @@ -9,14 +9,18 @@ and the Hilbert space for whole system can be constructed by taking the tensor p

A [`Site`](@ref) can be constructed out of a set of [`State`](@ref).
For example,
```julia
spinsite = Site{Int}([State{Int}("Up", 1), State{Int}("Dn", -1)])
```julia-repl
julia> spinsite = Site([State("Up", 1), State("Dn", -1)])
Site{Tuple{Int64}}(State{Tuple{Int64}}[State{Tuple{Int64}}("Up", (1,)), State{Tuple{Int64}}("Dn", (-1,))])
```
constructs a two-state site with spin-half degrees of freedom.
The type parameter `Int` is the type of the Abelian quantum number, which, in this case, is $2S_z$.
Each basis vector is represented as a (0-based) binary number,
corresponding to their order in the constructor.
For the example above, the up-state is represented by a `0` and the down-state is represented by a `1`.
The type parameter `Tuple{Int}` represents the type of Abelian quantum number.
which is is $2S_z$ in this case.
When there are more than one conserved quantum numbers, they can be combined:
e.g. `Tuple{Int, Int}`, to represent the charge and total $S_z$, for example.
Each basis vector is represented as a binary number,
corresponding to their order in the constructor (0-based).
For the example above, the up-state is represented as `0` and the down-state is represented as `1`.

## HilbertSpace

Expand All @@ -35,15 +39,24 @@ where each `Site` occupies a fixed location and width. e.g.
|↓↓↓↓⟩ = |1111⟩
```
The number of bits assigned for each site is determined by `Int(ceil(log2(length(site.states)))`, and can be accessed by [`bitwidth`](@ref).

## HilbertSpaceSector

A sub Hilbert space, in terms of the Abelian quantum number, can be constructed
using [`HilbertSpaceSector`](@ref), by specifying the value of the quantum number
A subspace of the whole Hilbert space, in terms of the Abelian quantum number, can be constructed using [`HilbertSpaceSector`](@ref), by specifying the value of the quantum number as an integer if the Hilbert space has a single integral quantum number,
```julia
hilbert_space_sector = HilbertSpaceSector(hilbert_space, 0)
```
or a set of quantum number values, if you need to for whatever reason
or as a tuple
```julia
hilbert_space_sector = HilbertSpaceSector(hilbert_space, (0,))
```
You can also allow more than one quantum number values, if you need to for whatever reason
```julia
hilbert_space_sector = HilbertSpaceSector(hilbert_space, [(0,), (2,), (4,)])
```
or more shortly,
```julia
hilbert_space_sector = HilbertSpaceSector(hilbert_space, [0,2,4])
hilbert_space_sector = HilbertSpaceSector(hilbert_space, [0, 2, 4])
```
This example creates a subspace whose quantum numbers can be one of 0, 2, and 4.
6 changes: 3 additions & 3 deletions docs/src/index.md
Expand Up @@ -28,9 +28,9 @@ of the Hilbert spaces as 𝐂ⁿ (or 𝐑ⁿ), and of operators as n×n matrices
First you need to create a Hilbert space representation:
1. Define `State`s, and `Site`s
1. Define the `HilbertSpace`
1. If there is quantum number, use that to define `HilbertSpaceSector`
1. If there are quantum numbers, use them to define `HilbertSpaceSector`
1. Define `HilbertSpaceRepresentation` and construct basis set
1. If there is translation symmetry, use that to define `ReducedHilbertSpaceRepresentation`
1. If there is space symmetry, translation or point or both, use that to define `ReducedHilbertSpaceRepresentation`

And then you can create operator representation using the Hilbert space representation from above:
1. Define `Operator`s
Expand All @@ -44,7 +44,7 @@ can install it using its URL as
```julia
]add https://github.com/kyungminlee/ExactDiagonalization.jl.git
```
Since, however, `ExactDiagonalization.jl` depends on other packages including [`TightBindingLattice.jl`](https://github.com/kyungminlee/TightBindingLattice.jl), it is convenient to add a custom registry.
Since, however, `ExactDiagonalization.jl` depends on other packages including [`LatticeTools.jl`](https://github.com/kyungminlee/LatticeTools.jl), it is convenient to add a custom registry.
In Julia, type
```sh
]registry add https://github.com/kyungminlee/KyungminLeeRegistry.jl.git
Expand Down
4 changes: 4 additions & 0 deletions docs/src/operator.md
@@ -1,5 +1,9 @@
# Operator

`ExactDiagonalization.jl` uses operators in the "projector" representation.



## Operator Types

### NullOperator
Expand Down
8 changes: 4 additions & 4 deletions examples/spinhalf_triangular.jl
@@ -1,6 +1,6 @@
using LinearAlgebra
using ExactDiagonalization
using TightBindingLattice
using LatticeTools
using Arpack

#=
Expand All @@ -21,7 +21,7 @@ function make_triangular_lattice(shape::AbstractMatrix{<:Integer})
nnnbondtypes = [ [ 2, 1], [ 1, 2], [-1, 1] ]

lattice = make_lattice(unitcell, shape)
orthocube = lattice.orthocube
hypercube = lattice.hypercube
supercell = lattice.supercell
tsym = TranslationSymmetry(lattice)
psym = little_symmetry(tsym, PointSymmetryDatabase.find2d("6mm"))
Expand All @@ -34,15 +34,15 @@ function make_triangular_lattice(shape::AbstractMatrix{<:Integer})

for r_row in lattice.bravais_coordinates
for colvec in nnbondtypes
R_col, r_col = orthocube.wrap(r_row .+ colvec)
R_col, r_col = hypercube.wrap(r_row .+ colvec)
roworb_super = ("A", r_row)
colorb_super = ("A", r_col)
irow = get(supercell.siteindices, roworb_super, -1)
icol = get(supercell.siteindices, colorb_super, -1)
push!(nnbonds, ((irow, icol), R_col))
end
for colvec in nnnbondtypes
R_col, r_col = orthocube.wrap(r_row .+ colvec)
R_col, r_col = hypercube.wrap(r_row .+ colvec)
roworb_super = ("A", r_row)
colorb_super = ("A", r_col)
irow = get(supercell.siteindices, roworb_super, -1)
Expand Down
2 changes: 1 addition & 1 deletion examples/spinhalfchain.jl
@@ -1,7 +1,7 @@
using SparseArrays
using LinearAlgebra
using ExactDiagonalization
using TightBindingLattice
using LatticeTools
using MinimalPerfectHash

n_sites = 7;
Expand Down
2 changes: 1 addition & 1 deletion examples/spinhalfchain2.jl
@@ -1,7 +1,7 @@
using SparseArrays
using LinearAlgebra
using ExactDiagonalization
using TightBindingLattice
using LatticeTools
using MinimalPerfectHash

## Set up lattice
Expand Down
2 changes: 1 addition & 1 deletion examples/spinhalfsquare_bigsize.jl
@@ -1,7 +1,7 @@
using SparseArrays
using LinearAlgebra
using ExactDiagonalization
using TightBindingLattice
using LatticeTools
using MinimalPerfectHash

@show Threads.nthreads()
Expand Down
2 changes: 1 addition & 1 deletion examples/spinhalfsquare_large.jl
Expand Up @@ -2,7 +2,7 @@ using Test
using SparseArrays
using LinearAlgebra
using ExactDiagonalization
using TightBindingLattice
using LatticeTools
using MinimalPerfectHash
using Printf

Expand Down
2 changes: 1 addition & 1 deletion examples/spinhalfsquare_small.jl
@@ -1,7 +1,7 @@
using SparseArrays
using LinearAlgebra
using ExactDiagonalization
using TightBindingLattice
using LatticeTools
using MinimalPerfectHash

@show Threads.nthreads()
Expand Down
2 changes: 1 addition & 1 deletion examples/testexample.jl
Expand Up @@ -3,7 +3,7 @@ using LinearAlgebra
using Arpack
using Plots

using TightBindingLattice
using LatticeTools
using ExactDiagonalization

println("# S=1/2 Heisenberg Chain")
Expand Down
2 changes: 1 addition & 1 deletion src/ExactDiagonalization.jl
Expand Up @@ -11,7 +11,7 @@ using SparseArrays
#end

# workaround?
import TightBindingLattice.dimension
import LatticeTools.dimension

include("util.jl")
include("frozensortedarray.jl")
Expand Down
30 changes: 27 additions & 3 deletions src/HilbertSpace/hilbert_space_sector.jl
Expand Up @@ -14,21 +14,41 @@ struct HilbertSpaceSector{QN<:Tuple{Vararg{<:AbstractQuantumNumber}}}<:AbstractH
parent::HilbertSpace{QN}
allowed_quantum_numbers::Set{QN}

"""
HilbertSpaceSector(parent::HilbertSpace{QN}) where QN
"""
function HilbertSpaceSector(parent::HilbertSpace{QN}) where QN
sectors = quantum_number_sectors(parent)
return new{QN}(parent, Set(sectors))
end

"""
HilbertSpaceSector(parent::HilbertSpace{QN}, allowed::Integer) where {QN<:Tuple{<:Integer}}
"""
function HilbertSpaceSector(parent::HilbertSpace{QN}, allowed::Integer) where {QN<:Tuple{<:Integer}}
sectors = Set{QN}(quantum_number_sectors(parent))
return new{QN}(parent, intersect(sectors, Set([(allowed,)])))
end

"""
HilbertSpaceSector(parent::HilbertSpace{QN}, allowed::QN) where QN
"""
function HilbertSpaceSector(parent::HilbertSpace{QN}, allowed::QN) where QN
sectors = Set{QN}(quantum_number_sectors(parent))
return new{QN}(parent, intersect(sectors, Set([allowed])))
end

"""
HilbertSpaceSector(parent::HilbertSpace{QN}, allowed::Union{AbstractSet{<:Integer}, AbstractVector{<:Integer}}) where QN
"""
function HilbertSpaceSector(
parent::HilbertSpace{QN},
allowed::Union{AbstractSet{<:Integer}, AbstractVector{<:Integer}}
) where QN
sectors = Set{QN}(quantum_number_sectors(parent))
return new{QN}(parent, intersect(sectors, Set((x,) for x in allowed)))
end

function HilbertSpaceSector(
parent::HilbertSpace{QN},
allowed::Union{AbstractSet{QN}, AbstractVector{QN}}
Expand Down Expand Up @@ -76,9 +96,7 @@ its parent `HilbertSpace` (with no quantum number restriction).
"""
basespace(hss::HilbertSpaceSector{QN}) where QN = basespace(hss.parent)::HilbertSpace{QN}


bitwidth(hss::HilbertSpaceSector) = bitwidth(basespace(hss))

#bitwidth(hss::HilbertSpaceSector) = bitwidth(basespace(hss))

function Base.:(==)(lhs::HilbertSpaceSector{Q1}, rhs::HilbertSpaceSector{Q2}) where {Q1, Q2}
return (
Expand All @@ -89,6 +107,7 @@ end


for fname in [
:bitwidth,
:get_bitmask,
:quantum_number_sectors,
:get_quantum_number,
Expand All @@ -99,6 +118,11 @@ for fname in [
:get_state,
]
@eval begin
"""
$($fname)(hss::HilbertSpaceSector, args...;kwargs...)
Call `$($fname)` with basespace of `hss`.
"""
@inline $fname(hss::HilbertSpaceSector, args...;kwargs...) = $fname(hss.parent, args...; kwargs...)
end
end
11 changes: 10 additions & 1 deletion src/HilbertSpace/sparse_state.jl
Expand Up @@ -8,7 +8,7 @@ import LinearAlgebra
"""
struct SparseState{Scalar<:Number, BR}
Represents a row vector. Free.
Represents a vector in unrestricted Hilbert space.
"""
mutable struct SparseState{Scalar<:Number, BR}
components::Dict{BR, Scalar}
Expand All @@ -24,6 +24,10 @@ mutable struct SparseState{Scalar<:Number, BR}
return new{Scalar, BR}(components)
end

function SparseState(components::Pair{BR, Scalar}...) where {Scalar, BR}
return new{Scalar, BR}(Dict{BR, Scalar}(components))
end

function SparseState{Scalar, BR}(binrep::BR) where {Scalar, BR}
return new{Scalar, BR}(Dict{BR, Scalar}(binrep => one(Scalar)))
end
Expand Down Expand Up @@ -56,6 +60,11 @@ function Base.setindex!(
end


"""
scalartype([state or type of state])
Return the scalar type of the state.
"""
scalartype(::SparseState{Scalar, BR}) where {Scalar, BR} = Scalar
scalartype(::Type{SparseState{Scalar, BR}}) where {Scalar, BR} = Scalar

Expand Down
5 changes: 5 additions & 0 deletions src/Operator/abstract_operator.jl
Expand Up @@ -7,6 +7,11 @@ export bintype
import LinearAlgebra


"""
AbstractOperator{S<:Number}
Represent an abstract operator in Hilbert space.
"""
abstract type AbstractOperator{S<:Number} end


Expand Down
2 changes: 1 addition & 1 deletion src/Operator/apply_sparse_state.jl
Expand Up @@ -3,7 +3,7 @@ export apply!


"""
apply!
apply!(out, nullop, psi)
Apply operator to `psi` and add it to `out`.
"""
Expand Down

0 comments on commit 82af2bc

Please sign in to comment.