ising-model | Python implementation of the Ising model
kandi X-RAY | ising-model Summary
kandi X-RAY | ising-model Summary
Python code to simulate the Ising model of a Ferromagnet. For a discussion of the theory, visit my blog post. The initial conditions of the ising lattice can be specified by the tempature, initial state, and size parameters of the model. Running the simulation will output a video of system as it changes through out the run steps.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Runs the fitting algorithm
- Return the index of the index i
- Calculate the energy of a system
- Compute the internal energy
ising-model Key Features
ising-model Examples and Code Snippets
Community Discussions
Trending Discussions on ising-model
QUESTION
I'm trying to solve a 2D-Ising model with Monte Carlo approach.
As it is slow I used Cython to accelerate the code execution. I would like to push it even further and parallelize the Cython code. My idea is to split the 2D-lattice in two, so for any point on a lattice has it's nearest neigbours on the other lattice. This way I can randomly choose one lattice and I can flip all the spins and this could be done in parallel since all those spins are independent.
So far this is my code :
( inspired from http://jakevdp.github.io/blog/2017/12/11/live-coding-cython-ising-model/ )
ANSWER
Answered 2020-Jun-07 at 18:39From a Cython point-of-view the main problem is that cy_spin_flip
requires the GIL. You need to add nogil
to the end of its signature, and set the return type to void
(since by default it returns a Python object, which requires the GIL).
However, np.exp
and np.random.rand
also require the GIL, because they're Python function calls. np.exp
is probably easily replaced with libc.math.exp
. np.random
is a bit harder, but there's plenty of suggestions for C- and C++-based approaches: 1 2 3 4 (+ others).
A more fundamental problem is the line:
QUESTION
I'm writing a simulation of the Ising model in 2D. The model behaves as predicted except for one thing: the critical temperature is roughly 3.5 while it should be near 2/ln(2 + sqrt (2))
.
The project is a C++ program that generates the data, and a shell script that exercises the program. The full code can be found here. Also here's lattice.cpp
...ANSWER
Answered 2018-Apr-05 at 11:27I have found a few issues in your code:
The
compute_dE
method returns the wrong energy, as the factor of 2 shouldn't be there. The Hamiltonian of the Ising system isWhile you are effectively using
The
compute_energy
method returns the wrong energy. The method should iterate over each spin pair only once. Something like this should do the trick:for (unsigned int i = 0; i < max; i++) { for (unsigned int j = i + 1; j < max; j++) { energy_sum += other.compute_point_energy(i, j); } }
You use a temperature that is updated on the fly instead of using the target temperature. I do not really understand the purpose of that.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ising-model
You can use ising-model like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page