Giter Club home page Giter Club logo

quantum-monte-carlo-methods's Introduction

logo

QMC-methods

In this repository there are various implementations of the Monte Carlo algorithm for the calculation of the minimum in an Ising model.
- Requirements -


Installation

  • 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
    )

Inclusion

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;

Usage

These are the algorithms implemented until now:

Simulated Annealing

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());
}

Swendsen Wang

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());
}

Santoro Tosatti Martonak

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());
}

2D Ising model parameters

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;

2D Transverse Ising model parameters

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;

Example

Also check out the example in apps/example.cpp.

Contributions

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!

quantum-monte-carlo-methods's People

Contributors

xaberr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.