Esempio n. 1
0
def test_nspinspec_sparse():
    # GIVEN v and J inputs for the Rioux 3-spin system
    v, J = rioux()
    # WHEN nspinspec_sparse is called with those inputs
    spectrum = nspinspec_sparse(v, J)
    # THEN the resulting spectrum matches that using the old algorithm
    assert np.allclose(spectrum, SPECTRUM_RIOUX)
Esempio n. 2
0
def test_hamiltonian_sparse():
    # GIVEN v and J inputs for the Rioux 3-spin system
    v, J = rioux()
    # WHEN hamiltonian_dense is used to calculate the Hamiltonian
    H_sparse = hamiltonian_sparse(v, J)
    # THEN it matches the Hamiltonian result using the old accepted algorithm
    assert np.array_equal(H_sparse.todense(), H_RIOUX)
Esempio n. 3
0
"""Collection of the current best candidates for nmrtools functions,
for testing speed etc.

"""

from nmrtools.nmrmath import hamiltonian as current_hamiltonian
from nmrtools.nmrmath import simsignals as current_simsignals

from speedtest.compare_hamiltonians import hamiltonian_sparse as \
    candidate_hamiltonian
from tests.test_simsignals import vectorized_simsignals as candidate_simsignals

if __name__ == '__main__':
    import numpy as np
    from simulation_data import rioux
    current_h = current_hamiltonian(*rioux())
    current_spectrum = current_simsignals(current_h, 3)
    candidate_h = candidate_hamiltonian(*rioux())
    candidate_spectrum = candidate_simsignals(candidate_h, 3)

    print(current_spectrum[:10])
    print(candidate_spectrum[:10])
    assert np.allclose(current_spectrum, candidate_spectrum)
Esempio n. 4
0
def test_h_mem():
    return candidate_hamiltonian(*rioux())
Esempio n. 5
0
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)


@timefn
def multitest(test, h, n):
Esempio n. 6
0
import numpy as np

from nmrtools.nmrmath import hamiltonian, nspinspec
from nmrtools.qm import (
    hamiltonian_dense,
    hamiltonian_sparse,
    nspinspec_dense,
    nspinspec_sparse,
    # hs2, nss2
)
from simulation_data import rioux

H_RIOUX = hamiltonian(*rioux())
SPECTRUM_RIOUX = nspinspec(*rioux())


def test_hamiltonian_dense():
    # GIVEN v and J inputs for the Rioux 3-spin system
    v, J = rioux()
    # WHEN hamiltonian_dense is used to calculate the Hamiltonian
    H_dense = hamiltonian_dense(v, J)
    # THEN it matches the Hamiltonian result using the old accepted algorithm
    assert np.array_equal(H_dense, H_RIOUX)


def test_hamiltonian_sparse():
    # GIVEN v and J inputs for the Rioux 3-spin system
    v, J = rioux()
    # WHEN hamiltonian_dense is used to calculate the Hamiltonian
    H_sparse = hamiltonian_sparse(v, J)
    # THEN it matches the Hamiltonian result using the old accepted algorithm