def test_z(): for T in np.linspace(1., 10., 5): analytic = a.z(T) calculated = 0 states = a.produce_states() for state in states: energy = a.energy(state) calculated += np.exp(-1 / T * energy) assert analytic == approx(calculated, abs=tol)
def test_E2(): "<E^2>" for T in np.linspace(1., 10., 5): B = 1 / T analytic = 256 / a.z(T) * np.cosh(8 * B) states = a.produce_states() calculated = 0 for state in states: energy = a.energy(state) prob = a.probability(T, state) calculated += prob * energy**2 assert analytic == approx(calculated, abs=tol)
def test_Esquared(): "<E>^2" for T in np.linspace(1., 10., 3): B = 1 / T zt = a.z(T) analytic = 32**2 / (zt)**2 * np.sinh(8 * B)**2 states = a.produce_states() calculated = 0 for state in states: energy = a.energy(state) prob = a.probability(T, state) calculated += prob * energy assert analytic == approx(calculated**2)
def test_Msquared(): """ <M>^2 """ for T in np.linspace(1., 10., 5): B = 1 / T analytic = 64 / a.z(T)**2 * (4 * np.exp(8 * B) + np.exp(16 * B) + 4) states = a.produce_states() calculated = 0 for state in states: magnet = np.abs(a.magnetization(state)) prob = a.probability(T, state) calculated += prob * magnet assert analytic == approx(calculated**2, abs=tol)
def test_M2(): """ <M^2> """ for T in np.linspace(1., 10., 5): B = 1 / T analytic = 32 / a.z(T) * (np.exp(8 * B) + 1) states = a.produce_states() calculated = 0 for state in states: magnet = np.abs(a.magnetization(state)) prob = a.probability(T, state) calculated += prob * magnet**2 assert analytic == approx(calculated, abs=tol)
def test_M(): """ <M> """ for T in np.linspace(1., 10., 5): # analytic = a.expected_magnetization(T) zt = a.z(T) B = 1 / T analytic = 8 / zt * (np.exp(8 * B) + 2) states = a.produce_states() calculated = 0 for state in states: magnetization = a.magnetization(state) prob = a.probability(T, state) calculated += np.abs(magnetization) * prob assert analytic == approx(calculated, abs=tol)