def test_newH_profile(): n = 10 H = hamiltonian_sparse(*spin11()) for i in range(n): _ = simsignals2(H, 11) assert 1 == 1
from scipy.sparse import csc_matrix, csr_matrix, lil_matrix import sparse from nmrtools.nmrmath import is_allowed, normalize_spectrum, transition_matrix from nmrtools.nmrplot import nmrplot from speedtest.compare_hamiltonians import hamiltonian, hamiltonian_sparse from speedtest.speedutils import timefn from tests.test_spectraspeed import simsignals from simulation_data import spin8, spin3, spin11, rioux H3_MATRIX = hamiltonian(*spin3()) H3_NDARRAY = hamiltonian_sparse(*spin3()) H8_MATRIX = hamiltonian(*spin8()) H8_NDARRAY = hamiltonian_sparse(*spin8()) H11_MATRIX = hamiltonian(*spin11()) H11_NDARRAY = hamiltonian_sparse(*spin11()) H_RIOUX = hamiltonian(*rioux()) H_RIOUX_SPARSE = hamiltonian_sparse(*rioux()) @timefn def numpy_eigh(h): return np.linalg.eigh(h) @timefn def scipy_eigh(h): return scipy.linalg.eigh(h)
from simulation_data import spin11, rioux from candidates import candidate_hamiltonian, candidate_simsignals from tests.test_simsignals import H_RIOUX, H11_NDARRAY @profile def test_h_mem(): return candidate_hamiltonian(*rioux()) @profile def test_spec_mem(v, J): h = candidate_hamiltonian(v, J) return candidate_simsignals(h, len(v)) if __name__ == '__main__': test_spec_mem(*spin11())
Lcol = np.vstack((Lx, Ly, Lz)).real Lrow = Lcol.T # As opposed to sparse version of code, this works! Lproduct = np.dot(Lrow, Lcol) # Hamiltonian operator H = np.zeros((2**nspins, 2**nspins)) # Add Zeeman interactions: for n in range(nspins): H = H + freqlist[n] * Lz[0, n] # Scalar couplings # Testing with MATLAB discovered J must be /2. # Believe it is related to the fact that in the SpinDynamics.org simulation # freqs are *2pi, but Js by pi only. scalars = 0.5 * couplings scalars = np.multiply(scalars, Lproduct) for n in range(nspins): for k in range(nspins): H += scalars[n, k].real return H standard_3 = hamiltonian_original(*spin3()) standard_8 = hamiltonian_original(*spin8()) standard_11 = hamiltonian(*spin11()) # standard_fox = hamiltonian(*fox())