Skip to content

Commit

Permalink
Some low-level cleanup, set up tests for SpinhalfDistributed
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Wietek committed Jul 19, 2024
1 parent 8bb7ee8 commit 04c8f79
Show file tree
Hide file tree
Showing 150 changed files with 1,189 additions and 1,623 deletions.
27 changes: 18 additions & 9 deletions cmake/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,19 @@ set(XDIAG_SOURCES
combinatorics/subsets_indexing.cpp
combinatorics/lin_table.cpp
combinatorics/fermi_table.cpp

basis/basis.cpp

basis/spinhalf/basis_spinhalf.cpp
basis/spinhalf/basis_sz.cpp
basis/spinhalf/basis_no_sz.cpp
basis/spinhalf/basis_symmetric_sz.cpp
basis/spinhalf/basis_symmetric_no_sz.cpp
basis/spinhalf/basis_sublattice.cpp

basis/tj/basis_tj.cpp
basis/tj/basis_np.cpp
basis/tj/basis_symmetric_np.cpp

basis/electron/basis_electron.cpp
basis/electron/basis_np.cpp
basis/electron/basis_no_np.cpp
basis/electron/basis_symmetric_np.cpp
Expand All @@ -54,18 +55,18 @@ set(XDIAG_SOURCES
blocks/blocks.cpp

blocks/spinhalf/spinhalf.cpp
blocks/spinhalf/spinhalf_matrix.cpp
blocks/spinhalf/spinhalf_apply.cpp
blocks/spinhalf/matrix.cpp
blocks/spinhalf/apply.cpp
blocks/spinhalf/compile.cpp

blocks/electron/electron.cpp
blocks/electron/electron_matrix.cpp
blocks/electron/electron_apply.cpp
blocks/electron/matrix.cpp
blocks/electron/apply.cpp
blocks/electron/compile.cpp

blocks/tj/tj.cpp
blocks/tj/tj_matrix.cpp
blocks/tj/tj_apply.cpp
blocks/tj/matrix.cpp
blocks/tj/apply.cpp
blocks/tj/compile.cpp

symmetries/qn.cpp
Expand Down Expand Up @@ -120,10 +121,18 @@ set(XDIAG_DISTRIBUTED_SOURCES
parallel/mpi/timing_mpi.cpp
parallel/mpi/buffer.cpp

basis/spinhalf_distributed/basis_spinhalf_distributed.cpp
basis/spinhalf_distributed/basis_sz.cpp
basis/spinhalf_distributed/apply.cpp

basis/tj_distributed/basis_tj_distributed.cpp
basis/tj_distributed/basis_np.cpp

blocks/spinhalf_distributed/spinhalf_distributed.cpp
blocks/spinhalf_distributed/apply.cpp

blocks/tj_distributed/tj_distributed.cpp
blocks/tj_distributed/tj_distributed_apply.cpp
blocks/tj_distributed/apply.cpp
)

set(XDIAG_JULIA_SOURCES
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ set(XDIAG_TESTCASES_SOURCES

set(XDIAG_TEST_DISTRIBUTED_SOURCES
parallel/mpi/test_cdot_distributed.cpp

basis/spinhalf_distributed/test_basis_sz.cpp
basis/tj_distributed/test_basis_np.cpp

blocks/spinhalf_distributed/test_spinhalf_distributed.cpp
blocks/spinhalf_distributed/test_spinhalf_distributed_apply.cpp
blocks/tj_distributed/test_tj_distributed_apply.cpp

algorithms/time_evolution/test_time_evolution_distributed.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion tests/algorithms/lanczos/test_eigs_lanczos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <xdiag/algebra/apply.hpp>
#include <xdiag/algorithms/lanczos/eigs_lanczos.hpp>

#include <xdiag/blocks/electron/electron_matrix.hpp>
#include <xdiag/blocks/electron/matrix.hpp>
#include <xdiag/utils/close.hpp>
#include <xdiag/utils/print_macro.hpp>

Expand Down
2 changes: 1 addition & 1 deletion tests/algorithms/lanczos/test_eigvals_lanczos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "../../blocks/electron/testcases_electron.hpp"

#include <xdiag/algorithms/lanczos/eigvals_lanczos.hpp>
#include <xdiag/blocks/electron/electron_matrix.hpp>
#include <xdiag/blocks/electron/matrix.hpp>
#include <xdiag/utils/close.hpp>

using namespace xdiag;
Expand Down
4 changes: 2 additions & 2 deletions tests/algorithms/lanczos/test_lanczos_pro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TEST_CASE("lanczos_pro", "[lanczos]") {

mat tmat = res.tmat;
mat A2 = mat(V * tmat * V.t());
REQUIRE(norm(A - A2) < N * ortho_level);
REQUIRE(norm(A - A2) < 2 * N * ortho_level);
}

{
Expand Down Expand Up @@ -119,7 +119,7 @@ TEST_CASE("lanczos_pro", "[lanczos]") {

cx_mat V = res.V;
double total_orthogonality = norm(V.t() * V - eye(N, N));
REQUIRE(total_orthogonality < N * ortho_level); // correct ortho levels
REQUIRE(total_orthogonality < 2 * N * ortho_level); // correct ortho levels

vec eigs;
eig_sym(eigs, A);
Expand Down
51 changes: 0 additions & 51 deletions tests/basis/electron/test_electron_symmetric_indexing.cpp

This file was deleted.

4 changes: 1 addition & 3 deletions tests/basis/spinhalf/test_spinhalf_basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ template <class bit_t> void test_basis_symmetric() {

TEST_CASE("spinhalf_basis", "[basis]") {
Log("Test SpinhalfBasisSublattice");
Log("uint16_t");
test_basis_symmetric<uint16_t>();
Log("uint32_t");
Log("uint32_t");
test_basis_symmetric<uint32_t>();
Log("uint64_t");
test_basis_symmetric<uint64_t>();
Expand Down
2 changes: 0 additions & 2 deletions tests/basis/spinhalf/test_spinhalf_basis_sublattice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,6 @@ template <class bit_t> void test_spinhalf_basis_sublattice() {

TEST_CASE("basis_spinhalf_sublattice", "[symmetries]") {
Log("Test basis_spinhalf_sublattice");
Log("uint16_t");
test_spinhalf_basis_sublattice<uint16_t>();
Log("uint32_t");
test_spinhalf_basis_sublattice<uint32_t>();
Log("uint64_t");
Expand Down
15 changes: 6 additions & 9 deletions tests/basis/spinhalf_distributed/test_basis_sz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,39 @@ template <typename bit_t> void test_spinhalf_distributed_basis_sz() {

// pre / post order
bit_t spins_before = 0;
int64_t size_local = 0;
int64_t idx = 0;
// Log("N: {} nup: {}", n_sites, n_up);
for (bit_t prefix : basis.prefixes()) {
bit_t prefix_shifted = prefix << basis.n_postfix_bits();
for (bit_t postfix : basis.postfix_states(prefix)) {
bit_t spins = prefix_shifted | postfix;
REQUIRE(bits::popcnt(spins) == n_up);
// std::cout << BSTR(spins) << "\n";
REQUIRE(bits::popcnt(spins) == n_up);
// std::cout << BSTR(spins) << "\n";
if (idx > 0) {
REQUIRE(spins > spins_before);
}
spins_before = spins;
++idx;
}
}
REQUIRE(idx == basis.size_local());
Log("{} {} sl {}", n_sites, n_up, idx);
std::cout << idx << "\n";
REQUIRE(idx == basis.size());

// post / pre order
spins_before = 0;
size_local = 0;
idx = 0;
for (bit_t postfix : basis.postfixes()) {
bit_t postfix_shifted = postfix << basis.n_prefix_bits();
for (bit_t prefix : basis.prefix_states(postfix)) {
bit_t spins = postfix_shifted | prefix;
REQUIRE(bits::popcnt(spins) == n_up);
REQUIRE(bits::popcnt(spins) == n_up);
if (idx > 0) {
REQUIRE(spins > spins_before);
}
spins_before = spins;
++idx;
}
}
REQUIRE(idx == basis.size_local_transpose());
REQUIRE(idx == basis.size_transpose());
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions tests/basis/tj_distributed/test_basis_np.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,16 @@ template <typename bit_t> void test_tj_distributed_basis_np() {
TEST_CASE("tj_distributed_basis_np", "[tj_distributed]") {
using namespace xdiag;

Log("tj_distributed_basis_np transpose test (uint16_t, double)");
test_tj_distributed_basis_np_transpose<uint16_t, double>();
Log("tj_distributed_basis_np transpose test (uint32_t, double)");
test_tj_distributed_basis_np_transpose<uint32_t, double>();
Log("tj_distributed_basis_np transpose test (uint64_t, double)");
test_tj_distributed_basis_np_transpose<uint64_t, double>();

Log("tj_distributed_basis_np transpose test (uint16_t, complex)");
test_tj_distributed_basis_np_transpose<uint16_t, complex>();
Log("tj_distributed_basis_np transpose test (uint32_t, complex)");
test_tj_distributed_basis_np_transpose<uint32_t, complex>();
Log("tj_distributed_basis_np transpose test (uint64_t, complex)");
test_tj_distributed_basis_np_transpose<uint64_t, complex>();

Log("tj_distributed_basis_np test (uint16_t)");
test_tj_distributed_basis_np<uint16_t>();
Log("tj_distributed_basis_np test (uint32_t)");
test_tj_distributed_basis_np<uint32_t>();
Log("tj_distributed_basis_np test (uint64_t)");
Expand Down
2 changes: 1 addition & 1 deletion tests/blocks/electron/test_electron_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "../tj/testcases_tj.hpp"
#include "testcases_electron.hpp"
#include <xdiag/blocks/electron/electron_matrix.hpp>
#include <xdiag/blocks/electron/matrix.hpp>
#include <xdiag/algebra/algebra.hpp>
#include <xdiag/algebra/apply.hpp>
#include <xdiag/algorithms/sparse_diag.hpp>
Expand Down
2 changes: 1 addition & 1 deletion tests/blocks/electron/test_electron_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "testcases_electron.hpp"

#include <xdiag/algebra/matrix.hpp>
#include <xdiag/blocks/electron/electron_matrix.hpp>
#include <xdiag/blocks/electron/matrix.hpp>
#include <xdiag/utils/close.hpp>

using namespace xdiag;
Expand Down
4 changes: 2 additions & 2 deletions tests/blocks/electron/test_electron_raiselower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <xdiag/algebra/algebra.hpp>
#include <xdiag/algebra/matrix.hpp>
#include <xdiag/algorithms/sparse_diag.hpp>
#include <xdiag/blocks/electron/electron_apply.hpp>
#include <xdiag/blocks/electron/electron_matrix.hpp>
#include <xdiag/blocks/electron/apply.hpp>
#include <xdiag/blocks/electron/matrix.hpp>
#include <xdiag/utils/close.hpp>

TEST_CASE("electron_raise_lower", "[electron]") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <xdiag/algebra/algebra.hpp>
#include <xdiag/algebra/matrix.hpp>
#include <xdiag/algorithms/sparse_diag.hpp>
#include <xdiag/blocks/electron/electron_apply.hpp>
#include <xdiag/blocks/electron/electron_matrix.hpp>
#include <xdiag/blocks/electron/apply.hpp>
#include <xdiag/blocks/electron/matrix.hpp>
#include <xdiag/utils/close.hpp>

using namespace xdiag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <iostream>

#include "../electron/testcases_electron.hpp"
#include <xdiag/blocks/electron/electron_matrix.hpp>
#include <xdiag/blocks/electron/electron_apply.hpp>
#include <xdiag/blocks/electron/matrix.hpp>
#include <xdiag/blocks/electron/apply.hpp>
#include <xdiag/algebra/algebra.hpp>
#include <xdiag/algebra/matrix.hpp>
#include <xdiag/algorithms/sparse_diag.hpp>
Expand Down
3 changes: 2 additions & 1 deletion tests/blocks/spinhalf/test_spinhalf_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#include <xdiag/algebra/algebra.hpp>
#include <xdiag/algebra/matrix.hpp>
#include <xdiag/algorithms/sparse_diag.hpp>
#include <xdiag/blocks/spinhalf/spinhalf_apply.hpp>
#include <xdiag/blocks/spinhalf/apply.hpp>
#include <xdiag/blocks/spinhalf/matrix.hpp>
#include <xdiag/utils/close.hpp>
#include <xdiag/utils/print_macro.hpp>

Expand Down
3 changes: 2 additions & 1 deletion tests/blocks/spinhalf/test_spinhalf_matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#include "testcases_spinhalf.hpp"
#include <iostream>
#include <xdiag/blocks/spinhalf/spinhalf_matrix.hpp>
#include <xdiag/blocks/spinhalf/matrix.hpp>
#include <xdiag/blocks/tj/matrix.hpp>
#include <xdiag/algebra/matrix.hpp>
#include <xdiag/utils/close.hpp>
#include <xdiag/utils/print_macro.hpp>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include <mpi.h>
#include "../../catch.hpp"
#include <mpi.h>

#include <xdiag/all.hpp>

using namespace xdiag;

template <class bit_t>
void test_spinhalf_mpi(int n_sites){
void test_spinhalf_distributed(int n_sites) {
for (int nup = 0; nup <= n_sites; ++nup) {
auto block = Spinhalf<bit_t>(n_sites, nup);
auto block_mpi = SpinhalfMPI<bit_t>(n_sites, nup);
auto block = Spinhalf(n_sites, nup);
auto block_mpi = SpinhalfDistributed(n_sites, nup);

auto mysiz = block_mpi.size();
int64_t mysize = 0;
Expand All @@ -22,15 +21,10 @@ void test_spinhalf_mpi(int n_sites){
}
}

TEST_CASE("spinhalf_distributed", "[spinhalf_distributed]") {

TEST_CASE("spinhalf_mpi", "[spinhalf_mpi]") {

LogMPI.out("SpinhalfMPI test");

for (int N = 2; N <= 6; ++N) {
test_spinhalf_mpi<uint16_t>(N);
test_spinhalf_mpi<uint32_t>(N);
test_spinhalf_mpi<uint64_t>(N);
Log("SpinhalfDistributed test");
for (int N = 0; N <= 6; ++N) {
test_spinhalf_distributed(N);
}

}
Loading

0 comments on commit 04c8f79

Please sign in to comment.