montecarlo

Multiprocessing not using whole CPU

Multiprocessing not using whole CPU Question: I’m testing python’s module "multiprocessing". I’m trying to compute pi using a montecarlo technique using my 12 threads ryzen 5 5600. The problem is that my cpu is not fully used, instead only 47% is used. I leave you my code below, changing the value of n_cpu leads to …

Total answers: 1

Further optimizing the ISING model

Further optimizing the ISING model Question: I’ve implemented the 2D ISING model in Python, using NumPy and Numba’s JIT: from timeit import default_timer as timer import matplotlib.pyplot as plt import numba as nb import numpy as np # TODO for Dict optimization. # from numba import types # from numba.typed import Dict @nb.njit(nogil=True) def initialstate(N): …

Total answers: 2

Trying to generate a conditional coin flip

Trying to generate a conditional coin flip Question: So I’m a trying to create a function which first flips an unbiased coin but if the result is heads it flips a biased coin with 0.75 probability of heads. If it shows tails then the next flip is unbiased. I’ve tried the following code but I …

Total answers: 3

How can I use 'prange' in Cython?

How can I use 'prange' in Cython? Question: I’m trying to solve a two-dimensional Ising model with a 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 two-dimensional lattice in …

Total answers: 2

Random Number from Histogram

Random Number from Histogram Question: Suppose I create a histogram using scipy/numpy, so I have two arrays: one for the bin counts, and one for the bin edges. If I use the histogram to represent a probability distribution function, how can I efficiently generate random numbers from that distribution? Asked By: xvtk || Source Answers: …

Total answers: 7