|
| 1 | +module ModelHamiltonians |
| 2 | +using Dictionaries: AbstractDictionary |
| 3 | +using Graphs: AbstractGraph, dst, edges, edgetype, neighborhood, path_graph, src, vertices |
| 4 | +using ITensors.Ops: OpSum |
| 5 | + |
| 6 | +to_callable(value::Type) = value |
| 7 | +to_callable(value::Function) = value |
| 8 | +to_callable(value::AbstractDict) = Base.Fix1(getindex, value) |
| 9 | +to_callable(value::AbstractDictionary) = Base.Fix1(getindex, value) |
| 10 | +function to_callable(value::AbstractArray{<:Any,N}) where {N} |
| 11 | + getindex_value(x::Integer) = value[x] |
| 12 | + getindex_value(x::Tuple{Vararg{Integer,N}}) = value[x...] |
| 13 | + getindex_value(x::CartesianIndex{N}) = value[x] |
| 14 | + return getindex_value |
| 15 | +end |
| 16 | +to_callable(value) = Returns(value) |
| 17 | + |
| 18 | +# TODO: Move to `NamedGraphs.jl` or `GraphsExtensions.jl`. |
| 19 | +# TODO: Add a tet for this. |
| 20 | +function nth_nearest_neighbors(g, v, n::Int) |
| 21 | + isone(n) && return neighborhood(g, v, 1) |
| 22 | + return setdiff(neighborhood(g, v, n), neighborhood(g, v, n - 1)) |
| 23 | +end |
| 24 | + |
| 25 | +# TODO: Move to `NamedGraphs.jl` or `GraphsExtensions.jl`. |
| 26 | +# TODO: Add a tet for this. |
| 27 | +next_nearest_neighbors(g, v) = nth_nearest_neighbors(g, v, 2) |
| 28 | + |
| 29 | +function tight_binding(g::AbstractGraph; t=1, tp=0, h=0) |
| 30 | + (; t, tp, h) = map(to_callable, (; t, tp, h)) |
| 31 | + h = to_callable(h) |
| 32 | + ℋ = OpSum() |
| 33 | + for e in edges(g) |
| 34 | + ℋ -= t(e), "Cdag", src(e), "C", dst(e) |
| 35 | + ℋ -= t(e), "Cdag", dst(e), "C", src(e) |
| 36 | + end |
| 37 | + for v in vertices(g) |
| 38 | + for nn in next_nearest_neighbors(g, v) |
| 39 | + e = edgetype(g)(v, nn) |
| 40 | + ℋ -= tp(e), "Cdag", src(e), "C", dst(e) |
| 41 | + ℋ -= tp(e), "Cdag", dst(e), "C", src(e) |
| 42 | + end |
| 43 | + end |
| 44 | + for v in vertices(g) |
| 45 | + ℋ -= h(v), "N", v |
| 46 | + end |
| 47 | + return ℋ |
| 48 | +end |
| 49 | + |
| 50 | +""" |
| 51 | +t-t' Hubbard Model g,i,v |
| 52 | +""" |
| 53 | +function hubbard(g::AbstractGraph; U=0, t=1, tp=0, h=0) |
| 54 | + (; U, t, tp, h) = map(to_callable, (; U, t, tp, h)) |
| 55 | + ℋ = OpSum() |
| 56 | + for e in edges(g) |
| 57 | + ℋ -= t(e), "Cdagup", src(e), "Cup", dst(e) |
| 58 | + ℋ -= t(e), "Cdagup", dst(e), "Cup", src(e) |
| 59 | + ℋ -= t(e), "Cdagdn", src(e), "Cdn", dst(e) |
| 60 | + ℋ -= t(e), "Cdagdn", dst(e), "Cdn", src(e) |
| 61 | + end |
| 62 | + for v in vertices(g) |
| 63 | + for nn in next_nearest_neighbors(g, v) |
| 64 | + e = edgetype(g)(v, nn) |
| 65 | + ℋ -= tp(e), "Cdagup", src(e), "Cup", dst(e) |
| 66 | + ℋ -= tp(e), "Cdagup", dst(e), "Cup", src(e) |
| 67 | + ℋ -= tp(e), "Cdagdn", src(e), "Cdn", dst(e) |
| 68 | + ℋ -= tp(e), "Cdagdn", dst(e), "Cdn", src(e) |
| 69 | + end |
| 70 | + end |
| 71 | + for v in vertices(g) |
| 72 | + ℋ -= h(v), "Sz", v |
| 73 | + ℋ += U(v), "Nupdn", v |
| 74 | + end |
| 75 | + return ℋ |
| 76 | +end |
| 77 | + |
| 78 | +""" |
| 79 | +Random field J1-J2 Heisenberg model on a general graph |
| 80 | +""" |
| 81 | +function heisenberg(g::AbstractGraph; J1=1, J2=0, h=0) |
| 82 | + (; J1, J2, h) = map(to_callable, (; J1, J2, h)) |
| 83 | + ℋ = OpSum() |
| 84 | + for e in edges(g) |
| 85 | + ℋ += J1(e) / 2, "S+", src(e), "S-", dst(e) |
| 86 | + ℋ += J1(e) / 2, "S-", src(e), "S+", dst(e) |
| 87 | + ℋ += J1(e), "Sz", src(e), "Sz", dst(e) |
| 88 | + end |
| 89 | + for v in vertices(g) |
| 90 | + for nn in next_nearest_neighbors(g, v) |
| 91 | + e = edgetype(g)(v, nn) |
| 92 | + ℋ += J2(e) / 2, "S+", src(e), "S-", dst(e) |
| 93 | + ℋ += J2(e) / 2, "S-", src(e), "S+", dst(e) |
| 94 | + ℋ += J2(e), "Sz", src(e), "Sz", dst(e) |
| 95 | + end |
| 96 | + end |
| 97 | + for v in vertices(g) |
| 98 | + ℋ += h(v), "Sz", v |
| 99 | + end |
| 100 | + return ℋ |
| 101 | +end |
| 102 | + |
| 103 | +""" |
| 104 | +Random field J1-J2 Heisenberg model on a chain of length N |
| 105 | +""" |
| 106 | +heisenberg(N::Integer; kwargs...) = heisenberg(path_graph(N); kwargs...) |
| 107 | + |
| 108 | +""" |
| 109 | +Next-to-nearest-neighbor Ising model (ZZX) on a general graph |
| 110 | +""" |
| 111 | +function ising(g::AbstractGraph; J1=-1, J2=0, h=0) |
| 112 | + (; J1, J2, h) = map(to_callable, (; J1, J2, h)) |
| 113 | + ℋ = OpSum() |
| 114 | + for e in edges(g) |
| 115 | + ℋ += J1(e), "Sz", src(e), "Sz", dst(e) |
| 116 | + end |
| 117 | + for v in vertices(g) |
| 118 | + for nn in next_nearest_neighbors(g, v) |
| 119 | + e = edgetype(g)(v, nn) |
| 120 | + # TODO: Try removing this if-statement. This |
| 121 | + # helps to avoid constructing next-nearest |
| 122 | + # neighbor gates, which `apply` can't handle |
| 123 | + # right now. We could skip zero terms in gate |
| 124 | + # construction. |
| 125 | + if !iszero(J2(e)) |
| 126 | + ℋ += J2(e), "Sz", src(e), "Sz", dst(e) |
| 127 | + end |
| 128 | + end |
| 129 | + end |
| 130 | + for v in vertices(g) |
| 131 | + ℋ += h(v), "Sx", v |
| 132 | + end |
| 133 | + return ℋ |
| 134 | +end |
| 135 | + |
| 136 | +""" |
| 137 | +Next-to-nearest-neighbor Ising model (ZZX) on a chain of length N |
| 138 | +""" |
| 139 | +ising(N::Integer; kwargs...) = ising(path_graph(N); kwargs...) |
| 140 | +end |
0 commit comments