Skip to content

Commit

Permalink
Large rewrite of Bond and BondList classes, introduced coupling class…
Browse files Browse the repository at this point in the history
…, dimension check for Lapack 32bit
  • Loading branch information
Alexander Wietek committed Jul 15, 2024
1 parent 1f6fec8 commit dd8157d
Show file tree
Hide file tree
Showing 84 changed files with 1,787 additions and 1,417 deletions.
1 change: 1 addition & 0 deletions cmake/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ set(XDIAG_SOURCES
symmetries/group_action/group_action_sublattice.cpp
symmetries/group_action/sublattice_stability.cpp

operators/coupling.cpp
operators/bond.cpp
operators/bondlist.cpp
operators/compiler.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ HB J 2 5
HB J 6 1
HB J 3 4
HB J 7 0
GENERICKITAEVX K 2 0
GENERICKITAEVX K 6 4
GENERICKITAEVX K 3 1
GENERICKITAEVX K 7 5
GENERICKITAEVY K 0 7
GENERICKITAEVY K 4 3
GENERICKITAEVY K 1 6
GENERICKITAEVY K 5 2
GENERICKITAEVZ K 0 3
GENERICKITAEVZ K 4 7
GENERICKITAEVZ K 1 2
GENERICKITAEVZ K 5 6
GENERICGAMMAX G 2 0
GENERICGAMMAX G 6 4
GENERICGAMMAX G 3 1
GENERICGAMMAX G 7 5
GENERICGAMMAY G 0 7
GENERICGAMMAY G 4 3
GENERICGAMMAY G 1 6
GENERICGAMMAY G 5 2
GENERICGAMMAZ G 0 3
GENERICGAMMAZ G 4 7
GENERICGAMMAZ G 1 2
GENERICGAMMAZ G 5 6
GENERICKITAEVX KX 2 0
GENERICKITAEVX KX 6 4
GENERICKITAEVX KX 3 1
GENERICKITAEVX KX 7 5
GENERICKITAEVY KY 0 7
GENERICKITAEVY KY 4 3
GENERICKITAEVY KY 1 6
GENERICKITAEVY KY 5 2
GENERICKITAEVZ KZ 0 3
GENERICKITAEVZ KZ 4 7
GENERICKITAEVZ KZ 1 2
GENERICKITAEVZ KZ 5 6
GENERICGAMMAX GX 2 0
GENERICGAMMAX GX 6 4
GENERICGAMMAX GX 3 1
GENERICGAMMAX GX 7 5
GENERICGAMMAY GY 0 7
GENERICGAMMAY GY 4 3
GENERICGAMMAY GY 1 6
GENERICGAMMAY GY 5 2
GENERICGAMMAZ GZ 0 3
GENERICGAMMAZ GZ 4 7
GENERICGAMMAZ GZ 1 2
GENERICGAMMAZ GZ 5 6
[SymmetryOps]=8
[S0] 0 1 2 3 4 5 6 7
[S1] 1 0 3 2 5 4 7 6
Expand Down
4 changes: 2 additions & 2 deletions tests/algorithms/arnoldi/test_arnoldi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ TEST_CASE("ritz_vecs_arnoldi", "[arnoldi]") {
BondList bonds;

for (int i = 0; i < n_sites; ++i) {
bonds << Bond("HB", "J1", {i, (i + 1) % n_sites});
bonds << Bond("HB", "J2", {i, (i + 2) % n_sites});
bonds += Bond("HB", "J1", {i, (i + 1) % n_sites});
bonds += Bond("HB", "J2", {i, (i + 2) % n_sites});
}
bonds["J1"] = 1;
bonds["J2"] = .5;
Expand Down
8 changes: 4 additions & 4 deletions tests/algorithms/lanczos/test_lanczos_pro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ TEST_CASE("lanczos_pro", "[lanczos]") {
std::string lfilename =
XDIAG_DIRECTORY "/misc/data/shastry.16.HB.J.Jd.fsl.toml";
auto lfile = FileToml(lfilename, 'r');
auto bonds = BondList(lfile["Interactions"]);
int n_sites = bonds.n_sites();
auto bonds = lfile["Interactions"].as<BondList>();
int n_sites = 16;
bonds["J"] = 0.63;
bonds["Jd"] = 1.00;
auto group = PermutationGroup(lfile["Symmetries"]);
Expand Down Expand Up @@ -195,8 +195,8 @@ TEST_CASE("lanczos_pro", "[lanczos]") {
std::string lfilename =
XDIAG_DIRECTORY "/misc/data/shastry.20.HB.J.Jd.fsl.toml";
auto lfile = FileToml(lfilename, 'r');
auto bonds = BondList(lfile["Interactions"]);
int n_sites = bonds.n_sites();
auto bonds = lfile["Interactions"].as<BondList>();
int n_sites = 20;
bonds["J"] = 0.63;
bonds["Jd"] = 1.00;
auto group = PermutationGroup(lfile["Symmetries"]);
Expand Down
18 changes: 9 additions & 9 deletions tests/algorithms/time_evolution/test_time_evolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEST_CASE("analytic_case_free_particle_1D", "[time_evolution]") try {
auto block = Electron(n_sites, nup, ndn);
BondList bonds;
for (int i = 0; i < n_sites; i++) {
bonds << Bond("HOP", "t", {i, (i + 1) % n_sites});
bonds += Bond("HOP", "t", {i, (i + 1) % n_sites});
}
bonds["t"] = t;
bonds["U"] = 1;
Expand Down Expand Up @@ -141,14 +141,14 @@ TEST_CASE("analytic_case_free_particle_2D", "[time_evolution]") try {
// nearest neighbour hops
int s_up_hop = L * ((i + 1) % L) + j;
int s_dn_hop = L * i + (j + 1) % L;
bonds << Bond("HOP", "t", {s, s_up_hop});
bonds << Bond("HOP", "t", {s, s_dn_hop});
bonds += Bond("HOP", "t", {s, s_up_hop});
bonds += Bond("HOP", "t", {s, s_dn_hop});

// next nearest neighbour hops
int s_across_up = L * ((i + 1) % L) + (j + 1) % L;
int s_across_dn = L * ((L + (i - 1) % L) % L) + (j + 1) % L;
bonds << Bond("HOP", "t1", {s, s_across_up});
bonds << Bond("HOP", "t1", {s, s_across_dn});
bonds += Bond("HOP", "t1", {s, s_across_up});
bonds += Bond("HOP", "t1", {s, s_across_dn});
}
}
bonds["t"] = t;
Expand Down Expand Up @@ -206,10 +206,10 @@ TEST_CASE("tj_complex_timeevo", "[time_evolution]") try {
int site = y * L + x;
int right = y * L + nx;
int top = ny * L + x;
bonds << Bond("HOP", "T", {site, right});
bonds << Bond("TJISING", "J", {site, right});
bonds << Bond("HOP", "T", {site, top});
bonds << Bond("TJISING", "J", {site, top});
bonds += Bond("HOP", "T", {site, right});
bonds += Bond("TJISING", "J", {site, right});
bonds += Bond("HOP", "T", {site, top});
bonds += Bond("TJISING", "J", {site, top});
}
}
bonds["T"] = (std::complex<double>)(1.0 + 0.2i);
Expand Down
60 changes: 31 additions & 29 deletions tests/blocks/electron/test_electron_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TEST_CASE("electron_matrix", "[electron]") {
auto block = Electron(n_sites, n_up, n_dn);

for (int i = 0; i < n_sites; ++i)
bondlist << Bond("HOP", "T", {i, (i + 1) % n_sites});
bondlist += Bond("HOP", "T", {i, (i + 1) % n_sites});
bondlist["T"] = 1.0;
bondlist["U"] = 5.0;
auto H1 = matrix(bondlist, block, block);
Expand Down Expand Up @@ -121,22 +121,24 @@ TEST_CASE("electron_matrix", "[electron]") {

//////////////////////////////////
// Test two site exact solution
bondlist.clear();
bondlist << Bond("HOP", "T", {0, 1});
auto block2 = Electron(2, 1, 1);
for (int i = 0; i < 20; ++i) {
double U = 1.234 * i;
Log("electron_matrix: two-site exact solution test, U={}", U);
bondlist["T"] = 1.0;
bondlist["U"] = U;
double e0_exact = 0.5 * (U - sqrt(U * U + 16));
auto H = matrix(bondlist, block2, block2);
REQUIRE(H.is_hermitian(1e-8));
arma::Col<double> eigs;
arma::eig_sym(eigs, H);
double e0 = eigs(0);
// printf("e0: %f, e0_exact: %f\n", e0, e0_exact);
REQUIRE(close(e0_exact, e0));
{
BondList bondlist;
bondlist += Bond("HOP", "T", {0, 1});
auto block2 = Electron(2, 1, 1);
for (int i = 0; i < 20; ++i) {
double U = 1.234 * i;
Log("electron_matrix: two-site exact solution test, U={}", U);
bondlist["T"] = 1.0;
bondlist["U"] = U;
double e0_exact = 0.5 * (U - sqrt(U * U + 16));
auto H = matrix(bondlist, block2, block2);
REQUIRE(H.is_hermitian(1e-8));
arma::Col<double> eigs;
arma::eig_sym(eigs, H);
double e0 = eigs(0);
// printf("e0: %f, e0_exact: %f\n", e0, e0_exact);
REQUIRE(close(e0_exact, e0));
}
}

///////////////////////////////////////////////////
Expand All @@ -150,10 +152,10 @@ TEST_CASE("electron_matrix", "[electron]") {
// Create single particle matrix
arma::Mat<double> Hs(n_sites, n_sites, arma::fill::zeros);
for (auto bond : bondlist) {
assert(bond.size() == 2);
int s1 = bond.site(0);
int s2 = bond.site(1);
auto name = bond.coupling_name();
REQUIRE(bond.size() == 2);
int s1 = bond[0];
int s2 = bond[1];
auto name = bond.coupling().as<std::string>();
Hs(s1, s2) = -bondlist[name].as<double>();
Hs(s2, s1) = -bondlist[name].as<double>();
}
Expand Down Expand Up @@ -196,11 +198,11 @@ TEST_CASE("electron_matrix", "[electron]") {

// Create single particle matrix for upspins
arma::cx_mat Hs_up(n_sites, n_sites, arma::fill::zeros);
for (auto bond : bondlist.bonds_of_type("HOPUP")) {
for (auto bond : bonds_of_type("HOPUP", bondlist)) {
assert(bond.size() == 2);
int s1 = bond.site(0);
int s2 = bond.site(1);
auto name = bond.coupling_name();
int s1 = bond[0];
int s2 = bond[1];
auto name = bond.coupling().as<std::string>();
Hs_up(s1, s2) = -bondlist[name].as<complex>();
Hs_up(s2, s1) = -conj(bondlist[name].as<complex>());
}
Expand All @@ -209,11 +211,11 @@ TEST_CASE("electron_matrix", "[electron]") {

// Create single particle matrix for dnspins
arma::cx_mat Hs_dn(n_sites, n_sites, arma::fill::zeros);
for (auto bond : bondlist.bonds_of_type("HOPDN")) {
for (auto bond : bonds_of_type("HOPDN", bondlist)) {
assert(bond.size() == 2);
int s1 = bond.site(0);
int s2 = bond.site(1);
auto name = bond.coupling_name();
int s1 = bond[0];
int s2 = bond[1];
auto name = bond.coupling().as<std::string>();
Hs_dn(s1, s2) = -bondlist[name].as<complex>();
Hs_dn(s2, s1) = -conj(bondlist[name].as<complex>());
}
Expand Down
72 changes: 36 additions & 36 deletions tests/blocks/electron/test_electron_raiselower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ TEST_CASE("electron_raise_lower", "[electron]") {

for (auto op_i_str : op_strs) {
for (auto op_j_str : op_strs) {
auto op_i = Bond(op_i_str, i);
auto op_j = Bond(op_j_str, j);
auto op_i = Bond(op_i_str, 1.0, i);
auto op_j = Bond(op_j_str, 1.0, j);
auto op_i_m = matrixC(op_i, block);
auto op_j_m = matrixC(op_j, block);
cx_mat anti_comm = op_i_m * op_j_m + op_j_m * op_i_m;
Expand Down Expand Up @@ -61,20 +61,20 @@ TEST_CASE("electron_raise_lower", "[electron]") {

// Check whether NUMBERUP agrees
{
auto bond = Bond("NUMBERUP", i);
auto bond = Bond("NUMBERUP", 1.0, i);
auto m = matrix(bond, block);
auto mi1 = matrix(Bond("CDAGUP", i), block);
auto mi2 = matrix(Bond("CUP", i), block);
auto mi1 = matrix(Bond("CDAGUP", 1.0, i), block);
auto mi2 = matrix(Bond("CUP", 1.0, i), block);
auto mm = mi1 * mi2;
REQUIRE(norm(mm - m) < 1e-12);
}

// Check whether NUMBERDN agrees
{
auto bond = Bond("NUMBERDN", i);
auto bond = Bond("NUMBERDN", 1.0, i);
auto m = matrix(bond, block);
auto mi1 = matrix(Bond("CDAGDN", i), block);
auto mi2 = matrix(Bond("CDN", i), block);
auto mi1 = matrix(Bond("CDAGDN", 1.0, i), block);
auto mi2 = matrix(Bond("CDN", 1.0, i), block);
auto mm = mi1 * mi2;
REQUIRE(norm(mm - m) < 1e-12);
}
Expand All @@ -84,43 +84,43 @@ TEST_CASE("electron_raise_lower", "[electron]") {

// Check whether HOPUP agrees
{
auto bond = Bond("HOPUP", {i, j});
auto bond = Bond("HOPUP", 1.0, {i, j});
auto m = matrix(bond, block);
auto m1 = matrix(Bond("CDAGUP", i), block);
auto m2 = matrix(Bond("CUP", j), block);
auto m3 = matrix(Bond("CDAGUP", j), block);
auto m4 = matrix(Bond("CUP", i), block);
auto m1 = matrix(Bond("CDAGUP", 1.0, i), block);
auto m2 = matrix(Bond("CUP", 1.0, j), block);
auto m3 = matrix(Bond("CDAGUP", 1.0, j), block);
auto m4 = matrix(Bond("CUP", 1.0, i), block);
auto mm = -m1 * m2 - m3 * m4;
REQUIRE(norm(mm - m) < 1e-12);
}

// Check whether HOPDN agrees
{
auto bond = Bond("HOPDN", {i, j});
auto bond = Bond("HOPDN", 1.0, {i, j});
auto m = matrix(bond, block);
auto m1 = matrix(Bond("CDAGDN", i), block);
auto m2 = matrix(Bond("CDN", j), block);
auto m3 = matrix(Bond("CDAGDN", j), block);
auto m4 = matrix(Bond("CDN", i), block);
auto m1 = matrix(Bond("CDAGDN", 1.0, i), block);
auto m2 = matrix(Bond("CDN", 1.0, j), block);
auto m3 = matrix(Bond("CDAGDN", 1.0, j), block);
auto m4 = matrix(Bond("CDN", 1.0, i), block);
auto mm = -m1 * m2 - m3 * m4;
REQUIRE(norm(mm - m) < 1e-12);
}

// Check whether ISING agrees
{
auto bond = Bond("ISING", {i, j});
auto bond = Bond("ISING", 1.0, {i, j});
auto m = matrix(bond, block);

auto mi1 = matrix(Bond("CDAGUP", i), block);
auto mi2 = matrix(Bond("CUP", i), block);
auto mi3 = matrix(Bond("CDAGDN", i), block);
auto mi4 = matrix(Bond("CDN", i), block);
auto mi1 = matrix(Bond("CDAGUP", 1.0, i), block);
auto mi2 = matrix(Bond("CUP", 1.0, i), block);
auto mi3 = matrix(Bond("CDAGDN", 1.0, i), block);
auto mi4 = matrix(Bond("CDN", 1.0, i), block);
auto szi = 0.5 * mi1 * mi2 - 0.5 * mi3 * mi4;

auto mj1 = matrix(Bond("CDAGUP", j), block);
auto mj2 = matrix(Bond("CUP", j), block);
auto mj3 = matrix(Bond("CDAGDN", j), block);
auto mj4 = matrix(Bond("CDN", j), block);
auto mj1 = matrix(Bond("CDAGUP", 1.0, j), block);
auto mj2 = matrix(Bond("CUP", 1.0, j), block);
auto mj3 = matrix(Bond("CDAGDN", 1.0, j), block);
auto mj4 = matrix(Bond("CDN", 1.0, j), block);
auto szj = 0.5 * mj1 * mj2 - 0.5 * mj3 * mj4;

auto mm = szi * szj;
Expand All @@ -129,20 +129,20 @@ TEST_CASE("electron_raise_lower", "[electron]") {

// Check whether EXCHANGE agrees
{
auto bond = Bond("EXCHANGE", {i, j});
auto bond = Bond("EXCHANGE", 1.0, {i, j});
auto m = matrix(bond, block);

auto mi1 = matrix(Bond("CDAGUP", i), block);
auto mi2 = matrix(Bond("CUP", i), block);
auto mi3 = matrix(Bond("CDAGDN", i), block);
auto mi4 = matrix(Bond("CDN", i), block);
auto mi1 = matrix(Bond("CDAGUP", 1.0, i), block);
auto mi2 = matrix(Bond("CUP", 1.0, i), block);
auto mi3 = matrix(Bond("CDAGDN", 1.0, i), block);
auto mi4 = matrix(Bond("CDN", 1.0, i), block);
auto spi = mi1 * mi4;
auto smi = mi3 * mi2;

auto mj1 = matrix(Bond("CDAGUP", j), block);
auto mj2 = matrix(Bond("CUP", j), block);
auto mj3 = matrix(Bond("CDAGDN", j), block);
auto mj4 = matrix(Bond("CDN", j), block);
auto mj1 = matrix(Bond("CDAGUP", 1.0, j), block);
auto mj2 = matrix(Bond("CUP", 1.0, j), block);
auto mj3 = matrix(Bond("CDAGDN", 1.0, j), block);
auto mj4 = matrix(Bond("CDN", 1.0, j), block);
auto spj = mj1 * mj4;
auto smj = mj3 * mj2;

Expand Down
Loading

0 comments on commit dd8157d

Please sign in to comment.