Skip to content

Commit 600a7ff

Browse files
committed
translate anderson and jperp tests into python
1 parent 413780e commit 600a7ff

File tree

12 files changed

+204
-224
lines changed

12 files changed

+204
-224
lines changed

c++/triqs_ctseg/work_data.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ namespace triqs_ctseg {
5252

5353
// Print block/index/color correspondence
5454
if (c.rank() == 0) {
55+
spdlog::info("\n");
5556
for (auto const &color : range(n_color)) {
5657
spdlog::info("Block: {} Index: {} Color: {}", gf_struct[block_number[color]].first, index_in_block[color],
5758
color);
@@ -73,8 +74,8 @@ namespace triqs_ctseg {
7374

7475
// Report
7576
if (c.rank() == 0) {
76-
spdlog::info("Interaction matrix: U = {}", U);
77-
spdlog::info("Orbital energies: mu - eps = {}", mu);
77+
spdlog::info("\n Interaction matrix: U = {} \n", U);
78+
spdlog::info("Orbital energies: mu - eps = {} \n", mu);
7879
}
7980

8081
// Dynamical interactions: convert Block2Gf to matrix Gf of size n_colors
@@ -164,7 +165,7 @@ namespace triqs_ctseg {
164165

165166
// Report
166167
if (c.rank() == 0) {
167-
spdlog::info("Dynamical interactions = {}, Jperp interactions = {}", has_Dt, has_Jperp);
168+
spdlog::info("Dynamical interactions = {}, Jperp interactions = {} \n", has_Dt, has_Jperp);
168169
if (p.measure_F_tau and !rot_inv)
169170
spdlog::info("WARNING: Cannot measure F(tau) because spin-spin interaction is not rotationally invariant.");
170171
}

test/c++/Jperp.cpp

Lines changed: 0 additions & 106 deletions
This file was deleted.

test/c++/Jperp.ref.h5

-309 KB
Binary file not shown.

test/c++/dynamical_U.cpp

Lines changed: 0 additions & 115 deletions
This file was deleted.

test/c++/dynamical_U.ref.h5

-475 KB
Binary file not shown.

test/python/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ endforeach()
66

77
# List of all tests
88
set(all_tests
9+
./anderson
10+
./dynamical_U
11+
./Jperp
912
./spin_spin
1013
./two_orbitals
1114
./multiorb

test/python/Jperp.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Single orbital with Jperp interaction and no hybridization
2+
from triqs.gf import *
3+
import triqs.utility.mpi as mpi
4+
from triqs.gf.descriptors import Function
5+
from triqs.operators import n
6+
import h5
7+
from triqs.utility.h5diff import h5diff
8+
from triqs_ctseg import SolverCore as Solver
9+
10+
# Numerical values
11+
beta = 10
12+
U = 4.0
13+
mu = U/2
14+
eps = 0.2
15+
n_tau = 2051
16+
n_tau_bosonic = 2001
17+
wp = 1
18+
g = 4
19+
20+
# Solver construction parameters
21+
gf_struct = [('down', 1), ('up', 1)]
22+
constr_params = {
23+
"gf_struct": gf_struct,
24+
"beta": beta,
25+
"n_tau": n_tau,
26+
"n_tau_bosonic": n_tau_bosonic
27+
}
28+
29+
# Construct solver
30+
S = Solver(**constr_params)
31+
32+
# Jperp interaction
33+
d0_iw = GfImFreq(indices=[0], beta=beta, statistic="Boson", n_points=n_tau_bosonic//2)
34+
d0_tau = GfImTime(indices=[0], beta=beta, statistic="Boson", n_points=n_tau_bosonic)
35+
d0_iw << Function(lambda w: g * wp**2 / (w**2 - wp**2))
36+
d0_tau << Fourier(d0_iw)
37+
S.Jperp_tau << d0_tau
38+
39+
# Solve parameters
40+
solve_params = {
41+
"h_int": U*n("up", 0)*n("down", 0),
42+
"h_loc0": -mu * (n("up", 0) + n("down", 0)),
43+
"length_cycle": 50,
44+
"n_warmup_cycles": 1000,
45+
"n_cycles": 10000,
46+
"measure_nn_tau": True,
47+
"measure_nn_static": True
48+
}
49+
50+
# Solve
51+
S.solve(**solve_params)
52+
53+
# Save and compare to reference
54+
if mpi.is_master_node():
55+
with h5.HDFArchive("Jperp.out.h5", 'w') as A:
56+
A['G_tau'] = S.results.G_tau
57+
A['nn_tau'] = S.results.nn_tau
58+
A['nn'] = S.results.nn_static
59+
A['densities'] = S.results.densities
60+
61+
h5diff("Jperp.out.h5", "Jperp.ref.h5", precision=1e-9)

test/python/Jperp.ref.h5

98.9 KB
Binary file not shown.

test/python/anderson.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Single orbital with static interaction at half-filling.
2+
from triqs.gf import *
3+
import triqs.utility.mpi as mpi
4+
from triqs.gf.descriptors import Function
5+
from triqs.operators import n
6+
from triqs.gf import iOmega_n
7+
import h5
8+
from triqs.utility.h5diff import h5diff
9+
from triqs_ctseg import SolverCore as Solver
10+
11+
# Numerical values
12+
beta = 10
13+
U = 4.0
14+
mu = U/2
15+
eps = 0.2
16+
n_tau = 2051
17+
n_tau_bosonic = 2001
18+
19+
# Solver construction parameters
20+
gf_struct = [('down', 1), ('up', 1)]
21+
constr_params = {
22+
"gf_struct": gf_struct,
23+
"beta": beta,
24+
"n_tau": n_tau,
25+
"n_tau_bosonic": n_tau_bosonic
26+
}
27+
28+
# Construct solver
29+
S = Solver(**constr_params)
30+
31+
# Hybridization Delta(tau)
32+
iw_mesh = MeshImFreq(beta, 'Fermion', n_tau//2)
33+
delta_iw = GfImFreq(indices = [0], mesh = iw_mesh)
34+
delta_iw << inverse(iOmega_n - eps)
35+
S.Delta_tau["up"] << Fourier(delta_iw)
36+
S.Delta_tau["down"] << Fourier(delta_iw)
37+
38+
# Solve parameters
39+
solve_params = {
40+
"h_int": U*n("up", 0)*n("down", 0),
41+
"h_loc0": -mu * (n("up", 0) + n("down", 0)),
42+
"length_cycle": 50,
43+
"n_warmup_cycles": 1000,
44+
"n_cycles": 10000,
45+
"measure_F_tau": True,
46+
"measure_nn_tau": True,
47+
"measure_nn_static": True
48+
}
49+
50+
# Solve
51+
S.solve(**solve_params)
52+
53+
# Save and compare to reference
54+
if mpi.is_master_node():
55+
with h5.HDFArchive("anderson.out.h5", 'w') as A:
56+
A['G_tau'] = S.results.G_tau
57+
A['F_tau'] = S.results.F_tau
58+
A['nn_tau'] = S.results.nn_tau
59+
A['nn'] = S.results.nn_static
60+
A['densities'] = S.results.densities
61+
62+
h5diff("anderson.out.h5", "anderson.ref.h5", precision=1e-9)

test/python/anderson.ref.h5

180 KB
Binary file not shown.

0 commit comments

Comments
 (0)