summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--collectStokesData.hpp37
-rw-r--r--mixedStokes.cpp (renamed from pureStokesFromMinima.cpp)14
-rw-r--r--mixedStokesFromMinima.cpp54
-rw-r--r--mixedStokesFromSaddles.cpp54
-rw-r--r--pureStokes.cpp (renamed from pureStokesFromSaddles.cpp)14
-rw-r--r--stokes.hpp8
6 files changed, 38 insertions, 143 deletions
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<Real>;
template<int ...ps, class Generator, typename... T>
-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<Real, ps...> 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<Real, ps>&... 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<Real, ps>&... 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<Complex> zi = c.f((i + 1.0) / (100.0 * nTs + 1.0));
+ unsigned nTest = nTs * 10;
+
+ for (unsigned i = 0; i < nTest; i++) {
+ Vector<Complex> 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<Complex>& gi : c.gs) {
file << gi.transpose() << std::endl;
}
diff --git a/pureStokesFromMinima.cpp b/mixedStokes.cpp
index 8f815cf..09a75b2 100644
--- a/pureStokesFromMinima.cpp
+++ b/mixedStokes.cpp
@@ -1,15 +1,10 @@
#include <getopt.h>
#include <chrono>
-#include <fstream>
#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<pcg32>;
@@ -20,10 +15,11 @@ int main(int argc, char* argv[]) {
Real ε = 1e-15;
Real δ = 1;
unsigned n = 10;
+ bool useMinima = false;
int opt;
- while ((opt = getopt(argc, argv, "N:e:d:n:")) != -1) {
+ while ((opt = getopt(argc, argv, "N:e:d:n:m")) != -1) {
switch (opt) {
case 'N':
N = (unsigned)atof(optarg);
@@ -37,6 +33,9 @@ int main(int argc, char* argv[]) {
case 'n':
n = atof(optarg);
break;
+ case 'm':
+ useMinima = true;
+ break;
default:
exit(1);
}
@@ -46,8 +45,7 @@ int main(int argc, char* argv[]) {
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);
+ 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 <getopt.h>
-#include <chrono>
-#include <fstream>
-
-#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<pcg32>;
-
-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 <getopt.h>
-#include <chrono>
-#include <fstream>
-
-#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<pcg32>;
-
-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/pureStokesFromSaddles.cpp b/pureStokes.cpp
index 6516a80..a07dbbc 100644
--- a/pureStokesFromSaddles.cpp
+++ b/pureStokes.cpp
@@ -1,15 +1,10 @@
#include <getopt.h>
#include <chrono>
-#include <fstream>
#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<pcg32>;
@@ -20,10 +15,11 @@ int main(int argc, char* argv[]) {
Real ε = 1e-15;
Real δ = 1;
unsigned n = 10;
+ bool useMinima = false;
int opt;
- while ((opt = getopt(argc, argv, "N:e:d:n:")) != -1) {
+ while ((opt = getopt(argc, argv, "N:e:d:n:m")) != -1) {
switch (opt) {
case 'N':
N = (unsigned)atof(optarg);
@@ -37,6 +33,9 @@ int main(int argc, char* argv[]) {
case 'n':
n = atof(optarg);
break;
+ case 'm':
+ useMinima = true;
+ break;
default:
exit(1);
}
@@ -46,8 +45,7 @@ int main(int argc, char* argv[]) {
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);
+ collectStokesData<3>(std::to_string(tag.time_since_epoch().count()), N, r.engine(), ε, δ, useMinima, 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++;
}
}