From c9cb8dd499c2b2648a78e63f2a0810451a69f8fd Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 12 Nov 2021 16:41:14 +0100 Subject: Some tweaking of the Stokes finder, how the lines are recorded, and fewer executables. --- collectStokesData.hpp | 37 ++++++++++++++++++------------- mixedStokes.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++ mixedStokesFromMinima.cpp | 54 ---------------------------------------------- mixedStokesFromSaddles.cpp | 54 ---------------------------------------------- pureStokes.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++ pureStokesFromMinima.cpp | 54 ---------------------------------------------- pureStokesFromSaddles.cpp | 54 ---------------------------------------------- stokes.hpp | 8 +++---- 8 files changed, 130 insertions(+), 235 deletions(-) create mode 100644 mixedStokes.cpp delete mode 100644 mixedStokesFromMinima.cpp delete mode 100644 mixedStokesFromSaddles.cpp create mode 100644 pureStokes.cpp delete mode 100644 pureStokesFromMinima.cpp delete mode 100644 pureStokesFromSaddles.cpp diff --git a/collectStokesData.hpp b/collectStokesData.hpp index 433f5ad..b32ccf0 100644 --- a/collectStokesData.hpp +++ b/collectStokesData.hpp @@ -5,10 +5,11 @@ using Complex = std::complex; template -void collectStokesData(std::ofstream& file, unsigned N, Generator& r, double ε, double δz, bool minimum, T... μs) { +void collectStokesData(std::string tag, unsigned N, Generator& r, double ε, double δz, bool minimum, T... μs) { + std::ofstream file("stokes_info_" + tag + ".dat"); unsigned nGs = 8; - unsigned nTs = 20; - Real newSaddleThres = 1e-3; + unsigned nTs = 32; + Real newSaddleThres = 1e-4; pSpinModel ReM(N, r, μs...); @@ -57,35 +58,41 @@ void collectStokesData(std::ofstream& file, unsigned N, Generator& r, double ε, file.precision(15); file << N << std::endl; - ((file << ps), ...) << std::endl;; - ((file << μs), ...) << std::endl;; + ((file << ps << " "), ...) << std::endl;; + ((file << μs << " "), ...) << std::endl;; - std::apply([&file](const Tensor&... Js) -> void { - ((file << Js << std::endl), ...); + std::ofstream tensorFile("stokes_tensor_" + tag + ".dat", std::ios::out | std::ios::binary | std::ios::trunc); + std::apply([&tensorFile](const Tensor&... Js) -> void { + std::make_tuple(tensorFile.write(Js.data(), Js.size() * sizeof(Complex))...); } , ReM.Js); file << xMin.transpose() << std::endl; file << Hx << std::endl; file << eigenS.eigenvalues().real().transpose() << std::endl; file << zSaddle.transpose() << std::endl; - file << Hz << std::endl; + file << Hz << " " << zSaddle.squaredNorm() << std::endl; file << eigenSz.eigenvalues().transpose() << std::endl; - file << φ << std::endl; + file << φ << " " << (xMin - zSaddle).norm() << std::endl; Cord c(M, zMin, zSaddle, nGs); c.relaxNewton(nTs, 1, 1e-10, 1e3); - Complex constraintError = 0; + Real reConstraintError = 0; + Real imConstraintError = 0; Real imEnergyError = 0; - for (unsigned i = 0; i < 100 * nTs; i++) { - Vector zi = c.f((i + 1.0) / (100.0 * nTs + 1.0)); + unsigned nTest = nTs * 10; + + for (unsigned i = 0; i < nTest; i++) { + Vector zi = c.f((i + 1.0) / (nTest + 1.0)); imEnergyError += pow(std::imag(M.getHamiltonian(zi) - M.getHamiltonian(zMin)), 2); - constraintError += pow(((Complex)(zi.transpose() * zi) - (Complex)N), 2); + Complex constraintError = (Complex)(zi.transpose() * zi) - (Complex)N; + reConstraintError += pow(real(constraintError), 2); + imConstraintError += pow(imag(constraintError), 2); } - file << nGs << " " << nTs << std::endl;; - file << c.totalCost(100 * nTs) / (100 * nTs) << " " << sqrt(imEnergyError) / (100 * nTs) << " " << sqrt(constraintError) / (100.0 * nTs) << std::endl; + file << nGs << " " << nTest << std::endl;; + file << c.totalCost(nTest) / (nTest) << " " << sqrt(imEnergyError / (Real)(nTest)) << " " << sqrt(reConstraintError / (Real)(nTest)) << " " << sqrt(imConstraintError / (Real)(nTest)) << std::endl; for (const Vector& gi : c.gs) { file << gi.transpose() << std::endl; } diff --git a/mixedStokes.cpp b/mixedStokes.cpp new file mode 100644 index 0000000..09a75b2 --- /dev/null +++ b/mixedStokes.cpp @@ -0,0 +1,52 @@ +#include +#include + +#include "collectStokesData.hpp" + +#include "pcg-cpp/include/pcg_random.hpp" +#include "randutils/randutils.hpp" + +using Rng = randutils::random_generator; + +int main(int argc, char* argv[]) { + // model parameters + unsigned N = 10; // number of spins + // simulation parameters + Real ε = 1e-15; + Real δ = 1; + unsigned n = 10; + bool useMinima = false; + + int opt; + + while ((opt = getopt(argc, argv, "N:e:d:n:m")) != -1) { + switch (opt) { + case 'N': + N = (unsigned)atof(optarg); + break; + case 'e': + ε = atof(optarg); + break; + case 'd': + δ = atof(optarg); + break; + case 'n': + n = atof(optarg); + break; + case 'm': + useMinima = true; + break; + default: + exit(1); + } + } + + Rng r; + + for (unsigned i = 0; i < n; i++) { + auto tag = std::chrono::high_resolution_clock::now(); + collectStokesData<2, 4>(std::to_string(tag.time_since_epoch().count()), N, r.engine(), ε, δ, useMinima, 1.0, 0.01); + } + + return 0; +} diff --git a/mixedStokesFromMinima.cpp b/mixedStokesFromMinima.cpp deleted file mode 100644 index f6d2cba..0000000 --- a/mixedStokesFromMinima.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -#include "collectStokesData.hpp" - -#include "pcg-cpp/include/pcg_random.hpp" -#include "randutils/randutils.hpp" -#include "unsupported/Eigen/CXX11/src/Tensor/TensorFFT.h" - -#define PSPIN_P 3 -const int p = PSPIN_P; // polynomial degree of Hamiltonian - -using Rng = randutils::random_generator; - -int main(int argc, char* argv[]) { - // model parameters - unsigned N = 10; // number of spins - // simulation parameters - Real ε = 1e-15; - Real δ = 1; - unsigned n = 10; - - int opt; - - while ((opt = getopt(argc, argv, "N:e:d:n:")) != -1) { - switch (opt) { - case 'N': - N = (unsigned)atof(optarg); - break; - case 'e': - ε = atof(optarg); - break; - case 'd': - δ = atof(optarg); - break; - case 'n': - n = atof(optarg); - break; - default: - exit(1); - } - } - - Rng r; - - for (unsigned i = 0; i < n; i++) { - auto tag = std::chrono::high_resolution_clock::now(); - std::ofstream output("stokes_" + std::to_string(tag.time_since_epoch().count()) + ".dat"); - collectStokesData<2, 4>(output, N, r.engine(), ε, δ, true, 1.0, 0.01); - } - - return 0; -} diff --git a/mixedStokesFromSaddles.cpp b/mixedStokesFromSaddles.cpp deleted file mode 100644 index 2373146..0000000 --- a/mixedStokesFromSaddles.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -#include "collectStokesData.hpp" - -#include "pcg-cpp/include/pcg_random.hpp" -#include "randutils/randutils.hpp" -#include "unsupported/Eigen/CXX11/src/Tensor/TensorFFT.h" - -#define PSPIN_P 3 -const int p = PSPIN_P; // polynomial degree of Hamiltonian - -using Rng = randutils::random_generator; - -int main(int argc, char* argv[]) { - // model parameters - unsigned N = 10; // number of spins - // simulation parameters - Real ε = 1e-15; - Real δ = 1; - unsigned n = 10; - - int opt; - - while ((opt = getopt(argc, argv, "N:e:d:n:")) != -1) { - switch (opt) { - case 'N': - N = (unsigned)atof(optarg); - break; - case 'e': - ε = atof(optarg); - break; - case 'd': - δ = atof(optarg); - break; - case 'n': - n = atof(optarg); - break; - default: - exit(1); - } - } - - Rng r; - - for (unsigned i = 0; i < n; i++) { - auto tag = std::chrono::high_resolution_clock::now(); - std::ofstream output("stokes_" + std::to_string(tag.time_since_epoch().count()) + ".dat"); - collectStokesData<2, 4>(output, N, r.engine(), ε, δ, false, 1.0, 0.01); - } - - return 0; -} diff --git a/pureStokes.cpp b/pureStokes.cpp new file mode 100644 index 0000000..a07dbbc --- /dev/null +++ b/pureStokes.cpp @@ -0,0 +1,52 @@ +#include +#include + +#include "collectStokesData.hpp" + +#include "pcg-cpp/include/pcg_random.hpp" +#include "randutils/randutils.hpp" + +using Rng = randutils::random_generator; + +int main(int argc, char* argv[]) { + // model parameters + unsigned N = 10; // number of spins + // simulation parameters + Real ε = 1e-15; + Real δ = 1; + unsigned n = 10; + bool useMinima = false; + + int opt; + + while ((opt = getopt(argc, argv, "N:e:d:n:m")) != -1) { + switch (opt) { + case 'N': + N = (unsigned)atof(optarg); + break; + case 'e': + ε = atof(optarg); + break; + case 'd': + δ = atof(optarg); + break; + case 'n': + n = atof(optarg); + break; + case 'm': + useMinima = true; + break; + default: + exit(1); + } + } + + Rng r; + + for (unsigned i = 0; i < n; i++) { + auto tag = std::chrono::high_resolution_clock::now(); + collectStokesData<3>(std::to_string(tag.time_since_epoch().count()), N, r.engine(), ε, δ, useMinima, 1.0); + } + + return 0; +} diff --git a/pureStokesFromMinima.cpp b/pureStokesFromMinima.cpp deleted file mode 100644 index 8f815cf..0000000 --- a/pureStokesFromMinima.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -#include "collectStokesData.hpp" - -#include "pcg-cpp/include/pcg_random.hpp" -#include "randutils/randutils.hpp" -#include "unsupported/Eigen/CXX11/src/Tensor/TensorFFT.h" - -#define PSPIN_P 3 -const int p = PSPIN_P; // polynomial degree of Hamiltonian - -using Rng = randutils::random_generator; - -int main(int argc, char* argv[]) { - // model parameters - unsigned N = 10; // number of spins - // simulation parameters - Real ε = 1e-15; - Real δ = 1; - unsigned n = 10; - - int opt; - - while ((opt = getopt(argc, argv, "N:e:d:n:")) != -1) { - switch (opt) { - case 'N': - N = (unsigned)atof(optarg); - break; - case 'e': - ε = atof(optarg); - break; - case 'd': - δ = atof(optarg); - break; - case 'n': - n = atof(optarg); - break; - default: - exit(1); - } - } - - Rng r; - - for (unsigned i = 0; i < n; i++) { - auto tag = std::chrono::high_resolution_clock::now(); - std::ofstream output("stokes_" + std::to_string(tag.time_since_epoch().count()) + ".dat"); - collectStokesData<3>(output, N, r.engine(), ε, δ, true, 1.0); - } - - return 0; -} diff --git a/pureStokesFromSaddles.cpp b/pureStokesFromSaddles.cpp deleted file mode 100644 index 6516a80..0000000 --- a/pureStokesFromSaddles.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -#include "collectStokesData.hpp" - -#include "pcg-cpp/include/pcg_random.hpp" -#include "randutils/randutils.hpp" -#include "unsupported/Eigen/CXX11/src/Tensor/TensorFFT.h" - -#define PSPIN_P 3 -const int p = PSPIN_P; // polynomial degree of Hamiltonian - -using Rng = randutils::random_generator; - -int main(int argc, char* argv[]) { - // model parameters - unsigned N = 10; // number of spins - // simulation parameters - Real ε = 1e-15; - Real δ = 1; - unsigned n = 10; - - int opt; - - while ((opt = getopt(argc, argv, "N:e:d:n:")) != -1) { - switch (opt) { - case 'N': - N = (unsigned)atof(optarg); - break; - case 'e': - ε = atof(optarg); - break; - case 'd': - δ = atof(optarg); - break; - case 'n': - n = atof(optarg); - break; - default: - exit(1); - } - } - - Rng r; - - for (unsigned i = 0; i < n; i++) { - auto tag = std::chrono::high_resolution_clock::now(); - std::ofstream output("stokes_" + std::to_string(tag.time_since_epoch().count()) + ".dat"); - collectStokesData<3>(output, N, r.engine(), ε, δ, false, 1.0); - } - - return 0; -} diff --git a/stokes.hpp b/stokes.hpp index 8c0c1fb..60a3f55 100644 --- a/stokes.hpp +++ b/stokes.hpp @@ -237,14 +237,14 @@ public: newCost = cNew.totalCost(nt); - δ *= 1.5; + δ *= 2; } std::cerr << newCost << " " << stepSize << " " << δ << std::endl; gs = cNew.gs; - return {δ / 1.5, stepSize}; + return {δ / 2, stepSize}; } void relaxNewton(unsigned nt, Real δ₀, Real ε, unsigned maxSteps) { @@ -254,9 +254,9 @@ public: while (stepSize > ε && steps < maxSteps) { std::tie(δ, stepSize) = relaxStepNewton(nt, δ); if (δ > 100) { - nt++; + break; } - δ /= 2; + δ /= 3; steps++; } } -- cgit v1.2.3-54-g00ecf