From 6eb4161249577769cca8be543555140c096f1fc4 Mon Sep 17 00:00:00 2001 From: Noam Bernstein Date: Mon, 22 Jul 2024 12:56:13 -0400 Subject: [PATCH] Do QE tests using user's default config file. Update complete_test.tin and github CI test to be consistent --- .github/workflows/pytests.yml | 20 +++--- tests/calculators/test_qe.py | 88 +++++++------------------ tests/local_scripts/complete_pytest.tin | 11 +--- 3 files changed, 33 insertions(+), 86 deletions(-) diff --git a/.github/workflows/pytests.yml b/.github/workflows/pytests.yml index c95e25c6..82dd8c32 100644 --- a/.github/workflows/pytests.yml +++ b/.github/workflows/pytests.yml @@ -182,17 +182,15 @@ jobs: ls -l /usr/bin/pw.x espresso_command=pw.x - - name: set up ASE config files (same content but in multiple pytest run directories) + - name: set up ASE config files run: | - export config_file_plain=${HOME}/pytest_plain_config.ini - echo "[espresso]" > ${config_file_plain} - echo "command = ${espresso_command}" >> ${config_file_plain} - echo "pseudo_dir = ${HOME}/pytest_plain" >> ${config_file_plain} - - export config_file_cov=${HOME}/pytest_cov_config.ini - echo "[espresso]" > ${config_file_cov} - echo "command = ${espresso_command}" >> ${config_file_cov} - echo "pseudo_dir = ${HOME}/pytest_cov" >> ${config_file_cov} + export config_file=${HOME}/pytest_plain_config.ini + echo "[espresso]" > ${config_file} + echo "command = ${espresso_command}" >> ${config_file} + echo "pseudo_dir = ${HOME}/dummy" >> ${config_file} + export ASE_CONFIG_PATH=${config_file} + echo ASE_CONFIG_PATH $ASE_CONFIG_PATH + cat $ASE_CONFIG_PATH - name: Lint with flake8 run: | @@ -212,7 +210,6 @@ jobs: export WFL_NUM_PYTHON_SUBPROCESSES=2 export OMP_NUM_THREADS=1 export WFL_JULIA_COMMAND=${PWD}/julia-1.8.1/bin/julia - export ASE_CONFIG_PATH=${config_file_plain} pytest --runremote --basetemp $HOME/pytest_plain -rxXs - name: Test with pytest - coverage @@ -230,7 +227,6 @@ jobs: export WFL_NUM_PYTHON_SUBPROCESSES=2 export OMP_NUM_THREADS=1 export WFL_JULIA_COMMAND=${PWD}/julia-1.8.1/bin/julia - export ASE_CONFIG_PATH=${config_file_cov} pytest -v --cov=wfl --cov-report term --cov-report html --cov-config=tests/.coveragerc --cov-report term-missing --cov-report term:skip-covered --runremote --basetemp $HOME/pytest_cov -rxXs # # DEBUGGING diff --git a/tests/calculators/test_qe.py b/tests/calculators/test_qe.py index e8b488ae..c10afe15 100644 --- a/tests/calculators/test_qe.py +++ b/tests/calculators/test_qe.py @@ -28,18 +28,17 @@ from ase.config import cfg as ase_cfg from ase.calculators.espresso import EspressoProfile -pytest_command = os.environ.get("PYTEST_WFL_ASE_ESPRESSO_COMMAND") -if "espresso" in ase_cfg.parser and os.environ.get('OMP_NUM_THREADS') == "1": - pytest_command = EspressoProfile.from_config(ase_cfg, "espresso").command -else: - pytest.skip('No command in "espresso" configuration or "OMP_NUM_THREADS" is not set to 1.') +# do all tests using user's default config file +# pseudo_dir will be overridden whenever calculator is constructed to ensure that +# pytest-specific PPs are used +if not ("espresso" in ase_cfg.parser and os.environ.get('OMP_NUM_THREADS') == "1"): + pytest.skip('No "espresso" configuration or "OMP_NUM_THREADS" is not set to 1.') @fixture(scope="session") def qe_profile_and_pseudo(tmp_path_factory): """Quantum Espresso fixture - - create profile with command from user's profile and pseudo_dir for pytest PPs - copies a pseudo-potential for Si implementation based on: @@ -47,8 +46,6 @@ def qe_profile_and_pseudo(tmp_path_factory): Returns ------- - profile: str - EspressoProfile with correct command and pseudo dir for pytest pspot_file: str Si pseudo potential file name """ @@ -66,25 +63,25 @@ def qe_profile_and_pseudo(tmp_path_factory): pspot_file = tmp_path_factory.getbasetemp() / "Si.UPF" shutil_copy(Path(__file__).parent.parent / "assets" / "QE" / "Si.pz-vbc.UPF", pspot_file) - return EspressoProfile(command=pytest_command, pseudo_dir=pspot_file.parent), pspot_file.name + return pspot_file def test_qe_kpoints(tmp_path, qe_profile_and_pseudo): - profile, pspot = qe_profile_and_pseudo + pspot = qe_profile_and_pseudo kw = dict( - pseudopotentials=dict(Si=pspot), + pseudopotentials=dict(Si=pspot.name), + pseudo_dir=pspot.parent, input_data={"SYSTEM": {"ecutwfc": 40, "input_dft": "LDA",}}, kpts=(2, 3, 4), conv_thr=0.0001, - workdir=tmp_path, - profile=profile - ) + workdir=tmp_path + ) # PBC = TTT atoms = Atoms("H", cell=[1, 1, 1], pbc=True) - properties = ["energy", "stress"] + properties = ["energy", "stress"] calc = wfl.calculators.espresso.Espresso(**kw) calc.atoms = atoms.copy() calc.setup_calc_params(properties) @@ -168,7 +165,7 @@ def test_qe_kpoints(tmp_path, qe_profile_and_pseudo): def test_qe_calculation(tmp_path, qe_profile_and_pseudo): - profile, pspot = qe_profile_and_pseudo + pspot = qe_profile_and_pseudo # atoms at = bulk("Si") @@ -176,12 +173,12 @@ def test_qe_calculation(tmp_path, qe_profile_and_pseudo): at0 = Atoms("Si", cell=[6.0, 6.0, 6.0], positions=[[3.0, 3.0, 3.0]], pbc=False) kw = dict( - pseudopotentials=dict(Si=pspot), + pseudopotentials=dict(Si=pspot.name), + pseudo_dir=pspot.parent, input_data={"SYSTEM": {"ecutwfc": 40, "input_dft": "LDA",}}, kpts=(2, 2, 2), conv_thr=0.0001, - workdir=tmp_path, - profile=profile + workdir=tmp_path ) calc = (wfl.calculators.espresso.Espresso, [], kw) @@ -227,16 +224,16 @@ def test_qe_calculation(tmp_path, qe_profile_and_pseudo): def test_wfl_Espresso_calc(tmp_path, qe_profile_and_pseudo): - profile, pspot = qe_profile_and_pseudo + pspot = qe_profile_and_pseudo atoms = Atoms("Si", cell=(2, 2, 2), pbc=[True] * 3) kw = dict( - pseudopotentials=dict(Si=pspot), + pseudopotentials=dict(Si=pspot.name), + pseudo_dir=pspot.parent, input_data={"SYSTEM": {"ecutwfc": 40, "input_dft": "LDA",}}, kpts=(2, 2, 2), - conv_thr=0.0001, - profile=profile - ) + conv_thr=0.0001 + ) calc = wfl.calculators.espresso.Espresso( workdir=tmp_path, @@ -251,49 +248,12 @@ def test_wfl_Espresso_calc(tmp_path, qe_profile_and_pseudo): def test_wfl_Espresso_calc_via_generic(tmp_path, qe_profile_and_pseudo): - profile, pspot = qe_profile_and_pseudo - - atoms = Atoms("Si", cell=(2, 2, 2), pbc=[True] * 3) - kw = dict( - pseudopotentials=dict(Si=pspot), - input_data={"SYSTEM": {"ecutwfc": 40, "input_dft": "LDA",}}, - kpts=(2, 2, 2), - conv_thr=0.0001, - workdir=tmp_path, - profile=profile - ) - - calc = (wfl.calculators.espresso.Espresso, [], kw) - - cfgs = [atoms]*3 + [Atoms("Cu", cell=(2, 2, 2), pbc=[True]*3)] - ci = ConfigSet(cfgs) - co = OutputSpec() - autoparainfo = AutoparaInfo( - num_python_subprocesses=0 - ) - - ci = generic.calculate( - inputs=ci, - outputs=co, - calculator=calc, - output_prefix='qe_', - autopara_info=autoparainfo - ) - - ats = list(ci) - assert not any("qe_calculation_failed" in at.info for at in ats[:-1]) - assert "qe_calculation_failed" in list(ci)[-1].info - - -def test_wfl_Espresso_no_explicit_profile(tmp_path, qe_profile_and_pseudo, monkeypatch): - _, pspot = qe_profile_and_pseudo - - import ase.config - ase.config.cfg = ase.config.Config.read() + pspot = qe_profile_and_pseudo atoms = Atoms("Si", cell=(2, 2, 2), pbc=[True] * 3) kw = dict( - pseudopotentials=dict(Si=pspot), + pseudopotentials=dict(Si=pspot.name), + pseudo_dir=pspot.parent, input_data={"SYSTEM": {"ecutwfc": 40, "input_dft": "LDA",}}, kpts=(2, 2, 2), conv_thr=0.0001, diff --git a/tests/local_scripts/complete_pytest.tin b/tests/local_scripts/complete_pytest.tin index e5f47f20..2467ee14 100755 --- a/tests/local_scripts/complete_pytest.tin +++ b/tests/local_scripts/complete_pytest.tin @@ -32,7 +32,6 @@ export ASE_VASP_COMMAND_GAMMA=vasp.gamma.serial export PYTEST_VASP_POTCAR_DIR=$VASP_PATH/pot/rev_54/PBE # QE module load dft/pwscf -espresso_command="env MPIRUN_EXTRA_ARGS='-np 1' pw.x" # no ORCA export OPENBLAS_NUM_THREADS=1 @@ -59,15 +58,7 @@ if [ -d $pytest_dir ]; then exit 1 fi -# set up config file for various (so far just espresso) tests mkdir -p $pytest_dir -export ASE_CONFIG_PATH=$pytest_dir/pytest_wfl_config.ini -echo "Creating ASE_CONFIG_PATH $ASE_CONFIG_PATH" -cat << EOF > $ASE_CONFIG_PATH -[espresso] -command = $espresso_command -pseudo_dir = $pytest_dir -EOF pytest -v -s --basetemp $pytest_dir ${runremote} --runslow --runperf -rxXs "$@" >> complete_pytest.tin.out 2>&1 @@ -76,7 +67,7 @@ l=`egrep '^=.*(passed|failed|skipped|xfailed)' complete_pytest.tin.out` echo "summary line $l" lp=$( echo $l | sed -E -e 's/ in .*//' -e 's/\s*,\s*/\n/g' ) -declare -A expected_n=( ["passed"]="176" ["skipped"]="21" ["warnings"]=823 ["xfailed"]=2 ["xpassed"]=1 ) +declare -A expected_n=( ["passed"]="175" ["skipped"]="21" ["warnings"]=823 ["xfailed"]=2 ["xpassed"]=1 ) IFS=$'\n' for out in $lp; do out_n=$(echo $out | sed -e 's/^=* //' -e 's/ .*//' -e 's/,//')