Skip to content

Commit

Permalink
Do QE tests using user's default config file. Update complete_test.ti…
Browse files Browse the repository at this point in the history
…n and github CI test to be consistent
  • Loading branch information
bernstei committed Jul 22, 2024
1 parent 6eeec7e commit 6eb4161
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 86 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/pytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand All @@ -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
Expand Down
88 changes: 24 additions & 64 deletions tests/calculators/test_qe.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,24 @@
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:
https://stackoverflow.com/questions/63417661/pytest-downloading-a-test-file-once-and-using-it-for-multiple-tests
Returns
-------
profile: str
EspressoProfile with correct command and pseudo dir for pytest
pspot_file: str
Si pseudo potential file name
"""
Expand All @@ -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)
Expand Down Expand Up @@ -168,20 +165,20 @@ 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")
at.positions[0, 0] += 0.01
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)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
11 changes: 1 addition & 10 deletions tests/local_scripts/complete_pytest.tin
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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/,//')
Expand Down

0 comments on commit 6eb4161

Please sign in to comment.