-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
373 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import numpy as np | ||
from timeit import default_timer as timer | ||
from renormalizer import Model, Op, BasisSimpleElectron, Mpo | ||
|
||
|
||
def fermiHubbardKS(N, t, U): | ||
toSite = lambda k, s: 2 * k + s | ||
|
||
terms = [] | ||
for k in range(N): | ||
for spin in (0, 1): | ||
factor = -2 * t * np.cos((2 * np.pi * k) / N) | ||
terms.append(Op(r"a^\dagger a", toSite(k, spin), factor)) | ||
|
||
for p in range(N): | ||
for q in range(N): | ||
for k in range(N): | ||
factor = U / N | ||
sites = [toSite((p - k) % N, 1), toSite((q + k) % N, 0), toSite(q, 0), toSite(p, 1)] | ||
terms.append(Op(r"a^\dagger a^\dagger a a", sites, factor)) | ||
|
||
model = Model([BasisSimpleElectron(i) for i in range(2 * N)], terms) | ||
return Mpo(model) | ||
|
||
numSites = [] | ||
bondDims = [] | ||
times = [] | ||
for N in [10, 20, 30, 40, 50]: | ||
start = timer() | ||
mpo = fermiHubbardKS(N, 1, 4) | ||
stop = timer() | ||
|
||
numSites.append(N) | ||
bondDims.append(max(mpo.bond_dims)) | ||
times.append(stop - start) | ||
|
||
print(f"N = {N}, time = {times[-1]}") | ||
|
||
print("numSites = ", numSites) | ||
print("bondDims = ", bondDims) | ||
print("times = ", times) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using ITensorMPOConstruction | ||
using ITensors | ||
|
||
function electronic_structure_example( | ||
N::Int, complexBasisFunctions::Bool; useITensorsAlg::Bool=false | ||
)::MPO | ||
coeff() = rand() + 1im * complexBasisFunctions * rand() | ||
|
||
os = complexBasisFunctions ? OpSum{ComplexF64}() : OpSum{Float64}() | ||
for a in 1:N | ||
for b in a:N | ||
epsilon_ab = coeff() | ||
os .+= epsilon_ab, "Cdagup", a, "Cup", b | ||
os .+= epsilon_ab, "Cdagdn", a, "Cdn", b | ||
|
||
a == b && continue | ||
os .+= conj(epsilon_ab), "Cdagup", b, "Cup", a | ||
os .+= conj(epsilon_ab), "Cdagdn", b, "Cdn", a | ||
end | ||
end | ||
|
||
for j in 1:N | ||
for s_j in ("dn", "up") | ||
for k in 1:N | ||
s_k = s_j | ||
(s_k, k) <= (s_j, j) && continue | ||
|
||
for l in 1:N | ||
for s_l in ("dn", "up") | ||
(s_l, l) <= (s_j, j) && continue | ||
|
||
for m in 1:N | ||
s_m = s_l | ||
(s_m, m) <= (s_k, k) && continue | ||
|
||
value = coeff() | ||
os .+= value, "Cdag$s_j", j, "Cdag$s_l", l, "C$s_m", m, "C$s_k", k | ||
os .+= conj(value), "Cdag$s_k", k, "Cdag$s_m", m, "C$s_l", l, "C$s_j", j | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
sites = siteinds("Electron", N; conserve_qns=true) | ||
|
||
## The only additional step required is to provide an operator basis in which to represent the OpSum. | ||
if useITensorsAlg | ||
return MPO(os, sites) | ||
else | ||
operatorNames = [ | ||
"I", | ||
"Cdn", | ||
"Cup", | ||
"Cdagdn", | ||
"Cdagup", | ||
"Ndn", | ||
"Nup", | ||
"Cup * Cdn", | ||
"Cup * Cdagdn", | ||
"Cup * Ndn", | ||
"Cdagup * Cdn", | ||
"Cdagup * Cdagdn", | ||
"Cdagup * Ndn", | ||
"Nup * Cdn", | ||
"Nup * Cdagdn", | ||
"Nup * Ndn", | ||
] | ||
|
||
opCacheVec = [ | ||
[OpInfo(ITensors.Op(name, n), sites[n]) for name in operatorNames] for | ||
n in eachindex(sites) | ||
] | ||
|
||
return MPO_new(os, sites; basisOpCacheVec=opCacheVec) | ||
end | ||
end | ||
|
||
let | ||
N = 25 | ||
|
||
# Ensure compilation | ||
electronic_structure_example(5, false) | ||
|
||
println("Constructing the Electronic Structure MPO for $N orbitals") | ||
@time mpo = electronic_structure_example(N, false) | ||
println("The maximum bond dimension is $(maxlinkdim(mpo))") | ||
end | ||
|
||
nothing; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.