Getting Started

To do a development install, download this repository and type pip install -e .in the root directory.

python MonteCarlo\Ising.py from root directory to run Ising Hamiltonian calculations and plot results

python MonteCarlo\MonteCarloSampling.py from root directory to run MonteCarlo Sweep on Hamiltonian and plot results agains actual values

Modules and Examples

The examples in this section provides an overview of how to use each module and class. The details of how all values are calculated in the class overview

Ising

This module includes a set of functions that are used to calculate and plot the average energy, average magnetism, heat capacity, and magnetic susceptibility for a one dimensional lattices of a given length. Do do this, all possible spin configurations with the appropriate length are calculated. The above values are calculated at a given temperature and the process is repeated for all temperatures in some range.

# import dependencies
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import math

# import package and submodules
import MonteCarlo
from MonteCarlo import Ising
from MonteCarlo import SpinConfiguration
from MonteCarlo import SingleDimensionHamiltonian

# assign the length of the spin configurations
latticeLength = 5

# create new list of spinConfiguration objects
spinConfigList = MonteCarlo.Ising.generateSpinConfigurations(latticeLength)

# print each spinConfigurations spins in binary
print("spinCongfigurations: ")
for sc in spinConfigList:
    print(sc.spins)

# define temperature, J constant, mu constant, and lattice length
temperature = 5
J = -2
mu = 1.1
latticeLength = 4

# calculate a dictionary of values
values = MonteCarlo.Ising.calculateValues(temperature, J, mu, latticeLength)

# call function do display the result of calling the above function
# note: this will rerun the above function
print("Values: ")
MonteCarlo.Ising.printValues(temperature, J, mu, latticeLength)



# call funtion to produce a plot of the results of the above function for temperatures between .1 and a maximum temp that you determine
maxTemp = 10
MonteCarlo.Ising.plotValues(maxTemp, J, mu, latticeLength)

Spin Configuration

This module contains the spinConfiguration class which includes functions for converting a bitstring into spins and calculating a spinConfiguration's magnetism.

# import dependencies
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import math

# import package and submodules
import MonteCarlo
from MonteCarlo import SpinConfiguration
# import spinConfiguration class from SpinConfiguration Module
from  MonteCarlo.SpinConfiguration import spinConfiguration

# select the lattice length for this spinConfiguration\
latticeLength = 5

# select a decimal value that will be converted into a binary representation of the spins of this spinConfiguration
# note this value must be between 0 and 2^latticeLength
binaryConfiguration = 4


spinConfig = spinConfiguration(binaryConfiguration, latticeLength)

# display the converted binary representation of the integer that you entered
print("Spins: {}".format(spinConfig.spins))


# calculate and display the magnetism value of this spinConfiguration object
print("Magnetism: {}".format(spinConfig.calculateMagnetism()))

Single Dimension Hamiltonian

This module contains the SingleDimensionHamiltonian class which includes functions for building a hamiltonian from a given spin configuration and calculating its energy.

# import dependencies
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
import math

# import package and submodules
import MonteCarlo
from MonteCarlo import SpinConfiguration
from MonteCarlo import SingleDimensionHamiltonian

# import SingleDimensionHamiltonian and spinConfiguration class
from  MonteCarlo.SpinConfiguration import spinConfiguration
from  MonteCarlo.SingleDimensionHamiltonian import SingleDimensionHamiltonian

# create a spinConfiguration object
spinConfig = spinConfiguration(10, 5)


# define J and mu constants
J  = -2
mu = 1.1

# create a hamiltonian object
ham = SingleDimensionHamiltonian(J, mu, spinConfig)

# calculate and display the energy of this hamiltonian
print("Energy: {}".format(ham.calculateEnergy()))

Theory

This package uses the Ising mathematical model in order to calculate the energy of a Hamiltonian.