#include #include "complex_normal.hpp" #include "p-spin.hpp" #include "dynamics.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 Complex = std::complex; using ComplexVector = Vector; using ComplexMatrix = Matrix; using ComplexTensor = Tensor; using Rng = randutils::random_generator; int main(int argc, char* argv[]) { // model parameters unsigned N = 10; // number of spins double T = 1; // temperature double Rκ = 1; // real part of distribution parameter double Iκ = 0; // imaginary part of distribution parameter // simulation parameters double ε = 1e-4; double εJ = 1e-2; double δ = 1e-2; // threshold for determining saddle double Δ = 1e-3; double γ = 1e-2; // step size unsigned t = 1000; // number of Langevin steps unsigned M = 100; unsigned n = 100; int opt; while ((opt = getopt(argc, argv, "N:M:n:T:e:r:i:g:t:E:")) != -1) { switch (opt) { case 'N': N = (unsigned)atof(optarg); break; case 't': t = (unsigned)atof(optarg); break; case 'T': T = atof(optarg); break; case 'e': δ = atof(optarg); break; case 'E': ε = atof(optarg); break; case 'g': γ = atof(optarg); case 'r': Rκ = atof(optarg); break; case 'i': Iκ = atof(optarg); break; case 'n': n = (unsigned)atof(optarg); break; case 'M': M = (unsigned)atof(optarg); break; default: exit(1); } } Complex κ(Rκ, Iκ); double σ = sqrt(factorial(p) / (2.0 * pow(N, p - 1))); Rng r; complex_normal_distribution<> d(0, 1, 0); ComplexTensor J = generateCouplings(N, complex_normal_distribution<>(0, σ, κ), r.engine()); ComplexVector z0 = normalize(randomVector(N, d, r.engine())); ComplexVector zSaddle = findSaddle(J, z0, ε); ComplexVector zSaddlePrev = ComplexVector::Zero(N); ComplexVector z = zSaddle; while (δ < (zSaddle - zSaddlePrev).norm()) { // Until we find two saddles sufficiently close... std::tie(std::ignore, z) = langevin(J, z, T, γ, M, d, r.engine()); try { ComplexVector zSaddleNext = findSaddle(J, z, ε); if (Δ < (zSaddleNext - zSaddle).norm()) { // Ensure we are finding distinct saddles. zSaddlePrev = zSaddle; zSaddle = zSaddleNext; } } catch (std::exception& e) { std::cerr << "Could not find a saddle: " << e.what() << std::endl; } std::cerr << "Current saddles are " << (zSaddle - zSaddlePrev).norm() << " apart." << std::endl; } std::cerr << "Found sufficiently nearby saddles, perturbing J." << std::endl; complex_normal_distribution<> dJ(0, εJ * σ, 0); std::function)> perturbJ = [&dJ, &r] (ComplexTensor& JJ, std::array ind) { Complex Ji = getJ(JJ, ind); setJ(JJ, ind, Ji + dJ(r.engine())); }; for (unsigned i = 0; i < n; i++) { ComplexTensor Jp = J; iterateOver(Jp, perturbJ); try { ComplexVector zSaddleNew = findSaddle(Jp, zSaddle, ε); ComplexVector zSaddlePrevNew = findSaddle(Jp, zSaddlePrev, ε); std::cout << zSaddleNew.transpose() << " " << zSaddlePrevNew.transpose() << std::endl; } catch (std::exception& e) { std::cerr << "Couldn't find a saddle with new couplings, skipping." << std::endl; } } return 0; }