Skip to content

Commit a8d4239

Browse files
committed
[tests] switch all pytest to unit tests
1 parent e0c2f43 commit a8d4239

13 files changed

Lines changed: 679 additions & 655 deletions

Docker/openmpi_dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ ENV CPATH=/triqs/include:/usr/include/mkl:${CPATH} \
179179
CMAKE_PREFIX_PATH=/triqs/share/cmake:${CMAKE_PREFIX_PATH} \
180180
CMAKE_BUILD_PARALLEL_LEVEL=${NCORES} \
181181
CTEST_OUTPUT_ON_FAILURE=1 \
182-
CTEST_PARALLEL_LEVEL=${NCORES} \
182+
CTEST_PARALLEL_LEVEL=1 \
183183
BLA_VENDOR=Intel10_64_dyn \
184184
TRIQS_ROOT=/triqs
185185

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
numpy
33
scipy
44
argparse
5-
pytest
65
scikit-image
76
# From python 3.11 and newer, toml is part of standard implementation
87
tomli

test/python/CMakeLists.txt

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
1-
# all pytest unittests
2-
set (all_pytests
3-
test_afm_mapping
4-
test_dict_to_h5
5-
test_interaction_hamiltonian
6-
test_manipulate_chemical_potential.py
7-
test_observables.py
8-
test_postproc_toml_dict.py
9-
test_postproc_toml_dict_integration.py
10-
)
11-
12-
foreach(test ${all_pytests})
13-
get_filename_component(test_name ${test} NAME_WE)
14-
get_filename_component(test_dir ${test} DIRECTORY)
15-
16-
add_test(NAME ${test_name}
17-
COMMAND ${TRIQS_PYTHON_EXECUTABLE} -m pytest -vv ${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/${test_name}.py
18-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir})
19-
20-
set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT PYTHONPATH=${PROJECT_BINARY_DIR}/python:$ENV{PYTHONPATH})
21-
endforeach()
22-
23-
# ------------------------------#
24-
251
# all other tests
26-
set(all_tests
2+
set(basic_tests
3+
test_afm_mapping
4+
test_dict_to_h5
5+
test_interaction_hamiltonian
6+
test_manipulate_chemical_potential
7+
test_observables
8+
test_postproc_toml_dict
9+
test_postproc_toml_dict_integration
2710
test_convergence
2811
test_matheval
2912
test_plot_correlated_bands
@@ -42,7 +25,7 @@ set(all_tests
4225
# copy reference data for respack test
4326
FILE(COPY respack_sfo_data DESTINATION ${test_dir})
4427

45-
foreach(test ${all_tests})
28+
foreach(test ${basic_tests})
4629
get_filename_component(test_name ${test} NAME_WE)
4730
get_filename_component(test_dir ${test} DIRECTORY)
4831
add_test(NAME ${test_name} COMMAND ${TRIQS_PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test_dir}/${test_name}.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${test_dir})

test/python/nio_cthyb_hartree/dmft_config.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ jobname = "out"
55
mu_initial_guess = 13.751
66
enforce_off_diag = [false, true]
77

8-
n_iw = 501
9-
beta = 20
8+
n_iw = 201
9+
beta = 10
1010
w_range = [-10, 10]
1111
eta = 0.05
1212
n_w = 501
@@ -31,7 +31,7 @@ dc_dmft = false
3131
type = "cthyb"
3232
idx_impurities = [0]
3333
n_l = 25
34-
length_cycle = 1000
34+
length_cycle = 200
3535
n_warmup_cycles = 1e+3
3636
n_cycles_tot = 1e+4
3737
imag_threshold = 1e-5
-683 KB
Binary file not shown.

test/python/svo_cthyb_basic_tf/dmft_config.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ seedname = "inp"
33
jobname = "out"
44
enforce_off_diag = false
55
block_threshold = 0.001
6-
mu_initial_guess = -0.027041
6+
mu_initial_guess = -0.0289
77

8-
prec_mu = 0.001
9-
n_iw = 501
8+
prec_mu = 0.01
9+
n_iw = 301
1010

1111
h_int_type = "kanamori"
1212
U = 8.0
@@ -34,8 +34,8 @@ load_sigma = false
3434

3535
[solver]
3636
type = "cthyb"
37-
length_cycle = 120
38-
n_warmup_cycles = 8000
37+
length_cycle = 400
38+
n_warmup_cycles = 1e+3
3939
n_cycles_tot = 1e+4
4040
imag_threshold = 1e-5
4141
delta_interface = true

test/python/test_afm_mapping.py

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,56 +10,63 @@
1010
from solid_dmft.dmft_tools import afm_mapping
1111
from helper import are_iterables_equal
1212

13-
def test_determine_afm_mapping():
14-
general_params = {'magmom': [+1, -1, +1, -1], 'afm_order': True}
15-
archive = {'DMFT_input': {}}
16-
n_inequiv_shells = 4
13+
import unittest
1714

18-
expected_general_params = general_params.copy()
19-
# copy, source, switch
20-
expected_general_params['afm_mapping'] = [[False, 0, False], [True, 0, True],
21-
[True, 0, False], [True, 0, True]]
15+
class test_afm_mapping(unittest.TestCase):
16+
def test_determine_afm_mapping(self):
17+
general_params = {'magmom': [+1, -1, +1, -1], 'afm_order': True}
18+
archive = {'DMFT_input': {}}
19+
n_inequiv_shells = 4
2220

23-
general_params = afm_mapping.determine(general_params, archive, n_inequiv_shells)
21+
expected_general_params = general_params.copy()
22+
# copy, source, switch
23+
expected_general_params['afm_mapping'] = [[False, 0, False], [True, 0, True],
24+
[True, 0, False], [True, 0, True]]
2425

25-
assert are_iterables_equal(general_params, expected_general_params)
26+
general_params = afm_mapping.determine(general_params, archive, n_inequiv_shells)
2627

27-
general_params = {'magmom': [+1, -1, +2, +2], 'afm_order': True}
28-
archive = {'DMFT_input': {}}
29-
n_inequiv_shells = 4
28+
assert are_iterables_equal(general_params, expected_general_params)
3029

31-
expected_general_params = general_params.copy()
32-
# copy, source, switch
33-
expected_general_params['afm_mapping'] = [[False, 0, False], [True, 0, True],
34-
[False, 2, False], [True, 2, False]]
30+
general_params = {'magmom': [+1, -1, +2, +2], 'afm_order': True}
31+
archive = {'DMFT_input': {}}
32+
n_inequiv_shells = 4
3533

36-
general_params = afm_mapping.determine(general_params, archive, n_inequiv_shells)
34+
expected_general_params = general_params.copy()
35+
# copy, source, switch
36+
expected_general_params['afm_mapping'] = [[False, 0, False], [True, 0, True],
37+
[False, 2, False], [True, 2, False]]
3738

38-
assert are_iterables_equal(general_params, expected_general_params)
39+
general_params = afm_mapping.determine(general_params, archive, n_inequiv_shells)
3940

40-
# Reading in the afm_mapping from the archive
41-
general_params = {'magmom': [+1, -1, +2], 'afm_order': True}
42-
archive = {'DMFT_input': {'afm_mapping': [[False, 0, False], [False, 1, False],
43-
[False, 2, False]]}}
44-
n_inequiv_shells = 3
41+
assert are_iterables_equal(general_params, expected_general_params)
4542

46-
expected_general_params = general_params.copy()
47-
# copy, source, switch
48-
expected_general_params['afm_mapping'] = [[False, 0, False], [False, 1, False],
49-
[False, 2, False]]
43+
# Reading in the afm_mapping from the archive
44+
general_params = {'magmom': [+1, -1, +2], 'afm_order': True}
45+
archive = {'DMFT_input': {'afm_mapping': [[False, 0, False], [False, 1, False],
46+
[False, 2, False]]}}
47+
n_inequiv_shells = 3
5048

51-
general_params = afm_mapping.determine(general_params, archive, n_inequiv_shells)
49+
expected_general_params = general_params.copy()
50+
# copy, source, switch
51+
expected_general_params['afm_mapping'] = [[False, 0, False], [False, 1, False],
52+
[False, 2, False]]
5253

53-
assert are_iterables_equal(general_params, expected_general_params)
54+
general_params = afm_mapping.determine(general_params, archive, n_inequiv_shells)
5455

55-
general_params = {'magmom': [+1, -1, +2, +2], 'afm_order': True}
56-
archive = {'DMFT_input': {}}
57-
n_inequiv_shells = 3
56+
assert are_iterables_equal(general_params, expected_general_params)
5857

59-
expected_general_params = general_params.copy()
60-
# copy, source, switch
61-
expected_general_params['afm_order'] = False
58+
general_params = {'magmom': [+1, -1, +2, +2], 'afm_order': True}
59+
archive = {'DMFT_input': {}}
60+
n_inequiv_shells = 3
6261

63-
general_params = afm_mapping.determine(general_params, archive, n_inequiv_shells)
62+
expected_general_params = general_params.copy()
63+
# copy, source, switch
64+
expected_general_params['afm_order'] = False
65+
66+
general_params = afm_mapping.determine(general_params, archive, n_inequiv_shells)
67+
68+
assert are_iterables_equal(general_params, expected_general_params)
69+
70+
if __name__ == '__main__':
71+
unittest.main()
6472

65-
assert are_iterables_equal(general_params, expected_general_params)

test/python/test_dict_to_h5.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
from solid_dmft.io_tools import dict_to_h5
22

3-
def test_prep_params_for_h5():
4-
inp = {'a': None, 'b': {'c': None, 'd': 'e'}, 'f': [None, 'g']}
5-
expected = {'a': 'none', 'b': {'c': 'none', 'd': 'e'}, 'f': ['none', 'g']}
3+
import unittest
64

7-
assert dict_to_h5.prep_params_for_h5(inp) == expected
5+
class test_dict_to_h5(unittest.TestCase):
6+
def test_prep_params_for_h5(self):
7+
inp = {'a': None, 'b': {'c': None, 'd': 'e'}, 'f': [None, 'g']}
8+
expected = {'a': 'none', 'b': {'c': 'none', 'd': 'e'}, 'f': ['none', 'g']}
89

9-
def test_prep_params_from_h5():
10-
inp = {'a': 'none', 'b': {'c': 'none', 'd': 'e'}, 'f': ['none', 'g']}
11-
expected = {'a': None, 'b': {'c': None, 'd': 'e'}, 'f': [None, 'g']}
10+
assert dict_to_h5.prep_params_for_h5(inp) == expected
1211

13-
assert dict_to_h5.prep_params_from_h5(inp) == expected
12+
def test_prep_params_from_h5(self):
13+
inp = {'a': 'none', 'b': {'c': 'none', 'd': 'e'}, 'f': ['none', 'g']}
14+
expected = {'a': None, 'b': {'c': None, 'd': 'e'}, 'f': [None, 'g']}
15+
16+
assert dict_to_h5.prep_params_from_h5(inp) == expected
17+
18+
if __name__ == '__main__':
19+
unittest.main()

test/python/test_interaction_hamiltonian.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,27 @@
88
from solid_dmft.dmft_tools.interaction_hamiltonian import _load_crpa_interaction_matrix
99
from helper import Dummy
1010

11-
def test_load_crpa_interaction_matrix():
12-
sum_k = Dummy()
13-
sum_k.n_inequiv_shells = 2
14-
sum_k.n_corr_shells = 4
15-
sum_k.corr_shells = [{'dim': 5}, {'dim': 5}, {'dim': 5}, {'dim': 5}]
16-
sum_k.corr_to_inequiv = [0, 1, 1, 0]
17-
sum_k.inequiv_to_corr = [0, 1]
18-
sum_k.gf_struct_solver = [{'down_0' : 5, 'up_0' : 5},{'down_0' : 5, 'up_0' : 5}]
11+
import unittest
1912

20-
crpa_matrix = _load_crpa_interaction_matrix(sum_k, 'UIJKL')
13+
class test_interaction_hamiltonian(unittest.TestCase):
14+
def test_load_crpa_interaction_matrix(self):
15+
sum_k = Dummy()
16+
sum_k.n_inequiv_shells = 2
17+
sum_k.n_corr_shells = 4
18+
sum_k.corr_shells = [{'dim': 5}, {'dim': 5}, {'dim': 5}, {'dim': 5}]
19+
sum_k.corr_to_inequiv = [0, 1, 1, 0]
20+
sum_k.inequiv_to_corr = [0, 1]
21+
sum_k.gf_struct_solver = [{'down_0' : 5, 'up_0' : 5},{'down_0' : 5, 'up_0' : 5}]
2122

22-
assert [c.shape for c in crpa_matrix] == [(5, 5, 5, 5), (5, 5, 5, 5)]
23+
crpa_matrix = _load_crpa_interaction_matrix(sum_k, 'UIJKL')
2324

24-
# Warning: these assert were just taken from the current implementation
25-
# and might be wrong if the implementation is buggy
26-
assert np.isclose(np.max(crpa_matrix), 2.5363308, rtol=0, atol=1e-6)
27-
assert np.isclose(np.min(crpa_matrix), -0.1894974, rtol=0, atol=1e-6)
28-
assert np.isclose(np.min(np.abs(crpa_matrix)), 7.76e-05, rtol=0, atol=1e-6)
25+
assert [c.shape for c in crpa_matrix] == [(5, 5, 5, 5), (5, 5, 5, 5)]
26+
27+
# Warning: these assert were just taken from the current implementation
28+
# and might be wrong if the implementation is buggy
29+
assert np.isclose(np.max(crpa_matrix), 2.5363308, rtol=0, atol=1e-6)
30+
assert np.isclose(np.min(crpa_matrix), -0.1894974, rtol=0, atol=1e-6)
31+
assert np.isclose(np.min(np.abs(crpa_matrix)), 7.76e-05, rtol=0, atol=1e-6)
32+
33+
if __name__ == '__main__':
34+
unittest.main()

0 commit comments

Comments
 (0)