Skip to content

Commit 9dbbb20

Browse files
authored
Merge pull request #107 from abhro/master
Docs and minor code updates
2 parents e173aaf + 6a8a9a9 commit 9dbbb20

File tree

11 files changed

+178
-140
lines changed

11 files changed

+178
-140
lines changed

docs/make.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using GreenFunc
22
using Documenter
3+
using Documenter.Remotes: GitHub
34

45
DocMeta.setdocmeta!(GreenFunc, :DocTestSetup, :(using GreenFunc); recursive=true)
56

67
makedocs(;
78
modules=[GreenFunc],
89
authors="Kun Chen, Tao Wang, Xiansheng Cai, PengCheng Hou, and Zhiyi Li",
9-
repo="https://github.com/numericaleft/GreenFunc.jl/blob/{commit}{path}#{line}",
10+
repo=GitHub("numericaleft/GreenFunc.jl"),
1011
sitename="GreenFunc.jl",
1112
format=Documenter.HTML(;
1213
prettyurls=get(ENV, "CI", "false") == "true",

docs/src/index.md

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,31 @@ GreenFunc.jl is a differentiable numerical framework to manipulate multidimensio
2222
- Interface to the [`TRIQS`](https://triqs.github.io/) library.
2323

2424
## Installation
25-
This package has been registered. So, simply type `import Pkg; Pkg.add("GreenFunc")` in the Julia REPL to install.
25+
This package has been registered. So, simply type
26+
```julia
27+
import Pkg; Pkg.add("GreenFunc")
28+
```
29+
in the Julia REPL to install.
2630

2731
## Basic Usage
2832

2933
### Example 1: Green's function of a single level
3034

3135
We first show how to use `MeshArray` to present Green's function of a single-level quantum system filled with spinless fermionic particles. We assume that the system could exchange particles and energy with the environment so that it's equilibrium state is a grand canonical ensemble. The single-particle Green's function then has a simple form in Matsubara-frequency representation: $G(ωₙ) = \frac{1}{(iωₙ - E)}$ where $E$ is the level energy. We show how to generate and manipulate this Green's function.
32-
33-
```julia
34-
using GreenFunc
3536

36-
β = 100.0; E = 1.0 # inverse temperature and the level energy
37-
ωₙ_mesh = MeshGrids.ImFreq(100.0, FERMION; Euv = 100E) # UV energy cutoff is 100 times larger than the level energy
38-
Gn = MeshArray(ωₙ_mesh; dtype=ComplexF64); # Green's function defined on the ωₙ_mesh
39-
40-
for (n, ωₙ) in enumerate(Gn.mesh[1])
41-
Gn[n] = 1/(ωₙ*im - E)
42-
end
37+
```julia
38+
using GreenFunc
39+
40+
# inverse temperature and the level energy
41+
β = 100.0; E = 1.0
42+
# UV energy cutoff is 100 times larger than the level energy
43+
ωₙ_mesh = MeshGrids.ImFreq(100.0, FERMION; Euv = 100E)
44+
# Green's function defined on the ωₙ_mesh
45+
Gn = MeshArray(ωₙ_mesh; dtype=ComplexF64)
46+
47+
for (n, ωₙ) in enumerate(Gn.mesh[1])
48+
Gn[n] = 1/(ωₙ*im - E)
49+
end
4350
```
4451

4552
- Green's function describes correlations between two or more spacetime events. The spacetime continuum needs to be discretized into spatial and temporal meshes. This example demonstrates how to define a one-body Green's function on a temporal mesh. The package provides three types of temporal meshes: imaginary-time grid, Matsubara-frequency grid, and DLR grid. The latter provides a generic compressed representation for Green's functions (We will show how to use DLR later). Correspondingly, They can be created with the `ImTime`, `ImFreq`, and `DLRFreq` methods. The user needs to specify the inverse temperature, whether the particle is fermion or boson (using the constant `FERMION` or `BOSON`). Internally, a set of non-uniform grid points optimized for the given inverse temperature and the cutoff energy will be created with the given parameters.
@@ -50,46 +57,51 @@ We first show how to use `MeshArray` to present Green's function of a single-lev
5057

5158
### Example 2: Green's function of a free electron gas
5259

53-
Now let us show how to create a Green's function of a free electron gas. Unlike the spinless fermionic particle, the electron is a spin-1/2 particle so that it has two inner states. In free space, it has a kinetic energy $ϵ_q = q^2-E$ (we use the unit where $m_e = 1/2$). The Green's function in Matsubara-frequency space is then given by the following equation: $G_n = G_{\sigma_1, \sigma_2}(q,\omega_n) = \frac{1}{i \omega_n - \epsilon_q}$, where $\sigma_i$ denotes the spins of the incoming and the outgoing electron in the propagator. We inherit the Matsubara-frequency grid from the first example. We show how to use the `CompositeGrids` package to generate momentum grids and how to treat the multiple inner states and the meshes with `MeshArray`.
60+
Now let us show how to create a Green's function of a free electron gas. Unlike the spinless fermionic particle, the electron is a spin-1/2 particle so that it has two inner states. In free space, it has a kinetic energy ``ϵ_q = q^2-E`` (we use the unit where ``m_e = 1/2``). The Green's function in Matsubara-frequency space is then given by the following equation: ``G_n = G_{\sigma_1, \sigma_2}(q,\omega_n) = \frac{1}{i \omega_n - \epsilon_q}``, where ``\sigma_i`` denotes the spins of the incoming and the outgoing electron in the propagator. We inherit the Matsubara-frequency grid from the first example. We show how to use the `CompositeGrids` package to generate momentum grids and how to treat the multiple inner states and the meshes with `MeshArray`.
5461
```julia
55-
using GreenFunc, CompositeGrids
56-
β = 100.0; E = 1.0 # inverse temperature and the level energy
57-
ωₙ_mesh = MeshGrids.ImFreq(100.0, FERMION; Euv = 100E) # UV energy cutoff is 100 times larger than the level energy
58-
kmesh = SimpleGrid.Uniform{Float64}([0.0, 10.0], 50); # initialze an uniform momentum grid
59-
G_n = MeshArray(1:2, 1:2, kmesh, ωₙ_mesh; dtype=ComplexF64); # Green's function of free electron gas with 2x2 innerstates
60-
61-
for ind in eachindex(G_n)
62-
q = G_n.mesh[3][ind[3]]
63-
ω_n = G_n.mesh[4][ind[4]]
64-
G_n[ind] = 1/(ω_n*im - (q^2-E))
65-
end
62+
using GreenFunc, CompositeGrids
63+
64+
# inverse temperature and the level energy
65+
β = 100.0; E = 1.0
66+
# UV energy cutoff is 100 times larger than the level energy
67+
ωₙ_mesh = MeshGrids.ImFreq(100.0, FERMION; Euv = 100E)
68+
# initialze an uniform momentum grid
69+
kmesh = SimpleGrid.Uniform{Float64}([0.0, 10.0], 50)
70+
# Green's function of free electron gas with 2x2 innerstates
71+
G_n = MeshArray(1:2, 1:2, kmesh, ωₙ_mesh; dtype=ComplexF64)
72+
73+
for ind in eachindex(G_n)
74+
q = G_n.mesh[3][ind[3]]
75+
ω_n = G_n.mesh[4][ind[4]]
76+
G_n[ind] = 1/(ω_n*im - (q^2-E))
77+
end
6678
```
6779
- One can generate various types of grids with the `CompositeGrids` package. The `SimpleGrid` module here provides several basic grids, such as uniform grids and logarithmically dense grids. The` Uniform` method here generates a 1D linearly spaced grid. The user has to specify the number of grid points `N` and the boundary points `[min, max]`. One can also combine arbitrary numbers of `SimpleGrid` subgrids with a user-specified pattern defined by a `panel grid`. These more advanced grids optimized for different purposes can be found in this [link](https://github.com/numericalEFT/CompositeGrids.jl).
6880

6981
- The constructor of `MeshArray` can take any iterable objects as one of its meshes. Therefore for discrete inner states such as spins, one can simply use a `1:2`, which is a `UnitRange{Int64}` object.
7082

7183
### Example 3: Green's function of a Hubbard lattice
7284

73-
Now we show how to generate a multi-dimensional Green's function on a Brillouin Zone meshe. We calculate the Green's function of a free spinless Fermi gas on a square lattice. It has a tight-binding dispersion $\epsilon_q = -2t(\cos(q_x)+\cos(q_y))$, which gives
74-
$G(q, \omega_n) = \frac{1}{i\omega_n - \epsilon_q}$.
85+
Now we show how to generate a multi-dimensional Green's function on a Brillouin Zone meshe. We calculate the Green's function of a free spinless Fermi gas on a square lattice. It has a tight-binding dispersion ``\epsilon_q = -2t(\cos(q_x)+\cos(q_y))``, which gives
86+
``G(q, \omega_n) = \frac{1}{i\omega_n - \epsilon_q}``.
7587
The momentum is defined on the first Brillouin zone captured by a 2D k-mesh.
7688

7789
```julia
78-
using GreenFunc
79-
using GreenFunc: BrillouinZoneMeshes
80-
81-
DIM, nk = 2, 8
82-
latvec = [1.0 0.0; 0.0 1.0] .* 2π
83-
bzmesh = BrillouinZoneMeshes.BaseMesh.UniformMesh{DIM, nk}([0.0, 0.0], latvec)
84-
ωₙmesh = ImFreq(10.0, FERMION)
85-
g_freq = MeshArray(bzmesh, ωₙmesh; dtype=ComplexF64)
86-
87-
t = 1.0
88-
for ind in eachindex(g_freq)
89-
q = g_freq.mesh[1][ind[1]]
90-
ωₙ = g_freq.mesh[2][ind[2]]
91-
g_freq[ind] = 1/(ωₙ*im - (-2*t*sum(cos.(q))))
92-
end
90+
using GreenFunc
91+
using GreenFunc: BrillouinZoneMeshes
92+
93+
DIM, nk = 2, 8
94+
latvec = [1.0 0.0; 0.0 1.0] .* 2π
95+
bzmesh = BrillouinZoneMeshes.BaseMesh.UniformMesh{DIM, nk}([0.0, 0.0], latvec)
96+
ωₙmesh = ImFreq(10.0, FERMION)
97+
g_freq = MeshArray(bzmesh, ωₙmesh; dtype=ComplexF64)
98+
99+
t = 1.0
100+
for ind in eachindex(g_freq)
101+
q = g_freq.mesh[1][ind[1]]
102+
ωₙ = g_freq.mesh[2][ind[2]]
103+
g_freq[ind] = 1/(ωₙ*im - (-2*t*sum(cos.(q))))
104+
end
93105
```
94106

95107
- For lattice systems with multi-dimensional Brillouin zone, the momentum grids internally generated with the [`BrillouinZoneMeshes.jl`](https://github.com/numericalEFT/BrillouinZoneMeshes.jl) package. Here a `UniformMesh{DIM,N}(origin, latvec)` generates a linearly spaced momentum mesh on the first Brillouin zone defined by origin and lattice vectors given. For more detail, see the [link](https://github.com/numericalEFT/BrillouinZoneMeshes.jl).
@@ -100,27 +112,27 @@ DLR provides a compact representation for one-body Green's functions. At a tempe
100112

101113
In the following example, we demonstrate how to perform DLR-based Fourier transform in `GreenFunc.jl` between the imaginary-time and the Matsubara-frequency domains back and forth through the DLR representation.
102114
```julia
103-
using GreenFunc, CompositeGrids
115+
using GreenFunc, CompositeGrids
104116

105-
β = 100.0; E = 1.0 # inverse temperature and the level energy
106-
ωₙ_mesh = ImFreq(100.0, FERMION; Euv = 100E) # UV energy cutoff is 100 times larger than the level energy
107-
kmesh = SimpleGrid.Uniform{Float64}([0.0, 10.0], 50); # initialze an uniform momentum grid
108-
G_n = MeshArray(1:2, 1:2, kmesh, ωₙ_mesh; dtype=ComplexF64); # Green's function of free electron gas with 2x2 innerstates
117+
β = 100.0; E = 1.0 # inverse temperature and the level energy
118+
ωₙ_mesh = ImFreq(100.0, FERMION; Euv = 100E) # UV energy cutoff is 100 times larger than the level energy
119+
kmesh = SimpleGrid.Uniform{Float64}([0.0, 10.0], 50); # initialze an uniform momentum grid
120+
G_n = MeshArray(1:2, 1:2, kmesh, ωₙ_mesh; dtype=ComplexF64); # Green's function of free electron gas with 2x2 innerstates
109121

110-
for ind in eachindex(G_n)
111-
q = G_n.mesh[3][ind[3]]
112-
ω_n = G_n.mesh[4][ind[4]]
113-
G_n[ind] = 1/(im*ω_n - (q^2-E))
114-
end
122+
for ind in eachindex(G_n)
123+
q = G_n.mesh[3][ind[3]]
124+
ω_n = G_n.mesh[4][ind[4]]
125+
G_n[ind] = 1/(im*ω_n - (q^2-E))
126+
end
115127

116-
G_dlr = to_dlr(G_n) # convert G_n to DLR space
117-
G_tau = to_imtime(G_dlr) # convert G_dlr to the imaginary-time domain
128+
G_dlr = to_dlr(G_n) # convert G_n to DLR space
129+
G_tau = to_imtime(G_dlr) # convert G_dlr to the imaginary-time domain
118130

119-
#alternative, you can use the pipe operator
120-
G_tau = G_n |> to_dlr |> to_imtime #Fourier transform to (k, tau) domain
131+
#alternative, you can use the pipe operator
132+
G_tau = G_n |> to_dlr |> to_imtime #Fourier transform to (k, tau) domain
121133

122134
```
123-
The imaginary-time Green's function after the Fourier transform shoud be consistent with the analytic solution $G_{\tau} = -e^{-\tau \epsilon_q}/(1+e^{-\beta \epsilon_q})$.
135+
The imaginary-time Green's function after the Fourier transform shoud be consistent with the analytic solution ``G_{\tau} = -e^{-\tau \epsilon_q}/(1+e^{-\beta \epsilon_q})``.
124136

125137
- For any Green's function that has at least one imaginary-temporal grid (`ImTime`, `ImFreq`, and `DLRFreq`) in meshes, we provide a set of operations (`to_dlr`, `to_imfreq` and `to_imtime`) to bridge the DLR space with imaginary-time and Matsubara-frequency space. By default, all these functions find the dimension of the imaginary-temporal mesh within Green's function meshes and perform the transformation with respect to it. Alternatively, one can specify the dimension with the optional keyword argument `dim`. Be careful that the original version of DLR is only guaranteed to work with one-body Green's function.
126138

example/SYK.jl

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
"""
22
A SYK model solver based on a forward fixed-point iteration method.
33
4-
The self-energy of the SYK model is given by,
4+
The self-energy of the SYK model is given by,
55
6-
Σ(τ) = J² * G(τ) * G(τ) * G(β-τ),
6+
```math
7+
Σ(τ) = J² * G(τ) * G(τ) * G(β-τ),
8+
```
79
8-
where Green's function of the SYK model is given by the Dyson equation,
10+
where Green's function of the SYK model is given by the Dyson equation,
911
10-
G(iωₙ) = -1/(iωₙ -μ + Σ(iωₙ))
12+
```math
13+
G(iωₙ) = -1/(iωₙ -μ + Σ(iωₙ))
14+
```
1115
12-
We solve the Dyson equation self-consistently by a weighted fixed point iteration,
13-
with weight `mix` assigned to the new iterate and weight `1-mix` assigned to the previous iterate.
16+
We solve the Dyson equation self-consistently by a weighted fixed point iteration,
17+
with weight `mix` assigned to the new iterate and weight `1-mix` assigned to the previous iterate.
1418
15-
The self-energy is evaluated in the imaginary time domain,
16-
and the Dyson equation is solved in the Matsubara frequency domain.
19+
The self-energy is evaluated in the imaginary time domain,
20+
and the Dyson equation is solved in the Matsubara frequency domain.
1721
18-
The SYK Green's function has particle-hole symmetry when μ=0.
19-
You may enforce such symmetry by setting `symmetry = :ph` when initialize the DLR grids.
20-
A symmetrized solver tends to be more robust than a unsymmetrized one.
22+
The SYK Green's function has particle-hole symmetry when μ=0.
23+
You may enforce such symmetry by setting `symmetry = :ph` when initialize the DLR grids.
24+
A symmetrized solver tends to be more robust than a unsymmetrized one.
2125
"""
2226

2327
using GreenFunc
@@ -76,4 +80,3 @@ for (i, t) in enumerate(G.mesh[1])
7680
@printf("%15.8f%40.15f%40.15f%40.15f\n", t, imag(G[i]), real(G[i]), conformal_tau(t, β))
7781
end
7882
println()
79-

src/green/DictParser.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module DictParser
33
export evalwithdict
44

55
"""
6-
evalwithdict(e::Union{Expr,Symbol,Number}, map::Dict{Symbol,Number})
6+
evalwithdict(e::Union{Expr,Symbol,Number}, map::Dict{Symbol,Number})
77
88
Evaluate the result produced by Meta.parse, looking up the values of
99
user-defined variables in "map". Argument "e" is a Union, because
@@ -79,4 +79,4 @@ end
7979
function f(::Val{:^}, args, map::Dict{Symbol,Number})
8080
return f(args[1], map) ^ f(args[2], map)
8181
end
82-
end # module MyEval
82+
end # module MyEval

0 commit comments

Comments
 (0)