Skip to content

Commit

Permalink
Simplify reporting messages.
Browse files Browse the repository at this point in the history
Co-authored-by: Lorenzo <[email protected]>
  • Loading branch information
t-reents and bastonero committed Feb 13, 2024
1 parent f7030f5 commit 1bcc183
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 63 deletions.
21 changes: 5 additions & 16 deletions src/aiida_quantumespresso_hp/workflows/hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,10 @@ def get_pseudos(self) -> dict:

return results

def relabel_onsite_hubbard(self, workchain):
def relabel_hubbard_structure(self, workchain) -> None:
"""Relabel the Hubbard structure if new types have been detected."""
from aiida_quantumespresso.utils.hubbard import is_intersite_hubbard

relabeling_message = ''

if not is_intersite_hubbard(workchain.outputs.hubbard_structure.hubbard):
for site in workchain.outputs.hubbard.dict.sites:
if not site['type'] == site['new_type']:
Expand All @@ -436,12 +434,8 @@ def relabel_onsite_hubbard(self, workchain):
self.ctx.current_hubbard_structure = result['hubbard_structure']
if self.ctx.current_magnetic_moments is not None:
self.ctx.current_magnetic_moments = result['starting_magnetization']
relabeling_message = 'new types have been detected: relabeling the structure.'
break

if relabeling_message and self.inputs.meta_convergence:
relabeling_message = relabeling_message[:-1] + ' and starting new iteration.'
return relabeling_message
self.report('new types have been detected: relabeling the structure.')
return

def run_relax(self):
"""Run the PwRelaxWorkChain to run a relax PwCalculation."""
Expand Down Expand Up @@ -600,15 +594,12 @@ def inspect_hp(self):

if not self.should_check_convergence():
self.ctx.current_hubbard_structure = workchain.outputs.hubbard_structure
relabeling_message = self.relabel_onsite_hubbard(workchain)
self.relabel_hubbard_structure(workchain)

if not self.inputs.meta_convergence:
self.report('meta convergence is switched off, so not checking convergence of Hubbard parameters.')
self.ctx.is_converged = True

if relabeling_message:
self.report(relabeling_message)

def check_convergence(self):
"""Check the convergence of the Hubbard parameters."""
workchain = self.ctx.workchains_hp[-1]
Expand All @@ -626,9 +617,7 @@ def check_convergence(self):

# We check if new types were created, in which case we relabel the `HubbardStructureData`
self.ctx.current_hubbard_structure = workchain.outputs.hubbard_structure
relabeling_message = self.relabel_onsite_hubbard(workchain)
if relabeling_message:
self.report(relabeling_message)
self.relabel_hubbard_structure(workchain)

if not len(ref_params) == len(new_params):
self.report('The new and old Hubbard parameters have different lenghts. Assuming to be at the first cycle.')
Expand Down
47 changes: 0 additions & 47 deletions tests/workflows/test_hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,50 +476,3 @@ def test_inspect_hp(generate_workchain_hubbard, generate_inputs_hubbard, generat
process.ctx.workchains_hp = [generate_hp_workchain_node(exit_status=300)]
result = process.inspect_hp()
assert result == WorkChain.exit_codes.ERROR_SUB_PROCESS_FAILED_HP.format(iteration=process.ctx.iteration)


@pytest.mark.usefixtures('aiida_profile')
def test_relabel_onsite_hubbard(
generate_workchain_hubbard, generate_inputs_hubbard, generate_hp_workchain_node, generate_hubbard_structure
):
"""Test `SelfConsistentHubbardWorkChain.relabel_onsite_hubbard`."""
from aiida.orm import Bool
inputs = generate_inputs_hubbard()

# Scenario 1: `meta_convergence` is False and intersite parameters are present
process = generate_workchain_hubbard(inputs=inputs)
process.setup()

current_hubbard_structure = generate_hubbard_structure(u_value=1, only_u=True)
process.ctx.current_hubbard_structure = current_hubbard_structure
# Contains intersite parameters --> no relabeling
workchain_hp = generate_hp_workchain_node(relabel=True, u_value=100, only_u=False)
relabeling_message = process.relabel_onsite_hubbard(workchain_hp)
assert relabeling_message == ''

# Scenario 2: `meta_convergence` is False and only onsite parameters are present
process = generate_workchain_hubbard(inputs=inputs)
process.setup()

current_hubbard_structure = generate_hubbard_structure(u_value=1, only_u=True)
process.ctx.current_hubbard_structure = current_hubbard_structure
# Contains only onsite parameters --> relabeling
# `meta_convergence` is False, so relableing message should not contain
# new iteration
workchain_hp = generate_hp_workchain_node(relabel=True, u_value=100, only_u=True)
relabeling_message = process.relabel_onsite_hubbard(workchain_hp)
assert relabeling_message == 'new types have been detected: relabeling the structure.'

# Scenario 3: `meta_convergence` is True and only onsite parameters are present
inputs['meta_convergence'] = Bool(True)
process = generate_workchain_hubbard(inputs=inputs)
process.setup()

current_hubbard_structure = generate_hubbard_structure(u_value=1, only_u=True)
process.ctx.current_hubbard_structure = current_hubbard_structure
# Contains only onsite parameters --> relabeling
# `meta_convergence` is True, so relableing message should contain
# new iteration
workchain_hp = generate_hp_workchain_node(relabel=True, u_value=100, only_u=True)
relabeling_message = process.relabel_onsite_hubbard(workchain_hp)
assert relabeling_message == 'new types have been detected: relabeling the structure and starting new iteration.'

0 comments on commit 1bcc183

Please sign in to comment.