In this repository there are various implementations of the Monte Carlo algorithm for the calculation of the minimum in an Ising model.
- Requirements -
-
Manual
Download this repository:
git clone [email protected]:XaBerr/quantum-monte-carlo-methods.git
and compile it running:
rm build/ -rf;cmake -S . -B build;make -C build;
-
CMake module
Module data:
FetchContent_Declare( "QMC-methods" GIT_REPOSITORY https://github.com/XaBerr/quantum-monte-carlo-methods.git GIT_TAG 1.0.0 )
All include files are available in the include
directory.
After the inclusion it is required to instantiate the random distribution Uniform
.
Libraries can be included individually:
#include <QMC-methods/SimulatedAnnealing.h>
#include <QMC-methods/SantoroTosattiMartonak.h>
#include <QMC-methods/SwendsenWang.h>
using namespace QMCm;
static Uniform uniform;
or in batch using the single include:
#include <QMC-methods.h>
using namespace QMCm;
static Uniform uniform;
These are the algorithms implemented until now:
- Simulated Annealing
- SwendsenWang
- SantoroTosattiMartonak
- RiegerKawashimaDiscrete
- RiegerKawashimaContinuous
First you must generate your Ising model.
SimulatedAnnealing monteCarlo;
monteCarlo.startingConfig.size = 3;
monteCarlo.startingConfig.generate();
Then you can set the spins and fields values.
/*
Initial nodes matrix of values
1 1 1
1 1 1
1 1 1
*/
for (int i = 0; i < monteCarlo.startingConfig.nodes.size(); i++) {
for (int j = 0; j < monteCarlo.startingConfig.nodes.size(); j++) {
monteCarlo.startingConfig.nodes[i][j].value = 1;
monteCarlo.startingConfig.nodes[i][j].spin = (uniform() < 0.5) ? 1 : -1;
}
}
/*
Initial arcs matrix of values
1 1 1
1 1 1
1 1 1
*/
for (int i = 0; i < monteCarlo.startingConfig.arcs.size(); i++)
for (int j = 0; j < monteCarlo.startingConfig.arcs[i].size(); j++)
for (int k = 0; k < monteCarlo.startingConfig.arcs[i][k].size(); k++)
monteCarlo.startingConfig.arcs[i][j][k].value = 1;
Last you run the algorithm few times.
printf("The starting energy is [%f]\n", monteCarlo.startingConfig.getEnergy());
for (int i = 0; i < 10; i++) {
monteCarlo.run();
printf("The ending energy is [%f]\n", monteCarlo.endingConfig.getEnergy());
}
First you must generate your Ising model.
SwendsenWang monteCarlo;
monteCarlo.startingConfig.size = 3;
monteCarlo.startingConfig.generate();
Then you can set the spins and fields values.
/*
Initial nodes matrix of values
1 1 1
1 1 1
1 1 1
*/
for (int i = 0; i < monteCarlo.startingConfig.nodes.size(); i++) {
for (int j = 0; j < monteCarlo.startingConfig.nodes.size(); j++) {
monteCarlo.startingConfig.nodes[i][j].value = 1;
monteCarlo.startingConfig.nodes[i][j].spin = (uniform() < 0.5) ? 1 : -1;
}
}
/*
Initial arcs matrix of values
1 1 1
1 1 1
1 1 1
*/
for (int i = 0; i < monteCarlo.startingConfig.arcs.size(); i++)
for (int j = 0; j < monteCarlo.startingConfig.arcs[i].size(); j++)
for (int k = 0; k < monteCarlo.startingConfig.arcs[i][k].size(); k++)
monteCarlo.startingConfig.arcs[i][j][k].value = 1;
Last you run the algorithm few times.
printf("The starting energy is [%f]\n", monteCarlo.startingConfig.getEnergy());
for (int i = 0; i < 10; i++) {
monteCarlo.run();
printf("The ending energy is [%f]\n", monteCarlo.endingConfig.getEnergy());
}
First you must generate your Ising model that will be used to generate the transverse once.
SantoroTosattiMartonak transverseMonteCarlo;
transverseMonteCarlo.startingConfig.numberOfreplicas = 3;
transverseMonteCarlo.startingConfig.mainReplica.size = 3;
transverseMonteCarlo.startingConfig.mainReplica.generate();
Then you can set the spins and fields values.
/*
Initial nodes matrix of values
1 1 1
1 1 1
1 1 1
*/
for (int i = 0; i < transverseMonteCarlo.startingConfig.mainReplica.nodes.size(); i++) {
for (int j = 0; j < transverseMonteCarlo.startingConfig.mainReplica.nodes[i].size(); j++) {
transverseMonteCarlo.startingConfig.mainReplica.nodes[i][j].value = 1;
transverseMonteCarlo.startingConfig.mainReplica.nodes[i][j].spin =
(uniform() < 0.5) ? 1 : -1;
}
}
/*
Initial arcs matrix of values
1 1 1
1 1 1
1 1 1
*/
for (int i = 0; i < transverseMonteCarlo.startingConfig.mainReplica.arcs.size(); i++)
for (int j = 0; j < transverseMonteCarlo.startingConfig.mainReplica.arcs[i].size(); j++)
for (int k = 0; k < transverseMonteCarlo.startingConfig.mainReplica.arcs[i][j].size(); k++)
transverseMonteCarlo.startingConfig.mainReplica.arcs[i][j][k].value = 1;
Here you have an intermediate step to generate the transverse Ising model.
transverseMonteCarlo.startingConfig.generate();
Last you run the algorithm few times.
printf("The starting energy is [%f]\n", transverseMonteCarlo.startingConfig.getIsingDiscreteEnergy());
for (int i = 0; i < 10; i++) {
transverseMonteCarlo.run();
printf("The ending energy is [%f]\n", transverseMonteCarlo.endingConfig.getIsingDiscreteEnergy());
}
The parameters for the Ising model (monteCarlo.startingConfig, transverseMonteCarlo.startingConfig.mainReplica) are the following:
// the size of the square of the Ising model
monteCarlo.startingConfig.size = +3;
// energy configuration parameters
monteCarlo.startingConfig.favorAlignment = true;
monteCarlo.startingConfig.favorSpinUp = true;
// if we want the structure is recursive
monteCarlo.startingConfig.periodicBoundary = false;
// this is the boundary of the random generation that is used by default
monteCarlo.startingConfig.nodeMaxValue = +1;
monteCarlo.startingConfig.nodeMinValue = -1;
monteCarlo.startingConfig.arcMaxValue = +1;
monteCarlo.startingConfig.arcMinValue = -1;
The parameters for the transverse Ising model (transverseMonteCarlo.startingConfig) are the following.
// number of replicas of the Ising model
transverseMonteCarlo.startingConfig.numberOfreplicas = 3;
// initial strength of the transverse field
transverseMonteCarlo.startingConfig.transverseField = 1;
// periodic boundary along the time direction
transverseMonteCarlo.startingConfig.periodicBoundary = false;
Also check out the example in apps/example.cpp
.
At the moment I don't have time to finish the last two algorithms, if you want to finish and push them, I would gladly accept a pull request.
Of course if you like this repository remember to ⭐ the project!