def test_cleanup(): # make a mess v, J = spin8() hamiltonian(v, J) # then clean it up files_cleaned = cleanup() print('FILES CLEANED:') print(files_cleaned) path = os.getcwd() spin8_operators = ['Lproduct8.npy', 'Lz8.npy'] operators = [os.path.join(path, operator) for operator in spin8_operators] assert files_cleaned == operators for operator in operators: assert not os.path.isfile(operator), 'File left behind! ' + operator
def test_oldH_profile(): n = 10 H = hamiltonian(*spin11()) for i in range(n): _ = simsignals2(H, 11) assert 1 == 1
"""Testing the performance for the entire spectrum calculation.""" import numpy as np 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 simulation_data import spin8, spin3, spin11 H8 = hamiltonian(*spin8()) H8_SPARSE = hamiltonian_sparse(*spin8()) print('Import type: ', type(H8_SPARSE)) # Below are older functions that were written before completion of # test_simsignals.py def nspinspec(h_func, freqs, couplings, normalize=True): """A version of nmrtools.nmrmath.nspinspec that accepts different H functions.""" """ Calculates second-order spectral data (freqency and intensity of signals) for *n* spin-half nuclei. Parameters --------- freqs : [float...] a list of *n* nuclei frequencies in Hz couplings : array-like
def test_hamiltonian(): v, J = SPIN_SYSTEM() test_H = hamiltonian(v, J) assert np.array_equal(test_H, STANDARD_H)
def hamiltonian_loop(v, J, n): for i in range(n): _ = hamiltonian(v, J) # cleanup() return _
profile = line_profiler.LineProfiler() import numpy as np import scipy 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